B
    hndh                 @  st  U d Z ddlm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
 ddlZddl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mZ dd	lmZ dd
lm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) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/ ddlm0Z0 ej1rddl2m3Z3 ddl4m5Z5 ddlm6Z6m7Z7m8Z8 ddlm9Z9m:Z: ddl;m<Z<m=Z= ddl&m>Z? e@e	e	e	f ZAejBejCeDe	f ddf ZEejFdddZGdZHdeId< ne0ZJdZKejLZMG dd dejNdZOejPddeQddd d!d"d#d!d$d%d&d'd(d)d*ZRejPdeQddd+d!d"d,d!d$d%d&d-d(d.d*ZRddeQdddd/d!d"d0d!d$d%d1d&d-d2	d3d*ZReeQZSdS )4zLogic for creating models.    )annotationsN)copydeepcopy)AnyClassVar)PydanticUndefined   )_annotated_handlers_config_decorators_fields_forward_ref	_generics_mock_validator_model_construction_repr_typing_extra_utils)getattr_migration)
ConfigDict)copy_internals)parse)PydanticUndefinedAnnotationPydanticUserError)ComputedFieldInfo	FieldInfoModelPrivateAttr)DEFAULT_REF_TEMPLATEGenerateJsonSchemaJsonSchemaModeJsonSchemaValuemodel_json_schema)PydanticDeprecatedSince20)	Signature)Path)
CoreSchemaSchemaSerializerSchemaValidator)LiteralUnpack)AbstractSetIntStrMappingIntStrAny)FieldModel	BaseModel)boundz<set[int] | set[str] | dict[int, Any] | dict[str, Any] | Noneztyping_extensions.TypeAliasIncEx)r.   create_modelc                  s  e Zd ZU dZejrd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e Zejd%d&d'Zd(Ze ZdZdZd)d*d+d,d-Zd.e_ed/d0d1d2Zed d0d3d4Zed"d0d5d6Zedd8d9d)d:d;d<d=Zd7dd>d:d d?d:d@dAdBZdCd7d7dddddd.dD	dEdFdFd?d?d?d?d?d?dGdH
dIdJZ d7d7d7dddddd.dK	dLdFdFd?d?d?d?d?d?dMdN
dOdPZ!ed.e"e#dQfd?dMdRdSdGdTdUdVZ$edWdMdXdYdZZ%d)d*d[d\d]Z&edd.d^d7d_d?d?d`d dadbdcddZ'ed7d7d7ded8d)dadad d:dfdgdhZ(ed7d7did8djdad d:dkdldmZ)edndodpdqdrdsZ*edpdtdudvdwdxZ+ed)d*dydzd{Z,d|d}d~ddZ-d:d:dddZ.dd:dd:dddZ/ejs$dMd)d fddZ0dMd)d*dddZ1dMd)dddZ2dd0ddZ3dd*dddZ4d)d?dddZ5ejrddddZ6dd0ddZ7dMd0ddZ8dd0ddZ9e:j;j<Z<e:j;j=Z=e:j;j>Z>e:j;j?Z?dMd0ddZ@eeAjBdeCddd0ddZDeeAjBdeCdd"d0ddZEeAjBdeCdd7d7ddddddFdFd?d?d?d?ddddZFeAjBdeCdd7d7ddddeGeGddFdFd?d?d?d?dd?d)dMd
ddZHeeAjBdeCdd8d)d:dddZIeeAjBdeCdd7dd7ddd8dddMdd?d:dŜddǄZJeeAjBdeCdd7dd7ddd8dddMdd?d:dʜdd̄ZKeeAjBdeCdd8d)d:dddτZLeeAjBdeCddd8d9d)d:d;dd҄ZMeAjBdeCdd7d7d7ddԜd:dddd?d:dלddلZNeeAjBdeCdd.e"fd?dMddۜdd݄ZOeeAjBdeCdd.e"dߜd?dMd)dMdddZPeeAjBdeCdd8d)d:dddZQeeAjBdeCdd)d*dddZReAjBdeCdd)d)d)dddZSeAjBdeCdd)d)d)dddZTeeAjBdeCdd)d)d)dddZUeAjBdeCdd)d)d)dddZV  ZWS )r.   a  A base model class for creating Pydantic models.

    Attributes:
        model_config: Configuration settings for the model.
        model_fields: Metadata about the fields defined on the model.
            This replaces `Model.__fields__` from Pydantic V1.

        __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 specified during validation.
        __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[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__Z__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)initzdict[str, Any] | None__pydantic_extra__zset[str]__pydantic_fields_set____pydantic_private__zXPydantic models should inherit from BaseModel, BaseModel cannot be instantiated directlyzbase-model-instantiated)code)__dict__rB   rA   rC   r   None)datareturnc             K  s   d}| j j|| d dS )a1  Create a new model by parsing and validating input data from keyword arguments.

        Raises ValidationError if the input data cannot be parsed to form a valid model.

        Uses `__pydantic_self__` instead of the more common `self` for the first arg to
        allow `self` as a field name.
        T)Zself_instanceN)r?   validate_python)Z__pydantic_self__rG   __tracebackhide__ rK   1/tmp/pip-unpacked-wheel-y3jxpnai/pydantic/main.py__init__   s    	zBaseModel.__init__Tzdict[str, ComputedFieldInfo])rH   c             C  s   dd | j j D S )zGet the computed fields of this model instance.

        Returns:
            A dictionary of computed field names and their corresponding `ComputedFieldInfo` objects.
        c             S  s   i | ]\}}|j |qS rK   )info).0kvrK   rK   rL   
<dictcomp>   s    z3BaseModel.model_computed_fields.<locals>.<dictcomp>)r9   Zcomputed_fieldsitems)selfrK   rK   rL   model_computed_fields   s    zBaseModel.model_computed_fieldsc             C  s   | j S )zGet extra fields set during validation.

        Returns:
            A dictionary of extra fields, or `None` if `config.extra` is not set to `"allow"`.
        )rA   )rT   rK   rK   rL   model_extra   s    zBaseModel.model_extrac             C  s   | j S )zReturns the set of fields that have been 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.
        )rB   )rT   rK   rK   rL   model_fields_set   s    zBaseModel.model_fields_setNztype[Model]zset[str] | Noner-   )cls_fields_setvaluesrH   c             K  s4  |  | }i }i }xh| j D ]Z\}}|jrH|j|krH||j||< q||kr`||||< q| s|jdd||< qW |dkrt| }|	| d}| j
ddkri }x(| D ]\}	}
|
||	< qW n
|	| t|d| t|d| | jst|d| | jr|d n| js0t|d	d |S )
aS  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.
        Behaves as if `Config.extra = 'allow'` was set since it adds all passed values

        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.
        T)Zcall_default_factoryNextraallowrE   rB   rA   rC   )__new__r3   rS   aliaspopZis_requiredget_defaultsetkeysupdater2   get_object_setattrr=   r<   model_post_init)rX   rY   rZ   mZfields_valuesdefaultsnamefieldZ_extrarP   rQ   rK   rK   rL   model_construct   s8    


zBaseModel.model_construct)rc   deepbool)rT   rc   rl   rH   c            C  s   |r|   n|  }|r| jddkrpxR| D ]8\}}|| jkrP||j|< q2|jdkr`i |_||j|< q2W n|j| |j	|
  |S )aN  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.
        r[   r\   N)__deepcopy____copy__r2   rd   rS   r3   rE   rA   rc   rB   rb   )rT   rc   rl   copiedrP   rQ   rK   rK   rL   
model_copy   s    

zBaseModel.model_copypython)	modeincludeexcludeby_aliasexclude_unsetexclude_defaultsexclude_none
round_tripwarningsz!Literal[('json', 'python')] | strr0   zdict[str, Any])
rs   rt   ru   rv   rw   rx   ry   rz   r{   rH   c   	   
      C  s    | j j| |||||||||	d
S )a  Usage docs: https://docs.pydantic.dev/dev-v2/usage/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 dictionary will only contain JSON serializable types.
                If mode is 'python', the dictionary may contain any Python objects.
            include: A list of fields to include in the output.
            exclude: A list of fields to exclude from the output.
            by_alias: Whether to use the field's alias in the dictionary key if defined.
            exclude_unset: Whether to exclude fields that are unset or None from the output.
            exclude_defaults: Whether to exclude fields that are set to their default value from the output.
            exclude_none: Whether to exclude fields that have a value of `None` from the output.
            round_trip: Whether to enable serialization and deserialization round-trip support.
            warnings: Whether to log warnings when invalid fields are encountered.

        Returns:
            A dictionary representation of the model.
        )	rs   rv   rt   ru   rw   rx   ry   rz   r{   )r>   Z	to_python)
rT   rs   rt   ru   rv   rw   rx   ry   rz   r{   rK   rK   rL   
model_dump  s    !zBaseModel.model_dump)	indentrt   ru   rv   rw   rx   ry   rz   r{   z
int | Nonestr)
r}   rt   ru   rv   rw   rx   ry   rz   r{   rH   c   	   
      C  s$   | j j| |||||||||	d
 S )aI  Usage docs: https://docs.pydantic.dev/dev-v2/usage/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. Can take either a string or set of strings.
            exclude: Field(s) to exclude from the JSON output. Can take either a string or set of strings.
            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 have the default value.
            exclude_none: Whether to exclude fields that have a value of `None`.
            round_trip: Whether to use serialization/deserialization between JSON and class instance.
            warnings: Whether to show any warnings that occurred during serialization.

        Returns:
            A JSON string representation of the model.
        )	r}   rt   ru   rv   rw   rx   ry   rz   r{   )r>   Zto_jsondecode)
rT   r}   rt   ru   rv   rw   rx   ry   rz   r{   rK   rK   rL   model_dump_json1  s    zBaseModel.model_dump_jsonZ
validationztype[GenerateJsonSchema]r   )rv   ref_templateschema_generatorrs   rH   c             C  s   t | ||||dS )a  Generates a JSON schema for a model class.

        To override the logic used to generate the JSON schema, you can create a subclass of `GenerateJsonSchema`
        with your desired modifications, then override this method on a custom base class and set the default
        value of `schema_generator` to be your subclass.

        Args:
            by_alias: Whether to use attribute aliases or not.
            ref_template: The reference template.
            schema_generator: The JSON schema generator.
            mode: The mode in which to generate the schema.

        Returns:
            The JSON schema for the given model class.
        )rv   r   r   rs   )r!   )rX   rv   r   r   rs   rK   rK   rL   r!   ]  s    zBaseModel.model_json_schemaztuple[type[Any], ...])paramsrH   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 rK   )
isinstancer~   r   Zdisplay_as_type)rO   paramrK   rK   rL   
<listcomp>  s    z5BaseModel.model_parametrized_name.<locals>.<listcomp>z, [])
issubclasstypingGeneric	TypeErrorjoin__name__)rX   r   Zparam_namesZparams_componentrK   rK   rL   model_parametrized_namex  s
    
z!BaseModel.model_parametrized_name)_BaseModel__contextrH   c             C  s   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.
        NrK   )rT   r   rK   rK   rL   rf     s    zBaseModel.model_post_init   )forceraise_errors_parent_namespace_depth_types_namespaceintzbool | None)r   r   r   r   rH   c            C  s   |s| j rdS |dk	r | }n>|dkrLtj|dp6i }| jp@i }||| _| j}t| |}tj| | jt	j
| jdd||dS 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`.
        Nr   )Zparent_depthF)check)r   types_namespace)r7   r   r   Zparent_frame_namespacer;   Zget_cls_types_namespacer   Zcomplete_model_classr   r
   ConfigWrapperr2   )rX   r   r   r   r   r   Zframe_parent_nsZcls_parent_nsrK   rK   rL   model_rebuild  s     



zBaseModel.model_rebuild)strictfrom_attributescontext)rX   objr   r   r   rH   c            C  s   d}| j j||||dS )a  Validate a pydantic model instance.

        Args:
            obj: The object to validate.
            strict: Whether to raise an exception on invalid fields.
            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.
        T)r   r   r   )r?   rI   )rX   r   r   r   r   rJ   rK   rK   rL   model_validate  s    zBaseModel.model_validate)r   r   zstr | bytes | bytearray)rX   	json_datar   r   rH   c            C  s   d}| j j|||dS )a  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.
        T)r   r   )r?   Zvalidate_json)rX   r   r   r   rJ   rK   rK   rL   model_validate_json  s    zBaseModel.model_validate_jsonztype[BaseModel]z(_annotated_handlers.GetCoreSchemaHandlerr%   )_BaseModel__source_BaseModel__handlerrH   c             C  s"   d| j k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`.
        r8   origin)rE   r:   r8   )rX   r   r   rK   rK   rL   __get_pydantic_core_schema__  s    

z&BaseModel.__get_pydantic_core_schema__z(_annotated_handlers.GetJsonSchemaHandlerr    )_BaseModel__core_schemar   rH   c             C  s   ||S )ac  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.
        rK   )rX   r   r   rK   rK   rL   __get_pydantic_json_schema__  s    z&BaseModel.__get_pydantic_json_schema__)kwargsrH   c             K  s   dS )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.
        NrK   )rX   r   rK   rK   rL   __pydantic_init_subclass__0  s    z$BaseModel.__pydantic_init_subclass__z!type[Any] | tuple[type[Any], ...]z3type[BaseModel] | _forward_ref.PydanticRecursiveRef)typevar_valuesrH   c       
   	     s  t | |}|d k	r|S | tkr(tdt| ds@t|  d| jd sdtj| jkrdt|  dt	|t
st|f}t | | tt| jd | t    r r| }t | || n| jd }|s|}nt
 fdd|D }| jd	 p| }||}t
d
d t   D }t |||}	|	d k	r:|	S t | |||}|d k	rX|S y|jdd W n tk
r~   Y nX t ||||}t | |||| W d Q R X |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   Zreplace_types)rO   arg)typevars_maprK   rL   	<genexpr>b  s    z.BaseModel.__class_getitem__.<locals>.<genexpr>r   c             S  s   i | ]
}d |qS )NrK   )rO   r   rK   rK   rL   rR   g  s    z/BaseModel.__class_getitem__.<locals>.<dictcomp>   )r   )r   Zget_cached_generic_type_earlyr.   r   hasattrr:   r   r   	__bases__r   tupleZcheck_parameters_countdictzipr   Zall_identicalrb   rZ   Zset_cached_generic_typer   Ziter_contained_typevarsZgeneric_recursion_self_typeZget_cached_generic_type_later   r   Zcreate_generic_submodel)
rX   r   cachedZsubmodelZparent_argsr   r   Z
model_namer   Zmaybe_self_typerK   )r   rL   __class_getitem__C  sL    





zBaseModel.__class_getitem__)rT   rH   c             C  s   t | }||}t|dt| j t|dt| j t|dt| j | jdkr`t|dd nt|ddd | j D  |S )z$Returns a shallow copy of the model.rE   rA   rB   NrC   c             S  s   i | ]\}}|t k	r||qS rK   )r   )rO   rP   rQ   rK   rK   rL   rR     s    z&BaseModel.__copy__.<locals>.<dictcomp>)	typer]   re   r   rE   rA   rB   rC   rS   )rT   rX   rg   rK   rK   rL   ro     s    

zBaseModel.__copy__zdict[int, Any] | None)rT   memorH   c             C  s   t | }||}t|dt| j|d t|dt| j|d t|dt| j | jdkrht|dd n$t|dtdd | j	 D |d |S )	z!Returns a deep copy of the model.rE   )r   rA   rB   NrC   c             S  s   i | ]\}}|t k	r||qS rK   )r   )rO   rP   rQ   rK   rK   rL   rR     s    z*BaseModel.__deepcopy__.<locals>.<dictcomp>)
r   r]   re   r   rE   rA   r   rB   rC   rS   )rT   r   rX   rg   rK   rK   rL   rn     s    

zBaseModel.__deepcopy__)itemrH   c          
     s  t | d}||kr|| }t|dr6|| t| S y
| j| S  tk
r| } ztt| jd||W d d }~X Y nX nt | d}|d k	ry|| S  tk
r } ztt| jd||W d d }~X Y nX n0t| j	|rt
 |S tt| jd|d S )Nr5   __get__z object has no attribute rA   )object__getattribute__r   r   r   rC   KeyErrorAttributeErrorr   	__class__super)rT   r   Zprivate_attributes	attributeexcpydantic_extra)r   rK   rL   __getattr__  s$    

..zBaseModel.__getattr__)ri   valuerH   c          	   C  s  || j kr4t|d| jj d| jj d| dnt|s| jd ksR|| jkr`t| || n,| j| }t	|dr|
| | n
|| j|< d S | jdd rd|f|d}tj| jj|gt| j|d }t|tr|
| | n| jd	d r| j| || nz| jd
dkrB|| jkrBtd| jj d| dn@| jd
dkrl|| jkrl|| j|< n|| 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__frozenZfrozen_instance)r   locinputvalidate_assignmentr[   r\   "z" object has no field ")r4   r   r   r   r   is_valid_field_namerC   r5   re   r   r   r2   rd   pydantic_coreValidationErrorfrom_exception_datagetattrr   propertyr?   r   r3   
ValueErrorrA   rE   rB   add)rT   ri   r   r   errorattrrK   rK   rL   __setattr__  s6    
(





zBaseModel.__setattr__c          
   C  s   || j krx| j | }t|dr,||  d S y| j|= W q tk
rt } ztt| jd||W d d }~X Y qX nt|| jkrt	
| | n\| jd k	r|| jkr| j|= n>yt	
| | W n, tk
r   tt| jd|Y nX d S )N
__delete__z object has no attribute )r5   r   r   rC   r   r   r   r   r3   r   __delattr__rA   )rT   r   r   r   rK   rK   rL   r     s"    



.

zBaseModel.__delattr__zdict[Any, Any]c             C  s0   | j }|rdd | D }| j| j| j|dS )Nc             S  s   i | ]\}}|t k	r||qS rK   )r   )rO   rP   rQ   rK   rK   rL   rR     s    z*BaseModel.__getstate__.<locals>.<dictcomp>)rE   rA   rB   rC   )rC   rS   rE   rA   rB   )rT   privaterK   rK   rL   __getstate__  s    zBaseModel.__getstate__)staterH   c             C  sD   t | d|d  t | d|d  t | d|d  t | d|d  d S )NrE   rB   rA   rC   )re   )rT   r   rK   rK   rL   __setstate__  s    zBaseModel.__setstate__)otherrH   c             C  s^   t |trV| jd p| j}|jd p(|j}||koT| j|jkoT| j|jkoT| j|jkS tS d S )Nr   )r   r.   r:   r   rE   rC   rA   NotImplemented)rT   r   	self_typeZ
other_typerK   rK   rL   __eq__  s    
zBaseModel.__eq__zUnpack[ConfigDict])r   c             K  s   dS )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.
            NrK   )rX   r   rK   rK   rL   __init_subclass__,  s    zBaseModel.__init_subclass__TupleGeneratorc             c  s   | j  E dH  dS )zSo `dict(model)` works.N)rE   rS   )rT   rK   rK   rL   __iter__C  s    zBaseModel.__iter__c             C  s   |    d| d dS )N(z, ))__repr_name____repr_str__)rT   rK   rK   rL   __repr__G  s    zBaseModel.__repr__z_repr.ReprArgsc             #  s   x6 j  D ](\}} j|}|r|jr||fV  qW  j}|d k	r^dd | D E d H   fdd j D E d H  d S )Nc             s  s   | ]\}}||fV  qd S )NrK   )rO   rP   rQ   rK   rK   rL   r   Q  s    z*BaseModel.__repr_args__.<locals>.<genexpr>c             3  s&   | ]\}}|j r|t |fV  qd S )N)reprr   )rO   rP   rQ   )rT   rK   rL   r   R  s    )rE   rS   r3   rd   r   rA   rU   )rT   rP   rQ   rj   r   rK   )rT   rL   __repr_args__J  s    
zBaseModel.__repr_args__c             C  s
   |  dS )N )r   )rT   rK   rK   rL   __str__Z  s    zBaseModel.__str__zEThe `__fields__` attribute is deprecated, use `model_fields` instead.)categoryzdict[str, FieldInfo]c             C  s   t dt | jS )NzEThe `__fields__` attribute is deprecated, use `model_fields` instead.)r{   warnDeprecationWarningr3   )rT   rK   rK   rL   
__fields__^  s    zBaseModel.__fields__zMThe `__fields_set__` attribute is deprecated, use `model_fields_set` instead.c             C  s   t dt | jS )NzMThe `__fields_set__` attribute is deprecated, use `model_fields_set` instead.)r{   r   r   rB   )rT   rK   rK   rL   __fields_set__f  s    zBaseModel.__fields_set__z:The `dict` method is deprecated; use `model_dump` instead.)rt   ru   rv   rw   rx   ry   ztyping.Dict[str, Any])rt   ru   rv   rw   rx   ry   rH   c            C  s"   t dt | j||||||dS )Nz:The `dict` method is deprecated; use `model_dump` instead.)rt   ru   rv   rw   rx   ry   )r{   r   r   r|   )rT   rt   ru   rv   rw   rx   ry   rK   rK   rL   r   q  s    zBaseModel.dictz?The `json` method is deprecated; use `model_dump_json` instead.)rt   ru   rv   rw   rx   ry   encodermodels_as_dictz"typing.Callable[[Any], Any] | None)
rt   ru   rv   rw   rx   ry   r   r   dumps_kwargsrH   c      
      K  sN   t dt |tk	rtd|tk	r,td|	r8td| j||||||dS )Nz?The `json` method is deprecated; use `model_dump_json` instead.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.)rt   ru   rv   rw   rx   ry   )r{   r   r   r   r   r   )
rT   rt   ru   rv   rw   rx   ry   r   r   r   rK   rK   rL   json  s    zBaseModel.jsonzCThe `parse_obj` method is deprecated; use `model_validate` instead.)rX   r   rH   c             C  s   t dt | |S )NzCThe `parse_obj` method is deprecated; use `model_validate` instead.)r{   r   r   r   )rX   r   rK   rK   rL   	parse_obj  s    zBaseModel.parse_objzThe `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_picklezstr | bytesz
str | Nonez!_deprecated_parse.Protocol | None)rX   br   r   r   r   rH   c         
   C  s   t dt ytj|||||d}W n ttfk
r } zldd l}t|t	rRd}	n&t||j
rdd}	nt|trtd}	nd}	t|	t|d|d	}
tj| j|
gW d d }~X Y nX | |S )
NzThe `parse_raw` method is deprecated; if your data is JSON use `model_validate_json`, otherwise load the data then use `model_validate` instead.)r   r   r   r   r   zvalue_error.unicodedecodezvalue_error.jsondecodeZvalue_errorZ
type_error)Z__root__)r   r   r   )r{   r   r   _deprecated_parseZload_str_bytesr   r   r   r   UnicodeDecodeErrorJSONDecodeErrorr   ZPydanticCustomErrorr~   r   r   r   r   )rX   r   r   r   r   r   r   r   r   Ztype_strr   rK   rK   rL   	parse_raw  s0    

$zBaseModel.parse_rawzThe `parse_file` method is deprecated; load the data from file, then if your data is JSON use `model_validate_json`, otherwise `model_validate` instead.z
str | Path)rX   pathr   r   r   r   rH   c            C  s*   t dt tj|||||d}| |S )NzThe `parse_file` method is deprecated; load the data from file, then if your data is JSON use `model_validate_json` otherwise `model_validate` instead.)r   r   r   r   )r{   r   r   r   Z	load_filer   )rX   r  r   r   r   r   r   rK   rK   rL   
parse_file  s    zBaseModel.parse_filezqThe `from_orm` method is deprecated; set `model_config['from_attributes']=True` and use `model_validate` instead.c             C  s0   t dt | jdd s&tdd d| |S )NzqThe `from_orm` method is deprecated; set `model_config["from_attributes"]=True` and use `model_validate` instead.r   zHYou must set the config attribute `from_attributes=True` to use from_orm)rD   )r{   r   r   r2   rd   r   r   )rX   r   rK   rK   rL   from_orm   s    
zBaseModel.from_ormzDThe `construct` method is deprecated; use `model_construct` instead.c             K  s    t dt | jf d|i|S )NzDThe `construct` method is deprecated; use `model_construct` instead.rY   )r{   r   r   rk   )rX   rY   rZ   rK   rK   rL   	construct  s    zBaseModel.constructz8The copy method is deprecated; use `model_copy` instead.)rt   ru   rc   rl   z+AbstractSetIntStr | MappingIntStrAny | Noneztyping.Dict[str, Any] | None)rT   rt   ru   rc   rl   rH   c      
   	   C  s   t dt ttj| dd||ddf|p*i }| jdkr>d}ndd | j D }| jdkrbd}nZ| j	 }x$t
| jD ]}||krx|| qxW x(t
|D ]}|| jkr||||< qW |r| j| B }	n
t| j}	|r|	t|8 }	tj| ||	|||dS )a  Returns a copy of the model.

        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.
        zThe `copy` method is deprecated; use `model_copy` instead. See the docstring of `BaseModel.copy` for details about how to handle `include` and `exclude`.F)Zto_dictrv   rt   ru   rw   Nc             S  s   i | ]\}}|t k	r||qS rK   )r   )rO   rP   rQ   rK   rK   rL   rR   J  s    z"BaseModel.copy.<locals>.<dictcomp>)rl   )r{   r   r   r   _deprecated_copy_internals_iterrC   rS   rA   r   listr_   rB   rb   ra   _copy_and_set_values)
rT   rt   ru   rc   rl   rZ   r   r[   rP   Z
fields_setrK   rK   rL   r     s2    !





zBaseModel.copyzCThe `schema` method is deprecated; use `model_json_schema` instead.)rv   r   rH   c             C  s   t dt | j||dS )NzCThe `schema` method is deprecated; use `model_json_schema` instead.)rv   r   )r{   r   r   r!   )rX   rv   r   rK   rK   rL   schemac  s    zBaseModel.schemazWThe `schema_json` method is deprecated; use `model_json_schema` and json.dumps instead.)rv   r   )rv   r   r   rH   c            K  s@   dd l }tdt ddlm} |j| j||dfd|i|S )Nr   zWThe `schema_json` method is deprecated; use `model_json_schema` and json.dumps instead.r   )pydantic_encoder)rv   r   default)r   r{   r   r   Zdeprecated.jsonr  dumpsr!   )rX   rv   r   r   r   r  rK   rK   rL   schema_jsonm  s    zBaseModel.schema_jsonzBThe `validate` method is deprecated; use `model_validate` instead.)rX   r   rH   c             C  s   t dt | |S )NzBThe `validate` method is deprecated; use `model_validate` instead.)r{   r   r   r   )rX   r   rK   rK   rL   validate  s    zBaseModel.validatezLThe `update_forward_refs` method is deprecated; use `model_rebuild` instead.)localnsrH   c             K  s(   t dt |rtd| jdd d S )NzLThe `update_forward_refs` method is deprecated; use `model_rebuild` instead.z,`localns` arguments are not longer accepted.T)r   )r{   r   r   r   r   )rX   r  rK   rK   rL   update_forward_refs  s
    zBaseModel.update_forward_refszHThe private method `_iter` will be removed and should no longer be used.)r   r   rH   c             O  s   t dt tj| f||S )NzHThe private method `_iter` will be removed and should no longer be used.)r{   r   r   r  r	  )rT   r   r   rK   rK   rL   r	    s    zBaseModel._iterzWThe private method `_copy_and_set_values` will be removed and should no longer be used.c             O  s   t dt tj| f||S )NzXThe private method  `_copy_and_set_values` will be removed and should no longer be used.)r{   r   r   r  r  )rT   r   r   rK   rK   rL   r    s    zBaseModel._copy_and_set_valueszMThe private method `_get_value` will be removed and should no longer be used.c             O  s   t dt tj| f||S )NzNThe private method  `_get_value` will be removed and should no longer be used.)r{   r   r   r  
_get_value)rX   r   r   rK   rK   rL   r    s    zBaseModel._get_valuezRThe private method `_calculate_keys` will be removed and should no longer be used.c             O  s   t dt tj| f||S )NzRThe private method `_calculate_keys` will be removed and should no longer be used.)r{   r   r   r  _calculate_keys)rT   r   r   rK   rK   rL   r    s    zBaseModel._calculate_keys)N)N)N)Xr   
__module____qualname____doc__r   TYPE_CHECKING__annotations___FieldrA   rB   rC   r3   r   ZDecoratorInfosr9   r   ZMockValidatorr?   	__slots__r   r2   r7   r=   rM   Z__pydantic_base_init__r   rU   rV   rW   classmethodrk   rq   r|   r   r   r   r!   r   rf   r   r   r   r   r   r   r   ro   rn   r   r   r   r   r   r   r   r   r   r   r   ZRepresentationr   r   Z
__pretty__Z__rich_repr__r   typing_extensions
deprecatedr"   r   r   r   r   r   r   r  r  r  r  r   r  r  r  r  r	  r  r  r  __classcell__rK   rK   )r   rL   r.   =   sn  
		
1&&&!' @'"($&$ @ 
	)	metaclass)
__config____base__r  __validators____cls_kwargs__r~   zConfigDict | NonerF   z dict[str, AnyClassMethod] | Nonezdict[str, Any] | Noner   ztype[BaseModel])__model_namer"  r#  r  r$  r%  field_definitionsrH   c            K  s   d S )NrK   )r&  r"  r#  r  r$  r%  r'  rK   rK   rL   r1     s    r1   )r"  r  r$  r%  z%type[Model] | tuple[type[Model], ...]ztype[Model]c            K  s   d S )NrK   )r&  r"  r#  r  r$  r%  r'  rK   rK   rL   r1     s    )r"  r#  r  r$  r%  r  z,type[Model] | tuple[type[Model], ...] | Noneztuple[str, ...] | None)	r&  r"  r#  r  r$  r%  r  r'  rH   c            K  s  |dk	rt dt |dk	rB|dk	r0tdddt|tsV|f}nttjd t	f}|p\i }i }i }	x|
 D ]\}
}t|
st d|
 dt t|trtd	|}y|\}}W q tk
r } ztd
dd|W dd}~X Y qX n
d| }}|r||	|
< |||
< qpW |	|d}|r*|| || |rJt|j|d< t|}tj| ||d\}}}||k	r|||d< || || ||fddi|S )a  Dynamically creates and returns a new Pydantic model.

    Args:
        __model_name: The name of the newly created model.
        __config__: The configuration of the new model.
        __base__: The base class for the new model.
        __module__: The name of the module that the model belongs to.
        __validators__: A dictionary of methods that validate
            fields.
        __cls_kwargs__: A dictionary of keyword arguments for class creation.
        __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>)` or `<name>=<default value>`. For more complex cases, they can be
            passed in the format: `<name>=<Field>` or `<name>=(<type>, <FieldInfo>)`.

    Returns:
        The newly created model.

    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-base)rD   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-definitions)r  r  r2   )kwds__orig_bases__Z#__pydantic_reset_parent_namespace__F)r{   r   RuntimeWarningr   r   r   r   castTyper.   rS   r   r   r   rc   r
   r   Zconfig_dicttypesresolve_basesprepare_class)r&  r"  r#  r  r$  r%  r  r'  fieldsr   f_nameZf_defZf_annotationZf_valuee	namespaceresolved_basesmetansr(  rK   rK   rL   r1     sR     









)Tr  
__future__r   Z_annotationsr-  r   r{   r   r   r   r   r   r  r   	_internalr	   r
   r   r   r   r   r   r   r   r   r   Z
_migrationr   configr   r  r   r  r   r   errorsr   r   r0  r   r   r   Zjson_schemar   r   r   r    r!   r"   r  inspectr#   pathlibr$   r%   r&   r'   r(   r)   Z_internal._utilsr*   r+   r,   r  r  ZAnyClassMethod	GeneratorTupler~   r   TypeVarr-   r0   r  r   __all__Zobject_setattrre   ZModelMetaclassr.   overloadr   r1   r   rK   rK   rK   rL   <module>   sx   4         $$	$M