
    df                        d dl mZ d dlmZmZmZmZ d dlmZm	Z	 d dl
mZ ddlmZmZ erddlmZ ddlmZ  ed	e	e      Z G d
 dee         ZdddZddZy)    )annotations)TYPE_CHECKINGCallableGenericTypeVar)SchemaSerializerSchemaValidator)Literal   )PydanticErrorCodesPydanticUserError)PydanticDataclass)	BaseModelValSerc                  D    e Zd ZdZdZdd	 	 	 	 	 	 	 	 	 ddZd	dZd
dZy)
MockValSerzMocker for `pydantic_core.SchemaValidator` or `pydantic_core.SchemaSerializer` which optionally attempts to
    rebuild the thing it's mocking when one of its methods is accessed and raises an error if that fails.
    )_error_message_code_val_or_ser_attempt_rebuildN)attempt_rebuildc               Z    || _         |dk(  rt        nt        | _        || _        || _        y )N	validator)r   r	   r   r   r   r   )selferror_messagecode
val_or_serr   s        Y/home/api-vastappli/venv/lib/python3.12/site-packages/pydantic/_internal/_mock_val_ser.py__init__zMockValSer.__init__   s-     ,.8K.G?M])-
 /    c                    d}| j                   r| j                         }|t        ||      S t        | j                  |       t        | j                  | j
                        )NTr   )r   getattrr   r   r   r   )r   item__tracebackhide__val_sers       r   __getattr__zMockValSer.__getattr__&   s[       ++-G"w-- 	  $' 3 3$**EEr    c                    | j                   r5| j                         }||S t        | j                  | j                        y )Nr"   )r   r   r   r   )r   r&   s     r   rebuildzMockValSer.rebuild1   s>      ++-G"'(;(;$**MMr    )
r   strr   r   r   z"Literal['validator', 'serializer']r   z"Callable[[], ValSer | None] | NonereturnNone)r$   r*   r+   r,   )r+   zValSer | None)__name__
__module____qualname____doc__	__slots__r   r'   r)    r    r   r   r      sU     MI ?C00 !	0
 70 <0 
0	Fr    r   c                     d| d| d| d}d fd}t        |dd|       _        d fd	}t        |dd
|       _        y)a&  Set `__pydantic_validator__` and `__pydantic_serializer__` to `MockValSer`s on a model.

    Args:
        cls: The model class to set the mocks on
        cls_name: Name of the model class, used in error messages
        undefined_name: Name of the undefined thing, used in error messages
    `*` is not fully defined; you should define z, then call `z.model_rebuild()`.c                 D     j                  dd      r j                  S y NF   raise_errors_parent_namespace_depth)model_rebuild__pydantic_validator__clss   r   attempt_rebuild_validatorz2set_model_mocks.<locals>.attempt_rebuild_validatorH   s%    %K---r    class-not-fully-definedr   r   r   r   c                 D     j                  dd      r j                  S y r7   )r<   __pydantic_serializer__r>   s   r   attempt_rebuild_serializerz3set_model_mocks.<locals>.attempt_rebuild_serializerU   s%    %K...r    
serializerNr+   zSchemaValidator | None)r+   zSchemaSerializer | None)r   r=   rD   )r?   cls_nameundefined_nameundefined_type_error_messager@   rE   s   `     r   set_model_mocksrK   ;   sl     H:??O Pj 2	4 !
 ",$&1	"C #-$&2	#Cr    c                R     d| d| d| d}d	 fd}t        |dd|       _        y )
Nr4   r5   z4, then call `pydantic.dataclasses.rebuild_dataclass(z)`.c                 @    ddl m}   | dd      rj                  S y )Nr   )rebuild_dataclassFr8   r9   )dataclassesrN   r=   )rN   r?   s    r   r   z5set_dataclass_mock_validator.<locals>.attempt_rebuildi   s!    3SuaP---r    rA   r   rB   rG   )r   r=   )r?   rH   rI   rJ   r   s   `    r   set_dataclass_mock_validatorrP   c   sJ    
H:??O P>>FZs	L !
 ",$&'	"Cr    N)zall referenced types)r?   ztype[BaseModel]rH   r*   rI   r*   r+   r,   )r?   ztype[PydanticDataclass]rH   r*   rI   r*   r+   r,   )
__future__r   typingr   r   r   r   pydantic_corer   r	   typing_extensionsr
   errorsr   r   rO   r   mainr   r   r   rK   rP   r2   r    r   <module>rW      sM    " < < ; % :/  
?,<	=& &R%Pr    