o
    hl                     @  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r=d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ZG dd  d Zd/d%d&Z d0d+d,Z!dS )1z(Pluggable schema validator for pydantic.    )annotationsN)TYPE_CHECKINGAnyCallableIterableTypeVar)
CoreConfig
CoreSchemaSchemaValidatorValidationError)Literal	ParamSpec   )BaseValidateHandlerProtocolPydanticPluginProtocol
SchemaKindSchemaTypePathPR)on_validate_pythonon_validate_jsonon_validate_stringszlist[Event]eventsschemar	   schema_typer   schema_type_modulestrschema_type_nameschema_kindr   configCoreConfig | Noneplugin_settingsdict[str, Any] | Nonereturnr
   c           
      C  sJ   ddl m} ddlm} | }	|	r t| |||||||	|pi S t| |S )zCreate a `SchemaValidator` or `PluggableSchemaValidator` if plugins are installed.

    Returns:
        If plugins are installed then return `PluggableSchemaValidator`, otherwise return `SchemaValidator`.
    r   )r   )get_plugins) r   _loaderr$   PluggableSchemaValidatorr
   )
r   r   r   r   r   r   r!   r   r$   plugins r)   W/var/www/html/ai/venv/lib/python3.10/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ZdddZdS )r'   zPluggable schema validator.)_schema_validatorvalidate_jsonvalidate_pythonvalidate_stringsr   r	   r   r   schema_type_pathr   r   r   r   r    r(    Iterable[PydanticPluginProtocol]r!   dict[str, Any]r#   Nonec                 C  s   t ||| _g }g }	g }
|D ]J}z|||||||\}}}W n ty< } ztd|j d|jj d| |d }~ww |d urF|| |d urO|	| |d urX|
| qt| jj	|| _	t| jj
|	| _
t| jj|
| _d S )NzError using plugin `:z`: )r
   r,   new_schema_validator	TypeError
__module__	__class____name__appendbuild_wrapperr.   r-   r/   )selfr   r   r0   r   r   r(   r!   python_event_handlersjson_event_handlersstrings_event_handlerspluginpjser)   r)   r*   __init__9   s.   
"


z!PluggableSchemaValidator.__init__namer   c                 C  s   t | j|S N)getattrr,   )r<   rF   r)   r)   r*   __getattr__Z   s   z$PluggableSchemaValidator.__getattr__N)r   r	   r   r   r0   r   r   r   r   r    r(   r1   r!   r2   r#   r3   )rF   r   r#   r   )r9   r7   __qualname____doc__	__slots__rE   rI   r)   r)   r)   r*   r'   4   s
    
!r'   funcCallable[P, R]event_handlers!list[BaseValidateHandlerProtocol]c                   st   |s S t dd |D t dd |D t dd |D t dd |D t d fdd}|S )Nc                 s       | ]}t |d r|jV  qdS )on_enterN)filter_handlersrR   .0hr)   r)   r*   	<genexpr>b       z build_wrapper.<locals>.<genexpr>c                 s  rQ   )
on_successN)rS   rY   rT   r)   r)   r*   rW   c   rX   c                 s  rQ   )on_errorN)rS   rZ   rT   r)   r)   r*   rW   d   rX   c                 s  rQ   )on_exceptionN)rS   r[   rT   r)   r)   r*   rW   e   rX   argsP.argskwargsP.kwargsr#   r   c            	   
     s   D ]	}|| i | qz	 | i |}W n+ t y+ } z
D ]}|| q d }~w ty@ } z
D ]}|| q4 d }~ww D ]}|| qC|S rG   )r   	Exception)	r\   r^   on_enter_handlerresulterroron_error_handler	exceptionon_exception_handleron_success_handlerrM   	on_enters	on_errorson_exceptionson_successesr)   r*   wrapperg   s$   


zbuild_wrapper.<locals>.wrapper)r\   r]   r^   r_   r#   r   )tuple	functoolswraps)rM   rO   rm   r)   rh   r*   r;   ^   s   r;   handler_clsr   method_nameboolc                 C  s*   t | |d}|du rdS |jdkr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)rH   r7   )rq   rr   handlerr)   r)   r*   rS   ~   s   
rS   )NN)r   r	   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r
   )rM   rN   rO   rP   r#   rN   )rq   r   rr   r   r#   rs   )"rK   
__future__r   ro   typingr   r   r   r   r   pydantic_corer   r	   r
   r   typing_extensionsr   r   r%   r   r   r   r   r   r   Eventlist__args__r   __annotations__r+   r'   r;   rS   r)   r)   r)   r*   <module>   s$    	 
* 