a
    h                  
   @  s   U d Z ddlmZ ddlZddlm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 erd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)Iterable)TYPE_CHECKINGAnyCallableLiteralTypeVar)
CoreConfig
CoreSchemaSchemaValidatorValidationError)	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$   ]/var/www/html/assistant/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_handlersZ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__r9   r=   r$   r$   r$   r%   r"   6   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_handlersrC   .0hr$   r$   r%   	<genexpr>d       z build_wrapper.<locals>.<genexpr>c                 s  s   | ]}t |d r|jV  qdS )
on_successN)rD   rJ   rE   r$   r$   r%   rH   e   rI   c                 s  s   | ]}t |d r|jV  qdS )on_errorN)rD   rK   rE   r$   r$   r%   rH   f   rI   c                 s  s   | ]}t |d r|jV  qdS )on_exceptionN)rD   rL   rE   r$   r$   r%   rH   g   rI   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)	rM   rN   Zon_enter_handlerresulterrorZon_error_handler	exceptionZon_exception_handlerZon_success_handlerrA   Z	on_entersZ	on_errorsZon_exceptionsZon_successesr$   r%   wrapperi   s    


zbuild_wrapper.<locals>.wrapper)tuple	functoolswraps)rA   rB   rT   r$   rS   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/   )rY   rZ   handlerr$   r$   r%   rD      s    
rD   )NN)#r?   
__future__r   rV   collections.abcr   typingr   r   r   r   r   Zpydantic_corer	   r
   r   r   Ztyping_extensionsr   r!   r   r   r   r   r   r   Eventlist__args__r   __annotations__r&   r"   r3   rD   r$   r$   r$   r%   <module>   s$   	   * 