o
    %if2                    @  s  U d Z ddlmZ ddlZddlZddlZddlZddlZddl	m	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZ ddlZddlZddlmZ ddlmZ dd	lmZmZmZmZmZ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)m*Z* ddl+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5 ddlm6Z6 edddZ7eee8ef ddf Z9eee: ee8 ee:ef ee8ef df Z;de<d< ej=rddl>m?Z? ddl@mAZA ddlmBZBmCZCmDZD ddlmEZE ddlFmGZGmHZH ddlImJZK ddlLmMZMmNZNmOZO ddlLmPZQ ne6ZRdZSejTZUG dd dejVd ZWejXdddeYddd!d>d3d4ZZejXddeYddd5d?d8d4ZZdddddddd9d@d=d4ZZe$eYZ[dS )AzLogic for creating models.    )annotationsN)copydeepcopy)	AnyClassVarDict	GeneratorLiteralSetTupleTypeVarUnionPydanticUndefined)	TypeAlias   )
_config_decorators_fields_forward_ref	_generics_mock_val_ser_model_construction_repr_typing_extra_utils)getattr_migration)AliasChoices	AliasPath)GetCoreSchemaHandlerGetJsonSchemaHandler)
ConfigDict)PydanticUndefinedAnnotationPydanticUserError)DEFAULT_REF_TEMPLATEGenerateJsonSchemaJsonSchemaModeJsonSchemaValuemodel_json_schema)PydanticDeprecatedSince20Model	BaseModel)boundr   IncEx)	Signature)Path)
CoreSchemaSchemaSerializerSchemaValidator)Unpack)AbstractSetIntStrMappingIntStrAny)Protocol)ComputedFieldInfo	FieldInfoModelPrivateAttr)Field)r+   create_modelc                      s  e Zd ZU dZejrided< 	 ded< 	 ded< 	 ded	< d
ed< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ed d!Zd"ed#< ed d!Z	d$ed%< ed d!Z
d"ed&< ni Zi Ze Zd'Zejd(d)d*d+Zejd(d,d*d+Zd-Ze Zd Zd Zdd2d3Zd4e_edd5d6Zedd7d8Zeddd?d@Z d'd dAddFdGZ!dHd'd'd'd d d d d d4d dIddYdZZ"d'd'd'd'd d d d d d4d d[dd_d`Z#ed4e$e%dafddfdgZ&eddjdkZ'ddmdnZ(ed d4dod'dpddwdxZ)ed'd'd'dydd}d~Z*ed'd'ddddZ+ed'd'dd ddZ,ed!ddZ-ed"ddZ.ed#ddZ/d$ddZ0d%ddZ1dd&ddZ2ejsqd' fddZ3d(ddZ4d'ddZ5d(ddZ6d)ddZ7d*ddZ8ejsd+ddZ9ejrd,ddZ:d-ddZ;d.ddZ<d/ddZ=e>j?j@Z@e>j?jAZAe>j?jBZBe>j?jCZCd.ddZDeeEjFdd'dd0ddńZGeeEjFdd'ddddȄZHeEjFdd'dd'd'd d d d dʜd1dd̈́ZIeEjFdd'dd'd'd d d d eJeJdϜd2ddՄZKeeEjFdd'dd3dd؄ZLeeEjFdd'dd'dd'd dۜd4ddZMeeEjFdd'dd'dd'd dۜd5ddZNeeEjFdd'dd3ddZOeeEjFdd'dddddZPeEjFdd'dd'd'd'd dd6ddZQeeEjFdd'dd4e$fd7ddZReeEjFdd'dd4e$dd8ddZSeeEjFdd'dd9dd ZTeeEjFdd'dd:ddZUeEjFdd'dd;ddZVeEjFd	d'dd;d
dZWeeEjFdd'dd;ddZXeEjFdd'dd;ddZY  ZZS (<  r+   a}  Usage docs: https://docs.pydantic.dev/2.7/concepts/models/

    A base class for creating Pydantic models.

    Attributes:
        __class_vars__: The names of classvars defined on the model.
        __private_attributes__: Metadata about the private attributes of the model.
        __signature__: The signature for instantiating the model.

        __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
        __pydantic_core_schema__: The pydantic-core schema used to build the SchemaValidator and SchemaSerializer.
        __pydantic_custom_init__: Whether the model has a custom `__init__` function.
        __pydantic_decorators__: Metadata containing the decorators defined on the model.
            This replaces `Model.__validators__` and `Model.__root_validators__` from Pydantic V1.
        __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to
            __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
        __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
        __pydantic_post_init__: The name of the post-init method for the model, if defined.
        __pydantic_root_model__: Whether the model is a `RootModel`.
        __pydantic_serializer__: The pydantic-core SchemaSerializer used to dump instances of the model.
        __pydantic_validator__: The pydantic-core SchemaValidator used to validate instances of the model.

        __pydantic_extra__: An instance attribute with the values of extra fields from validation when
            `model_config['extra'] == 'allow'`.
        __pydantic_fields_set__: An instance attribute with the names of fields explicitly set.
        __pydantic_private__: Instance attribute with the values of private attributes set on the model instance.
    zClassVar[ConfigDict]model_configzClassVar[dict[str, FieldInfo]]model_fieldsz&ClassVar[dict[str, ComputedFieldInfo]]model_computed_fieldszClassVar[set[str]]__class_vars__z%ClassVar[dict[str, ModelPrivateAttr]]__private_attributes__zClassVar[Signature]__signature__zClassVar[bool]__pydantic_complete__zClassVar[CoreSchema]__pydantic_core_schema____pydantic_custom_init__z$ClassVar[_decorators.DecoratorInfos]__pydantic_decorators__z+ClassVar[_generics.PydanticGenericMetadata]__pydantic_generic_metadata__zClassVar[dict[str, Any] | None]__pydantic_parent_namespace__z+ClassVar[None | Literal['model_post_init']]__pydantic_post_init____pydantic_root_model__zClassVar[SchemaSerializer]__pydantic_serializer__zClassVar[SchemaValidator]__pydantic_validator__F)initdict[str, Any] | None__pydantic_extra__set[str]__pydantic_fields_set____pydantic_private__NzXPydantic models should inherit from BaseModel, BaseModel cannot be instantiated directly	validatorzbase-model-instantiated)
val_or_sercode
serializer)__dict__rP   rN   rQ   datar   returnNonec                K  s   d}| j j|| d dS )a/  Create a new model by parsing and validating input data from keyword arguments.

        Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
        validated to form a valid model.

        `self` is explicitly positional-only to allow `self` as a field name.
        T)self_instanceNrK   validate_python)selfrW   __tracebackhide__ r_   F/var/www/html/corbot_env/lib/python3.10/site-packages/pydantic/main.py__init__   s   	zBaseModel.__init__Tc                 C     | j S )zGet extra fields set during validation.

        Returns:
            A dictionary of extra fields, or `None` if `config.extra` is not set to `"allow"`.
        )rN   r]   r_   r_   r`   model_extra   s   zBaseModel.model_extrac                 C  rb   )zReturns the set of fields that have been explicitly set on this model instance.

        Returns:
            A set of strings representing the fields that have been set,
                i.e. that were not filled from defaults.
        )rP   rc   r_   r_   r`   model_fields_set   s   zBaseModel.model_fields_setclstype[Model]_fields_setset[str] | Nonevaluesr*   c                 K  s  |  | }i }t }| j D ]\}}|jdur*|j|v r*||j||< || ||vrv|jdurvt|jt	r=|jj
n|jg}|D ]2}	t|	tr\|	|v r\||	||< ||  nt|	tru|	|}
|
turu|
||< ||  nqC||vr||v r||||< || q| s|jdd||< q|du r|}| jddkrdd | D nd}t|d| t|d	| | jst|d
| | jr|d t|dr|jdur| D ]\}}||jv r||j|< q|S | jst|dd |S )a_  Creates a new instance of the `Model` class with validated data.

        Creates a new model setting `__dict__` and `__pydantic_fields_set__` from trusted or pre-validated data.
        Default values are respected, but no other validation is performed.

        !!! note
            `model_construct()` generally respects the `model_config.extra` setting on the provided model.
            That is, if `model_config.extra == 'allow'`, then all extra passed values are added to the model instance's `__dict__`
            and `__pydantic_extra__` fields. If `model_config.extra == 'ignore'` (the default), then all extra passed values are ignored.
            Because no validation is performed with a call to `model_construct()`, having `model_config.extra == 'forbid'` does not result in
            an error if extra values are passed, but they will be ignored.

        Args:
            _fields_set: The set of field names accepted for the Model instance.
            values: Trusted or pre-validated data dictionary.

        Returns:
            A new instance of the `Model` class with validated data.
        NT)call_default_factoryextraallowc                 S  s   i | ]\}}||qS r_   r_   .0kvr_   r_   r`   
<dictcomp>  s    z-BaseModel.model_construct.<locals>.<dictcomp>rV   rP   rN   rQ   )__new__setr=   itemsaliaspopaddvalidation_alias
isinstancer   choicesstrr   search_dict_for_pathr   is_requiredget_defaultr<   get_object_setattrrI   rH   model_post_inithasattrrQ   r@   )rf   rh   rj   mfields_values
fields_setnamefieldvalidation_aliasesrv   value_extrarp   rq   r_   r_   r`   model_construct   sd   







$


zBaseModel.model_construct)updatedeepr]   r   r   boolc                C  s   |r|   n|  }|rD| jddkr6| D ]\}}|| jv r'||j|< q|jdu r/i |_||j|< qn|j| |j	|
  |S )a  Usage docs: https://docs.pydantic.dev/2.7/concepts/serialization/#model_copy

        Returns a copy of the model.

        Args:
            update: Values to change/add in the new model. Note: the data is not validated
                before creating the new model. You should trust this data.
            deep: Set to `True` to make a deep copy of the model.

        Returns:
            New model instance.
        rl   rm   N)__deepcopy____copy__r<   r   ru   r=   rV   rN   r   rP   keys)r]   r   r   copiedrp   rq   r_   r_   r`   
model_copy  s   

zBaseModel.model_copypython)modeincludeexcludecontextby_aliasexclude_unsetexclude_defaultsexclude_none
round_tripwarningsserialize_as_anyr   Literal['json', 'python'] | strr   r-   r   r   r   r   r   r   r   r   'bool | Literal['none', 'warn', 'error']r   dict[str, Any]c                C  s$   | j j| |||||||||	|
|dS )a  Usage docs: https://docs.pydantic.dev/2.7/concepts/serialization/#modelmodel_dump

        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`.
            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].
            serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.

        Returns:
            A dictionary representation of the model.
        )r   r   r   r   r   r   r   r   r   r   r   )rJ   	to_python)r]   r   r   r   r   r   r   r   r   r   r   r   r_   r_   r`   
model_dump5  s   &zBaseModel.model_dumpindentr   r   r   r   r   r   r   r   r   r   r   
int | Noner|   c                C  s(   | j j| |||||||||	|
|d S )a-  Usage docs: https://docs.pydantic.dev/2.7/concepts/serialization/#modelmodel_dump_json

        Generates a JSON representation of the model using Pydantic's `to_json` method.

        Args:
            indent: Indentation to use in the JSON output. If None is passed, the output will be compact.
            include: Field(s) to include in the JSON output.
            exclude: Field(s) to exclude from the JSON output.
            context: Additional context to pass to the serializer.
            by_alias: Whether to serialize using field aliases.
            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`.
            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].
            serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.

        Returns:
            A JSON string representation of the model.
        r   )rJ   to_jsondecode)r]   r   r   r   r   r   r   r   r   r   r   r   r_   r_   r`   model_dump_jsonj  s    $zBaseModel.model_dump_json
validationref_templateschema_generatortype[GenerateJsonSchema]r&   c                 C  s   t | ||||dS )a  Generates a JSON schema for a model class.

        Args:
            by_alias: Whether to use attribute aliases or not.
            ref_template: The reference template.
            schema_generator: To override the logic used to generate the JSON schema, as a subclass of
                `GenerateJsonSchema` with your desired modifications
            mode: The mode in which to generate the schema.

        Returns:
            The JSON schema for the given model class.
        )r   r   r   r   )r(   )rf   r   r   r   r   r_   r_   r`   r(     s   
zBaseModel.model_json_schemaparamstuple[type[Any], ...]c                 C  s>   t | tjs
tddd |D }d|}| j d| dS )a}  Compute the class name for parametrizations of generic classes.

        This method can be overridden to achieve a custom naming scheme for generic BaseModels.

        Args:
            params: Tuple of types of the class. Given a generic class
                `Model` with 2 type variables and a concrete model `Model[str, int]`,
                the value `(str, int)` would be passed to `params`.

        Returns:
            String representing the new class where `params` are passed to `cls` as type variables.

        Raises:
            TypeError: Raised when trying to generate concrete names for non-generic models.
        z;Concrete names should only be generated for generic models.c                 S  s$   g | ]}t |tr|nt|qS r_   )rz   r|   r   display_as_typero   paramr_   r_   r`   
<listcomp>  s   $ z5BaseModel.model_parametrized_name.<locals>.<listcomp>, [])
issubclasstypingGeneric	TypeErrorjoin__name__)rf   r   param_namesparams_componentr_   r_   r`   model_parametrized_name  s
   
z!BaseModel.model_parametrized_name_BaseModel__contextc                 C     dS )zOverride this method to perform additional initialization after `__init__` and `model_construct`.
        This is useful if you want to do some validation that requires the entire model to be initialized.
        Nr_   )r]   r   r_   r_   r`   r     s   zBaseModel.model_post_init   )forceraise_errors_parent_namespace_depth_types_namespacer   r   r   intr   bool | Nonec          	      C  s   |s| j rdS d| jv rt| d |dur| }n-|dkr;tj|dp%i }t| jp-i }i ||}t	|| _nt| j}t
| |}i | jddi}tj| | jtj|dd||dS )	a1  Try to rebuild the pydantic-core schema for the model.

        This may be necessary when one of the annotations is a ForwardRef which could not be resolved during
        the initial attempt to build the schema, and automatic rebuilding fails.

        Args:
            force: Whether to force the rebuilding of the model schema, defaults to `False`.
            raise_errors: Whether to raise errors, defaults to `True`.
            _parent_namespace_depth: The depth level of the parent namespace, defaults to 2.
            _types_namespace: The types namespace, defaults to `None`.

        Returns:
            Returns `None` if the schema is already "complete" and rebuilding was not required.
            If rebuilding _was_ required, returns `True` if rebuilding was successful, otherwise `False`.
        NrC   r   )parent_depthdefer_buildF)check)r   types_namespace)rB   rV   delattrr   r   parent_frame_namespacer   unpack_lenient_weakvaluedictrG   build_lenient_weakvaluedictget_cls_types_namespacer<   complete_model_classr   r   ConfigWrapper)	rf   r   r   r   r   r   frame_parent_nscls_parent_nsconfigr_   r_   r`   model_rebuild  s0   



zBaseModel.model_rebuildstrictfrom_attributesr   objr   r   c                C  s   d}| j j||||dS )a  Validate a pydantic model instance.

        Args:
            obj: The object to validate.
            strict: Whether to enforce types strictly.
            from_attributes: Whether to extract data from object attributes.
            context: Additional context to pass to the validator.

        Raises:
            ValidationError: If the object could not be validated.

        Returns:
            The validated model instance.
        Tr   r[   )rf   r   r   r   r   r^   r_   r_   r`   model_validate  s   zBaseModel.model_validater   r   	json_datastr | bytes | bytearrayc                C     d}| j j|||dS )a  Usage docs: https://docs.pydantic.dev/2.7/concepts/json/#json-parsing

        Validate the given JSON data against the Pydantic model.

        Args:
            json_data: The JSON data to validate.
            strict: Whether to enforce types strictly.
            context: Extra variables to pass to the validator.

        Returns:
            The validated Pydantic model.

        Raises:
            ValueError: If `json_data` is not a JSON string.
        Tr   )rK   validate_json)rf   r   r   r   r^   r_   r_   r`   model_validate_json+  s   zBaseModel.model_validate_jsonc                C  r   )aR  Validate the given object contains string data against the Pydantic model.

        Args:
            obj: The object contains string data to validate.
            strict: Whether to enforce types strictly.
            context: Extra variables to pass to the validator.

        Returns:
            The validated Pydantic model.
        Tr   )rK   validate_strings)rf   r   r   r   r^   r_   r_   r`   model_validate_stringsF  s   z BaseModel.model_validate_stringssourcetype[BaseModel]handlerr   r0   c                C  s"   d| j v r| jd s| jS ||S )a  Hook into generating the model's CoreSchema.

        Args:
            source: The class we are generating a schema for.
                This will generally be the same as the `cls` argument if this is a classmethod.
            handler: Call into Pydantic's internal JSON schema generation.
                A callable that calls into Pydantic's internal CoreSchema generation logic.

        Returns:
            A `pydantic-core` `CoreSchema`.
        rC   origin)rV   rF   rC   )rf   r   r   r_   r_   r`   __get_pydantic_core_schema__\  s   

z&BaseModel.__get_pydantic_core_schema__core_schemar    r'   c                C  s   ||S )a_  Hook into generating the model's JSON schema.

        Args:
            core_schema: A `pydantic-core` CoreSchema.
                You can ignore this argument and call the handler with a new CoreSchema,
                wrap this CoreSchema (`{'type': 'nullable', 'schema': current_schema}`),
                or just call the handler with the original schema.
            handler: Call into Pydantic's internal JSON schema generation.
                This will raise a `pydantic.errors.PydanticInvalidForJsonSchema` if JSON schema
                generation fails.
                Since this gets called by `BaseModel.model_json_schema` you can override the
                `schema_generator` argument to that function to change JSON schema generation globally
                for a type.

        Returns:
            A JSON schema, as a Python object.
        r_   )rf   r   r   r_   r_   r`   __get_pydantic_json_schema__t  s   z&BaseModel.__get_pydantic_json_schema__kwargsc                 K  r   )a  This is intended to behave just like `__init_subclass__`, but is called by `ModelMetaclass`
        only after the class is actually fully initialized. In particular, attributes like `model_fields` will
        be present when this is called.

        This is necessary because `__init_subclass__` will always be called by `type.__new__`,
        and it would require a prohibitively large refactor to the `ModelMetaclass` to ensure that
        `type.__new__` was called in such a manner that the class would already be sufficiently initialized.

        This will receive the same `kwargs` that would be passed to the standard `__init_subclass__`, namely,
        any kwargs passed to the class definition that aren't used internally by pydantic.

        Args:
            **kwargs: Any keyword arguments passed to the class definition that aren't used internally
                by pydantic.
        Nr_   rf   r   r_   r_   r`   __pydantic_init_subclass__  s   z$BaseModel.__pydantic_init_subclass__typevar_values!type[Any] | tuple[type[Any], ...]3type[BaseModel] | _forward_ref.PydanticRecursiveRefc           
   	     s  t | |}|d ur|S | tu rtdt| ds t|  d| jd s2tj| jvr2t|  dt	|t
s:|f}t | | tt| jd | t    ra ra| }t | || |S | jd }|sk|}nt
 fdd|D }| jd	 p|| }||}t
d
d t   D }t ||N}	|	d ur|	W  d    S t | |||}|d ur|W  d    S z|jdd W n	 ty   Y nw t ||||}t | |||| W d    |S 1 sw   Y  |S )NzAType parameters should be placed on typing.Generic, not BaseModel__parameters__zG cannot be parametrized because it does not inherit from typing.Generic
parametersz is not a generic classargsc                 3  s    | ]	}t | V  qd S N)r   replace_types)ro   argtypevars_mapr_   r`   	<genexpr>      z.BaseModel.__class_getitem__.<locals>.<genexpr>r   c                 S  s   i | ]}|d qS r   r_   r   r_   r_   r`   rr     s    z/BaseModel.__class_getitem__.<locals>.<dictcomp>   )r   )r   get_cached_generic_type_earlyr+   r   r   rF   r   r   	__bases__rz   tuplecheck_parameters_countdictzipr   all_identicalr   rj   set_cached_generic_typer   iter_contained_typevarsgeneric_recursion_self_typeget_cached_generic_type_later   r"   create_generic_submodel)
rf   r   cachedsubmodelparent_argsr   r   
model_namer   maybe_self_typer_   r   r`   __class_getitem__  s^   

%

	
zBaseModel.__class_getitem__c                 C  s   t | }||}t|dt| j t|dt| j t|dt| j t| dr.| jdu r6t|dd |S t|ddd | j	 D  |S )z$Returns a shallow copy of the model.rV   rN   rP   rQ   Nc                 S     i | ]\}}|t ur||qS r_   r   rn   r_   r_   r`   rr         z&BaseModel.__copy__.<locals>.<dictcomp>)
typers   r   r   rV   rN   rP   r   rQ   ru   )r]   rf   r   r_   r_   r`   r     s   
zBaseModel.__copy__memodict[int, Any] | Nonec                 C  s   t | }||}t|dt| j|d t|dt| j|d t|dt| j t| dr2| j	du r:t|dd |S t|dtdd | j	
 D |d |S )	z!Returns a deep copy of the model.rV   )r  rN   rP   rQ   Nc                 S  r  r_   r   rn   r_   r_   r`   rr     r  z*BaseModel.__deepcopy__.<locals>.<dictcomp>)r  rs   r   r   rV   rN   r   rP   r   rQ   ru   )r]   r  rf   r   r_   r_   r`   r     s   
zBaseModel.__deepcopy__itemc              
     s  t | d}||v r;|| }t|dr|| t| S z| j| W S  ty: } ztt| jd||d }~ww zt | d}W n tyN   d }Y nw |rpz|| W S  tyo } ztt| jd||d }~ww t| j	|r|t
 |S tt| jd|)Nr@   __get__ object has no attribute rN   )object__getattribute__r   r  r  rQ   KeyErrorAttributeErrorr   	__class__super)r]   r  private_attributes	attributeexcpydantic_extrar  r_   r`   __getattr__  s4   

zBaseModel.__getattr__r   r   c              	   C  s  || j v rt|d| jj d| jj d| dt|sI| jd u s(|| jvr0t| || d S | j| }t	|drB|
| | d S || j|< d S | || t| j|d }t|trc|
| | d S | jdd rt| j| || d S | jddkr|| jvrtd	| jj d
| d	| jddkr|| jvr| jr|| jv r|| j|< d S zt| | W n ty   || j|< Y d S w t| || d S || j|< | j| d S )Nz is a ClassVar of `zR` and cannot be set on an instance. If you want to set a value on the class, use `.z
 = value`.__set__validate_assignmentrl   rm   "z" object has no field ")r?   r  r  r   r   is_valid_field_namerQ   r@   r   r   r&  _check_frozengetattrrz   propertyr<   r   rK   r'  r=   
ValueErrorrd   rN   rV   rP   rx   )r]   r   r   r   attrr_   r_   r`   __setattr__-  sJ   






zBaseModel.__setattr__c              
   C  s   || j v r7| j | }t|dr||  d S z| j|= W d S  ty6 } ztt| jd||d }~ww | |d  || j	v rJt
| | d S | jd urZ|| jv rZ| j|= d S z	t
| | W d S  tyv   tt| jd|w )N
__delete__r  )r@   r   r0  rQ   r  r  r  r   r*  r=   r  __delattr__rN   )r]   r  r   r!  r_   r_   r`   r1  X  s,   




zBaseModel.__delattr__c                 C  sT   | j dd r
d}nt| j|ddrd}nd S ||f|d}tj| jj|g)Nfrozenfrozen_instanceFfrozen_fieldr  locinput)	r<   r   r+  r=   pydantic_coreValidationErrorfrom_exception_datar  r   )r]   r   r   typerrorr_   r_   r`   r*  r  s   zBaseModel._check_frozendict[Any, Any]c                 C  s0   | j }|rdd | D }| j| j| j|dS )Nc                 S  r  r_   r   rn   r_   r_   r`   rr     r  z*BaseModel.__getstate__.<locals>.<dictcomp>)rV   rN   rP   rQ   )rQ   ru   rV   rN   rP   )r]   privater_   r_   r`   __getstate__  s   zBaseModel.__getstate__statec                 C  sD   t | d|d  t | d|d  t | d|d  t | d|d  d S )NrP   rN   rQ   rV   )r   )r]   r@  r_   r_   r`   __setstate__  s   zBaseModel.__setstate__otherc                 C  s  t |tr| jd p| j}|jd p|j}||kr+t| dd t|dd kr+| j|jks-dS | j|jkr5dS t| j	 }| j	 |krL|j	 |krLdS |rSt
j| ndd }z|| j||jkW S  ty   t| j}t|j}||||k Y S w tS )Nr   rQ   FTc                 S  s   t jS r   )r   	_SENTINEL_r_   r_   r`   <lambda>  s    z"BaseModel.__eq__.<locals>.<lambda>)rz   r+   rF   r  r+  rN   rV   r  r=   r   operator
itemgetterr  r   SafeGetItemProxyNotImplemented)r]   rB  	self_type
other_typer=   getterself_fields_proxyother_fields_proxyr_   r_   r`   __eq__  s*   
	zBaseModel.__eq__Unpack[ConfigDict]c                 K  r   )a  This signature is included purely to help type-checkers check arguments to class declaration, which
            provides a way to conveniently set model_config key/value pairs.

            ```py
            from pydantic import BaseModel

            class MyModel(BaseModel, extra='allow'):
                ...
            ```

            However, this may be deceiving, since the _actual_ calls to `__init_subclass__` will not receive any
            of the config arguments, and will only receive any keyword arguments passed during class initialization
            that are _not_ expected keys in ConfigDict. (This is due to the way `ModelMetaclass.__new__` works.)

            Args:
                **kwargs: Keyword arguments passed to the class definition, which set model_config

            Note:
                You may want to override `__pydantic_init_subclass__` instead, which behaves similarly but is called
                *after* the class is fully initialized.
            Nr_   r   r_   r_   r`   __init_subclass__  s    zBaseModel.__init_subclass__TupleGeneratorc                 c  s<    dd | j  D E dH  | j}|r| E dH  dS dS )zSo `dict(model)` works.c                 S  s"   g | ]\}}| d s||fqS rD  )
startswithrn   r_   r_   r`   r     s   " z&BaseModel.__iter__.<locals>.<listcomp>N)rV   ru   rN   )r]   rl   r_   r_   r`   __iter__  s   zBaseModel.__iter__c                 C  s   |    d| d dS )N(r   ))__repr_name____repr_str__rc   r_   r_   r`   __repr__  s   zBaseModel.__repr___repr.ReprArgsc                 #  s     j  D ]\}} j|}|r|jr||fV  qzt d}W n ty.   d }Y nw |d ur?dd | D E d H   fdd j D E d H  d S )NrN   c                 s  s    | ]	\}}||fV  qd S r   r_   rn   r_   r_   r`   r      r   z*BaseModel.__repr_args__.<locals>.<genexpr>c                 3  s(    | ]\}}|j r|t |fV  qd S r   )reprr+  rn   rc   r_   r`   r     s   & )	rV   ru   r=   r   r\  r  r  r  r>   )r]   rp   rq   r   r"  r_   rc   r`   __repr_args__  s   

"zBaseModel.__repr_args__c                 C  s
   |  dS )N )rY  rc   r_   r_   r`   __str__	  s   
zBaseModel.__str__EThe `__fields__` attribute is deprecated, use `model_fields` instead.categorydict[str, FieldInfo]c                 C     t jdtd | jS )Nr`  ra  )r   warnr)   r=   rc   r_   r_   r`   
__fields__  s   zBaseModel.__fields__MThe `__fields_set__` attribute is deprecated, use `model_fields_set` instead.c                 C  rd  )Nrg  ra  )r   re  r)   rP   rc   r_   r_   r`   __fields_set__  s
   zBaseModel.__fields_set__:The `dict` method is deprecated; use `model_dump` instead.r   r   r   r   r   r   typing.Dict[str, Any]c                C  s$   t jdtd | j||||||dS )Nri  ra  rj  )r   re  r)   r   )r]   r   r   r   r   r   r   r_   r_   r`   r  #  s   zBaseModel.dict?The `json` method is deprecated; use `model_dump_json` instead.)r   r   r   r   r   r   encodermodels_as_dictrm  "typing.Callable[[Any], Any] | Nonern  dumps_kwargsc          
      K  sP   t jdtd |turtd|turtd|	rtd| j||||||dS )Nrl  ra  zMThe `encoder` argument is no longer supported; use field serializers instead.zUThe `models_as_dict` argument is no longer supported; use a model serializer instead.z9`dumps_kwargs` keyword arguments are no longer supported.rj  )r   re  r)   r   r   r   )
r]   r   r   r   r   r   r   rm  rn  rp  r_   r_   r`   json8  s"   zBaseModel.jsonCThe `parse_obj` method is deprecated; use `model_validate` instead.c                 C     t jdtd | |S )Nrr  ra  r   re  r)   r   rf   r   r_   r_   r`   	parse_objX     
zBaseModel.parse_objThe `parse_raw` method is deprecated; if your data is JSON use `model_validate_json`, otherwise load the data then use `model_validate` instead.utf8)content_typeencodingprotoallow_picklebstr | bytesrz  
str | Noner{  r|  DeprecatedParseProtocol | Noner}  c             
   C  s   t jdtd ddlm} z|j|||||d}W nB ttfy[ } z4dd l}	t	|t
r/d}
nt	||	jr8d}
n
t	|tr@d	}
nd
}
t|
t|d|d}tj| j|gd }~ww | |S )Nrx  ra  r   parser|  rz  r{  r}  r   zvalue_error.unicodedecodezvalue_error.jsondecodevalue_error
type_error)__root__r5  )r   re  r)   
deprecatedr  load_str_bytesr-  r   rq  rz   UnicodeDecodeErrorJSONDecodeErrorr8  PydanticCustomErrorr|   r9  r:  r   r   )rf   r~  rz  r{  r|  r}  r  r   r!  rq  type_strr<  r_   r_   r`   	parse_raw`  s<   



zBaseModel.parse_rawThe `parse_file` method is deprecated; load the data from file, then if your data is JSON use `model_validate_json`, otherwise `model_validate` instead.path
str | Pathc                C  s8   t jdtd ddlm} |j|||||d}| |S )Nr  ra  r   r  r  )r   re  r)   r  r  	load_filerv  )rf   r  rz  r{  r|  r}  r  r   r_   r_   r`   
parse_file  s   
zBaseModel.parse_fileqThe `from_orm` method is deprecated; set `model_config['from_attributes']=True` and use `model_validate` instead.c                 C  s2   t jdtd | jdd stdd d| |S )Nr  ra  r   zHYou must set the config attribute `from_attributes=True` to use from_ormrT   )r   re  r)   r<   r   r#   r   ru  r_   r_   r`   from_orm  s   
zBaseModel.from_ormDThe `construct` method is deprecated; use `model_construct` instead.c                 K  s"   t jdtd | jdd|i|S )Nr  ra  rh   r_   )r   re  r)   r   )rf   rh   rj   r_   r_   r`   	construct  s   zBaseModel.constructThe `copy` method is deprecated; use `model_copy` instead. See the docstring of `BaseModel.copy` for details about how to handle `include` and `exclude`.)r   r   r   r   +AbstractSetIntStr | MappingIntStrAny | Nonetyping.Dict[str, Any] | Nonec             	   C  s
  t jdtd ddlm} t|j| dd||ddfi |pi }| jdu r(d}n
dd	 | j D }| j	du r:d}n)| j	
 }t| j	D ]}	|	|vrO||	 qDt|D ]}	|	| j	v rb||	||	< qT|rm| j| B }
nt| j}
|rz|
t|8 }
|j| ||
|||d
S )a  Returns a copy of the model.

        !!! warning "Deprecated"
            This method is now deprecated; use `model_copy` instead.

        If you need `include` or `exclude`, use:

        ```py
        data = self.model_dump(include=include, exclude=exclude, round_trip=True)
        data = {**data, **(update or {})}
        copied = self.model_validate(data)
        ```

        Args:
            include: Optional set or mapping specifying which fields to include in the copied model.
            exclude: Optional set or mapping specifying which fields to exclude in the copied model.
            update: Optional dictionary of field-value pairs to override field values in the copied model.
            deep: If True, the values of fields that are Pydantic models will be deep-copied.

        Returns:
            A copy of the model with included, excluded and updated fields as specified.
        r  ra  r   copy_internalsF)to_dictr   r   r   r   Nc                 S  r  r_   r   rn   r_   r_   r`   rr     r  z"BaseModel.copy.<locals>.<dictcomp>)r   )r   re  r)   r  r  r  _iterrQ   ru   rN   r   listrw   rP   r   rt   _copy_and_set_values)r]   r   r   r   r   r  rj   r>  rl   rp   r   r_   r_   r`   r     s@   #





zBaseModel.copyCThe `schema` method is deprecated; use `model_json_schema` instead.c                 C  s   t jdtd | j||dS )Nr  ra  r   r   )r   re  r)   r(   )rf   r   r   r_   r_   r`   schema  s   zBaseModel.schemaWThe `schema_json` method is deprecated; use `model_json_schema` and json.dumps instead.r  c                K  sB   t jdtd dd l}ddlm} |j| j||dfd|i|S )Nr  ra  r   r   )pydantic_encoderr  default)r   re  r)   rq  deprecated.jsonr  dumpsr(   )rf   r   r   rp  rq  r  r_   r_   r`   schema_json$  s   zBaseModel.schema_jsonBThe `validate` method is deprecated; use `model_validate` instead.c                 C  rs  )Nr  ra  rt  )rf   r   r_   r_   r`   validate:  rw  zBaseModel.validateLThe `update_forward_refs` method is deprecated; use `model_rebuild` instead.localnsc                 K  s*   t jdtd |rtd| jdd d S )Nr  ra  z,`localns` arguments are not longer accepted.T)r   )r   re  r)   r   r   )rf   r  r_   r_   r`   update_forward_refsB  s   zBaseModel.update_forward_refsHThe private method `_iter` will be removed and should no longer be used.r   c                 O  2   t jdtd ddlm} |j| g|R i |S )Nr  ra  r   r  )r   re  r)   r  r  r  r]   r   r   r  r_   r_   r`   r  P  s   zBaseModel._iterWThe private method `_copy_and_set_values` will be removed and should no longer be used.c                 O  r  )Nr  ra  r   r  )r   re  r)   r  r  r  r  r_   r_   r`   r  \     zBaseModel._copy_and_set_valuesMThe private method `_get_value` will be removed and should no longer be used.c                 O  r  )Nr  ra  r   r  )r   re  r)   r  r  
_get_value)rf   r   r   r  r_   r_   r`   r  i  s   zBaseModel._get_valueRThe private method `_calculate_keys` will be removed and should no longer be used.c                 O  r  )Nr  ra  r   r  )r   re  r)   r  r  _calculate_keysr  r_   r_   r`   r  w  r  zBaseModel._calculate_keys)rW   r   rX   rY   )rX   rM   )rX   rO   r   )rf   rg   rh   ri   rj   r   rX   r*   )r]   r*   r   rM   r   r   rX   r*   )r   r   r   r-   r   r-   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rX   r   )r   r   r   r-   r   r-   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rX   r|   )
r   r   r   r|   r   r   r   r&   rX   r   )r   r   rX   r|   )r   r   rX   rY   )
r   r   r   r   r   r   r   rM   rX   r   )rf   rg   r   r   r   r   r   r   r   rM   rX   r*   )
rf   rg   r   r   r   r   r   rM   rX   r*   )
rf   rg   r   r   r   r   r   rM   rX   r*   )r   r   r   r   rX   r0   )r   r0   r   r    rX   r'   )r   r   rX   rY   )r   r   rX   r   )r]   r*   rX   r*   )r]   r*   r  r  rX   r*   )r  r|   rX   r   )r   r|   r   r   rX   rY   )rX   r=  )r@  r=  rX   rY   )rB  r   rX   r   )r   rQ  )rX   rS  )rX   r|   )rX   r[  )rX   rc  )r   r-   r   r-   r   r   r   r   r   r   r   r   rX   rk  )r   r-   r   r-   r   r   r   r   r   r   r   r   rm  ro  rn  r   rp  r   rX   r|   )rf   rg   r   r   rX   r*   )rf   rg   r~  r  rz  r  r{  r|   r|  r  r}  r   rX   r*   )rf   rg   r  r  rz  r  r{  r|   r|  r  r}  r   rX   r*   )r]   r*   r   r  r   r  r   r  r   r   rX   r*   )r   r   r   r|   rX   rk  )r   r   r   r|   rp  r   rX   r|   )rf   rg   r   r   rX   r*   )r  r   rX   rY   )r   r   r   r   rX   r   )[r   
__module____qualname____doc__r   TYPE_CHECKING__annotations___FieldrN   rP   rQ   r=   r>   r   DecoratorInfosrE   rG   r   
MockValSerrK   rJ   	__slots__r!   r<   rB   rI   ra   __pydantic_base_init__r,  rd   re   classmethodr   r   r   r   r$   r%   r(   r   r   r   r   r   r   r   r   r   r  r   r   r$  r/  r1  r*  r?  rA  rP  rR  rU  rZ  r]  r   RepresentationrX  rY  
__pretty____rich_repr__r_  typing_extensionsr  rf  rh  r  r   rq  rv  r  r  r  r  r   r  r  r  r  r  r  r  r  __classcell__r_   r_   r#  r`   r+   B   s  
 	P837@ +7	/	G				)	metaclass)
__config__r  __base__r  __validators____cls_kwargs____model_namer|   r  ConfigDict | Noner  r  r  rY   r  r  dict[str, classmethod] | Noner  rM   field_definitionsr   rX   r   c                K     d S r   r_   r  r  r  r  r  r  r  r  r_   r_   r`   r;        r;   )r  r  r  r  r  %type[Model] | tuple[type[Model], ...]rg   c                K  r  r   r_   r  r_   r_   r`   r;     r  )r  r  r  r  r  r  r  ,type[Model] | tuple[type[Model], ...] | Noner  tuple[str, ...] | Nonec                K  s  |dur
t dt |dur!|durtdddt|ts |f}n
ttjd t	f}|p.i }i }	i }
|
 D ]f\}}t|sJt d| dt t|trotd	|}z|\}}W n7 tyn } ztd
dd|d}~ww t|rt|^}}}ddlm} t||stdddnd|}}|r||
|< ||	|< q7|du rtd}|jd }|
|d}|r|d|i |r|| ||	 |rt|j|d< t|}tj| ||d\}}}||ur||d< || || ||fd|d|S )a2  Usage docs: https://docs.pydantic.dev/2.7/concepts/models/#dynamic-model-creation

    Dynamically creates and returns a new Pydantic model, in other words, `create_model` dynamically creates a
    subclass of [`BaseModel`][pydantic.BaseModel].

    Args:
        __model_name: The name of the newly created model.
        __config__: The configuration of the new model.
        __doc__: The docstring of the new model.
        __base__: The base class or classes for the new model.
        __module__: The name of the module that the model belongs to;
            if `None`, the value is taken from `sys._getframe(1)`
        __validators__: A dictionary of methods that validate fields.
        __cls_kwargs__: A dictionary of keyword arguments for class creation, such as `metaclass`.
        __slots__: Deprecated. Should not be passed to `create_model`.
        **field_definitions: Attributes of the new model. They should be passed in the format:
            `<name>=(<type>, <default value>)`, `<name>=(<type>, <FieldInfo>)`, or `typing.Annotated[<type>, <FieldInfo>]`.
            Any additional metadata in `typing.Annotated[<type>, <FieldInfo>, ...]` will be ignored.

    Returns:
        The new [model][pydantic.BaseModel].

    Raises:
        PydanticUserError: If `__base__` and `__config__` are both passed.
    Nz.__slots__ should not be passed to create_modelzFto avoid confusion `__config__` and `__base__` cannot be used togetherzcreate-model-config-baser  r*   z3fields may not start with an underscore, ignoring "r(  ztuple[str, Any]z4Field definitions should be a `(<type>, <default>)`.zcreate-model-field-definitionsr   )r8   z<Field definitions should be a Annotated[<type>, <FieldInfo>]r   )r  r  r  r<   )kwds__orig_bases__F)#__pydantic_reset_parent_namespace___create_model_module)r   re  RuntimeWarningr#   rz   r  r   castTyper+   ru   r   r)  r-  r   is_annotatedr  get_argsfieldsr8   sys	_getframe	f_globalsr   r   r   config_dicttypesresolve_basesprepare_class)r  r  r  r  r  r  r  r  r  r  r   f_namef_deff_annotationf_valueerE  r8   f	namespaceresolved_basesmetansr  r_   r_   r`   r;     s   %














)r  r|   r  r  r  r  r  rY   r  r|   r  r  r  rM   r  r   rX   r   )r  r|   r  r  r  r  r  r  r  r|   r  r  r  rM   r  r   rX   rg   )r  r|   r  r  r  r  r  r  r  r  r  r  r  rM   r  r  r  r   rX   rg   )\r  
__future__r   _annotationsrG  r  r  r   r   r   r   r   r   r   r   r	   r
   r   r   r   r8  r  r   r   	_internalr   r   r   r   r   r   r   r   r   r   
_migrationr   aliasesr   r   annotated_handlersr   r    r   r!   errorsr"   r#   json_schemar$   r%   r&   r'   r(   r)   r*   r|   rS  r   r-   r  r  inspectr.   pathlibr/   r0   r1   r2   r3   _internal._utilsr4   r5   deprecated.parser6   DeprecatedParseProtocolr  r7   r8   r9   r:   r  DeprecationWarning__all__object_setattrr   ModelMetaclassr+   overloadr   r;   r$  r_   r_   r_   r`   <module>   s    ,02          Mu