a
    Ofx                  
   @  s   U d Z ddlmZ ddlZddlmZmZmZmZm	Z	 ddl
mZmZmZmZ ddlmZmZ erzddlmZmZmZmZ ed	Ze	d
Zed ZeejZded< d$dddddddddddZG dd dZddddddZ ddd d!d"d#Z!dS )%z(Pluggable schema validator for pydantic.    )annotationsN)TYPE_CHECKINGAnyCallableIterableTypeVar)
CoreConfig
CoreSchemaSchemaValidatorValidationError)Literal	ParamSpec   )BaseValidateHandlerProtocolPydanticPluginProtocol
SchemaKindSchemaTypePathPR)Zon_validate_pythonZon_validate_jsonZon_validate_stringszlist[Event]eventsr	   r   strr   CoreConfig | Nonezdict[str, Any] | Nonez*SchemaValidator | PluggableSchemaValidator)schemaschema_typeschema_type_moduleschema_type_nameschema_kindconfigplugin_settingsreturnc           
      C  sN   ddl m} ddlm} | }	|	r@t| |||||||	|p<i S t| |S dS )zCreate a `SchemaValidator` or `PluggableSchemaValidator` if plugins are installed.

    Returns:
        If plugins are installed then return `PluggableSchemaValidator`, otherwise return `SchemaValidator`.
    r   )r   )get_pluginsN) r   Z_loaderr    PluggableSchemaValidatorr
   )
r   r   r   r   r   r   r   r   r    plugins r$   Z/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pydantic/plugin/_schema_validator.pycreate_schema_validator   s    
r&   c                	   @  s@   e Zd ZdZdZddddddd	d
dddZdddddZdS )r"   zPluggable schema validator.)_schema_validatorvalidate_jsonvalidate_pythonvalidate_stringsr	   r   r   r   r   z Iterable[PydanticPluginProtocol]zdict[str, Any]None)r   r   schema_type_pathr   r   r#   r   r   c                 C  s   t ||| _g }g }	g }
|D ]}z|||||||\}}}W nF ty } z.td|j d|jj d| |W Y d }~n
d }~0 0 |d ur|| |d ur|	| |d ur|
| qt| jj	|| _	t| jj
|	| _
t| jj|
| _d S )NzError using plugin `:z`: )r
   r'   Znew_schema_validator	TypeError
__module__	__class____name__appendbuild_wrapperr)   r(   r*   )selfr   r   r,   r   r   r#   r   Zpython_event_handlersZjson_event_handlersZstrings_event_handlerspluginpjser$   r$   r%   __init__:   s(    
8

z!PluggableSchemaValidator.__init__r   )namer   c                 C  s   t | j|S N)getattrr'   )r4   r;   r$   r$   r%   __getattr__[   s    z$PluggableSchemaValidator.__getattr__N)r1   r/   __qualname____doc__	__slots__r:   r>   r$   r$   r$   r%   r"   5   s   !r"   zCallable[P, R]z!list[BaseValidateHandlerProtocol])funcevent_handlersr   c                   s   |s S t dd |D t dd |D t dd |D t dd |D t dddd	 fd
d}|S d S )Nc                 s  s   | ]}t |d r|jV  qdS )on_enterN)filter_handlersrD   .0hr$   r$   r%   	<genexpr>c       z build_wrapper.<locals>.<genexpr>c                 s  s   | ]}t |d r|jV  qdS )
on_successN)rE   rK   rF   r$   r$   r%   rI   d   rJ   c                 s  s   | ]}t |d r|jV  qdS )on_errorN)rE   rL   rF   r$   r$   r%   rI   e   rJ   c                 s  s   | ]}t |d r|jV  qdS )on_exceptionN)rE   rM   rF   r$   r$   r%   rI   f   rJ   zP.argszP.kwargsr   )argskwargsr   c            	   
     s   D ]}|| i | qz | i |}W nn t yb } z D ]}|| q> W Y d }~nVd }~0  ty } z D ]}|| qt W Y d }~n d }~0 0 D ]}|| q|S d S r<   )r   	Exception)	rN   rO   Zon_enter_handlerresulterrorZon_error_handler	exceptionZon_exception_handlerZon_success_handlerrB   Z	on_entersZ	on_errorsZon_exceptionsZon_successesr$   r%   wrapperh   s    


zbuild_wrapper.<locals>.wrapper)tuple	functoolswraps)rB   rC   rU   r$   rT   r%   r3   _   s     r3   r   bool)handler_clsmethod_namer   c                 C  s.   t | |d}|du rdS |jdkr&dS dS dS )zFilter out handler methods which are not implemented by the plugin directly - e.g. are missing
    or are inherited from the protocol.
    NFzpydantic.pluginT)r=   r/   )rZ   r[   handlerr$   r$   r%   rE      s    
rE   )NN)"r@   
__future__r   rW   typingr   r   r   r   r   Zpydantic_corer   r	   r
   r   typing_extensionsr   r   r!   r   r   r   r   r   r   Eventlist__args__r   __annotations__r&   r"   r3   rE   r$   r$   r$   r%   <module>   s"   	   * 