a
    “˜ëj·  ã                   @  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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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]ÚeventsTr
   r   Ústrr   úCoreConfig | Nonezdict[str, Any] | NoneÚboolz*SchemaValidator | PluggableSchemaValidator)	ÚschemaÚschema_typeÚschema_type_moduleÚschema_type_nameÚschema_kindÚconfigÚplugin_settingsÚ_use_prebuiltÚreturnc              
   C  sV   ddl m} ddlm}	 |	ƒ }
|
rDt| ||||ƒ|||
|p<i |d�S t| ||d�S dS )zÒCreate a `SchemaValidator` or `PluggableSchemaValidator` if plugins are installed.

    Returns:
        If plugins are installed then return `PluggableSchemaValidator`, otherwise return `SchemaValidator`.
    r   )r   )Úget_plugins©r    N)Ú r   Z_loaderr"   ÚPluggableSchemaValidatorr   )r   r   r   r   r   r   r   r    r   r"   Úplugins© r'   ú`/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pydantic/plugin/_schema_validator.pyÚcreate_schema_validator   s    ør)   c                   @  sV   e Zd ZdZdZddddddd	d
dddœ	dd„Ze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_stringsTr
   r   r   r   r   z Iterable[PydanticPluginProtocol]zdict[str, Any]r   ÚNone)	r   r   Úschema_type_pathr   r   r&   r   r    r!   c	                 C  sö   t |||d�| _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 )Nr#   z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   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   )r!   c                 C  s   | j S )z…The underlying pydantic-core `SchemaValidator`.

        This is a private attribute, not meant to be used outside Pydantic.
        )r*   )r7   r'   r'   r(   Ú__pydantic_schema_validator__`   s    z6PluggableSchemaValidator.__pydantic_schema_validator__r   )Únamer!   c                 C  s   t | j|ƒS ©N)Úgetattrr*   )r7   r>   r'   r'   r(   Ú__getattr__h   s    z$PluggableSchemaValidator.__getattr__N)T)	r4   r2   Ú__qualname__Ú__doc__Ú	__slots__r<   Úpropertyr=   rA   r'   r'   r'   r(   r%   8   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_handlersrH   ©Ú.0Úhr'   r'   r(   Ú	<genexpr>p   ó    z build_wrapper.<locals>.<genexpr>c                 s  s   | ]}t |d ƒr|jV  qdS )Ú
on_successN)rI   rO   rJ   r'   r'   r(   rM   q   rN   c                 s  s   | ]}t |d ƒr|jV  qdS )Úon_errorN)rI   rP   rJ   r'   r'   r(   rM   r   rN   c                 s  s   | ]}t |d ƒr|jV  qdS )Úon_exceptionN)rI   rQ   rJ   r'   r'   r(   rM   s   rN   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)	rR   rS   Zon_enter_handlerÚresultÚerrorZon_error_handlerÚ	exceptionZon_exception_handlerZon_success_handler©rF   Z	on_entersZ	on_errorsZon_exceptionsZon_successesr'   r(   Úwrapperu   s    


zbuild_wrapper.<locals>.wrapper)ÚtupleÚ	functoolsÚwraps)rF   rG   rY   r'   rX   r(   r6   l   s     r6   r   )Úhandler_clsÚmethod_namer!   c                 C  s.   t | |dƒ}|du rdS |jdkr&dS dS dS )z–Filter out handler methods which are not implemented by the plugin directly - e.g. those that are missing
    or are inherited from the protocol.
    NFzpydantic.pluginT)r@   r2   )r]   r^   Úhandlerr'   r'   r(   rI   Œ   s    
rI   )NNT)#rC   Ú
__future__r   r[   Ú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%   r6   rI   r'   r'   r'   r(   Ú<module>   s&   	   ø "4 