o
    ¨Ýjÿ!  ã                   @  s  d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
mZmZmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZ ddlmZmZ e	rnddlmZ ddlmZ ddlm Z  edeefd�G dd„ dej!ƒƒZ"nej!Z"dZ#edƒZ$G dd„ deee$ e"d�Z%dS )z%RootModel class and type definitions.é    )Úannotations)ÚCallable)ÚcopyÚdeepcopy)ÚTYPE_CHECKINGÚAnyÚGenericÚLiteralÚTypeVar)ÚPydanticUndefined)ÚSelfÚdataclass_transformé   )ÚPydanticUserError)Ú_model_constructionÚ_repr)Ú	BaseModelÚ_object_setattr)ÚField)ÚPrivateAttr)ÚIncExF)Zkw_only_defaultZfield_specifiersc                   @  s   e Zd ZdS )Ú_RootModelMetaclassN)Ú__name__Ú
__module__Ú__qualname__© r   r   úN/var/www/html/chatgpt/venv/lib/python3.10/site-packages/pydantic/root_model.pyr      s    r   )Ú	RootModelÚRootModelRootTypec                      sÎ   e Zd ZU dZdZdZdZded< ‡ fdd„Ze	fd>d
d„Z
de
_ed?d@‡ fdd„ƒZdAdd„ZdBdd„ZdCdd„Zd?dDdd„ZerWdddddddddddddddœdEd6d7„ZdF‡ fd9d:„ZdGd<d=„Z‡  ZS )Hr   a»  !!! abstract "Usage Documentation"
        [`RootModel` and Custom Root Types](../concepts/models.md#rootmodel-and-custom-root-types)

    A Pydantic `BaseModel` for the root object of the model.

    Attributes:
        root: The root object of the model.
        __pydantic_root_model__: Whether the model is a RootModel.
        __pydantic_private__: Private fields in the model.
        __pydantic_extra__: Extra fields in the model.

    TNr   Úrootc                   s6   | j  d¡}|d urtddd�‚tƒ jdi |¤Ž d S )NÚextraz<`RootModel` does not support setting `model_config['extra']`zroot-model-extra)Úcoder   )Zmodel_configÚgetr   ÚsuperÚ__init_subclass__)ÚclsÚkwargsr    ©Ú	__class__r   r   r$   6   s   ÿzRootModel.__init_subclass__ÚreturnÚNonec                K  s0   d}|r|t urtdƒ‚|}| jj|| d� d S )NTz_"RootModel.__init__" accepts either a single positional argument or arbitrary keyword arguments)Zself_instance)r   Ú
ValueErrorZ__pydantic_validator__Zvalidate_python)Úselfr   ÚdataZ__tracebackhide__r   r   r   Ú__init__>   s   ÿzRootModel.__init__Ú_fields_setúset[str] | Noner   c                   s   t ƒ j||d�S )aS  Create a new model using the provided root object and update fields set.

        Args:
            root: The root object of the model.
            _fields_set: The set of fields to be updated.

        Returns:
            The new model.

        Raises:
            NotImplemented: If the model is not a subclass of `RootModel`.
        )r   r/   )r#   Úmodel_construct)r%   r   r/   r'   r   r   r1   J   s   zRootModel.model_constructúdict[Any, Any]c                 C  s   | j | jdœS )N©Ú__dict__Ú__pydantic_fields_set__r3   ©r,   r   r   r   Ú__getstate__Z   s   þzRootModel.__getstate__Ústatec                 C  s$   t | d|d ƒ t | d|d ƒ d S )Nr5   r4   )r   )r,   r8   r   r   r   Ú__setstate__`   s   zRootModel.__setstate__c                 C  sP   t | ƒ}| |¡}t| jƒ}t| jd ƒ|d< t|d|ƒ t|dt| jƒƒ |S )z$Returns a shallow copy of the model.r   r4   r5   )ÚtypeÚ__new__r   r4   r   r5   )r,   r%   ÚmZnew_dictr   r   r   Ú__copy__d   s   

zRootModel.__copy__Úmemoúdict[int, Any] | Nonec                 C  s>   t | ƒ}| |¡}t|dt| j|d�ƒ t|dt| jƒƒ |S )z!Returns a deep copy of the model.r4   )r>   r5   )r:   r;   r   r   r4   r   r5   )r,   r>   r%   r<   r   r   r   Ú__deepcopy__n   s
   
zRootModel.__deepcopy__ÚpythonF)ÚmodeÚincludeÚexcludeÚcontextÚby_aliasÚexclude_unsetÚexclude_defaultsÚexclude_noneÚexclude_computed_fieldsÚ
round_tripÚwarningsÚfallbackÚserialize_as_anyÚpolymorphic_serializationrB   úLiteral['json', 'python'] | strrC   úIncEx | NonerD   rE   ú
Any | NonerF   úbool | NonerG   ÚboolrH   rI   rJ   rK   rL   ú'bool | Literal['none', 'warn', 'error']rM   úCallable[[Any], Any] | NonerN   rO   r   c                C  s   dS )a�  !!! abstract "Usage Documentation"
                [`model_dump`](../concepts/serialization.md#python-mode)

            Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

            Args:
                mode: The mode in which `to_python` should run.
                    If mode is 'json', the output will only contain JSON serializable types.
                    If mode is 'python', the output may contain non-JSON-serializable Python objects.
                include: A set of fields to include in the output.
                exclude: A set of fields to exclude from the output.
                context: Additional context to pass to the serializer.
                by_alias: Whether to use the field's alias in the dictionary key if defined.
                exclude_unset: Whether to exclude fields that have not been explicitly set.
                exclude_defaults: Whether to exclude fields that are set to their default value.
                exclude_none: Whether to exclude fields that have a value of `None`.
                exclude_computed_fields: Whether to exclude computed fields.
                    While this can be useful for round-tripping, it is usually recommended to use the dedicated
                    `round_trip` parameter instead.
                round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
                warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
                    "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
                fallback: A function to call when an unknown value is encountered. If not provided,
                    a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
                serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
                polymorphic_serialization: Whether to use model and dataclass polymorphic serialization for this call.

            Returns:
                A dictionary representation of the model.
            Nr   )r,   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   r   r   r   Ú
model_dump€   s   0zRootModel.model_dumpÚotherc                   s2   t |tƒstS | jd j|jd jkotƒ  |¡S ©Nr   )Ú
isinstancer   ÚNotImplementedZ__pydantic_fields__Ú
annotationr#   Ú__eq__)r,   rX   r'   r   r   r]   ²   s   
ÿþ
þzRootModel.__eq__ú_repr.ReprArgsc                 c  s   � d| j fV  d S rY   )r   r6   r   r   r   Ú__repr_args__¹   s   €zRootModel.__repr_args__)r   r   r)   r*   )N)r   r   r/   r0   r)   r   )r)   r2   )r8   r2   r)   r*   )r)   r   )r>   r?   r)   r   )rB   rP   rC   rQ   rD   rQ   rE   rR   rF   rS   rG   rT   rH   rT   rI   rT   rJ   rT   rK   rT   rL   rU   rM   rV   rN   rT   rO   rS   r)   r   )rX   r   r)   rT   )r)   r^   )r   r   r   Ú__doc__Z__pydantic_root_model__Z__pydantic_private__Z__pydantic_extra__Ú__annotations__r$   r   r.   Z__pydantic_base_init__Úclassmethodr1   r7   r9   r=   r@   r   rW   r]   r_   Ú__classcell__r   r   r'   r   r   "   sB   
 





ð2r   )Ú	metaclassN)&r`   Ú
__future__r   Z_annotationsÚcollections.abcr   r   r   Útypingr   r   r   r	   r
   Zpydantic_corer   Ztyping_extensionsr   r   Ú r   Ú	_internalr   r   Úmainr   r   Úfieldsr   ZPydanticModelFieldr   ZPydanticModelPrivateAttrr   ZModelMetaclassr   Ú__all__r   r   r   r   r   r   Ú<module>   s(    