o
    $6dZ                     @   st  U d dl 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
 d dlmZ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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$m%Z%m&Z& d
dl'm(Z(m)Z)m*Z*m+Z+ d
dl,m-Z-m.Z. d
dl/m0Z0m1Z1m2Z2m3Z3 d
dl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; d
dl<m=Z=m>Z> d
dl?m@Z@mAZAmBZB d
dlCmDZDmEZE d
dlmFZFmGZG d
dlmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZO d
dlPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^ erd dl_m`Z` d
dl"maZa d
dlmbZb d
dlmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZk edddZldZmedZndeeoe7f d dfd!d"Zpd#eqd eeegerf  fd$d%ZseteuevewfZxeed&f eyd'< efex Zzeed&f eyd(< d)Z{e!d*e6fd+G d,d- d-eZ|e}j~ZG d.d deUe|d/Zd*Z{eddeddd0d1eod2eee(  d3dd4eod5eeod6f d7eeoef d8ed ed fd9d:Zededdd;d1eod2eee(  d3eed eed d&f f d4eod5eeod6f d7eeoef d8ed ed fd<d:Zddedddd=d1eod2eee(  d3eded eed d&f f d4eod5eeod6f d7eeoef d>eeeod&f  d8ed ed fd?d:Ze} Z	dHd@ee dAdBdCdDd edBdEee. f fdFdGZdS )I    N)ABCMeta)deepcopy)Enum)partial)Path)FunctionTypeprepare_classresolve_bases)TYPE_CHECKINGAbstractSetAnyCallableClassVarDictListMappingOptionalTupleTypeTypeVarUnioncastno_type_checkoverload)dataclass_transform   )ValidatorGroupextract_root_validatorsextract_validatorsinherit_validators)
BaseConfigExtrainherit_configprepare_config)ErrorWrapperValidationError)ConfigError	DictError
ExtraErrorMissingError)MAPPING_LIKE_SHAPESField
ModelFieldModelPrivateAttrPrivateAttr	Undefinedis_finalvar_with_default_val)custom_pydantic_encoderpydantic_encoder)Protocol	load_fileload_str_bytes)default_ref_templatemodel_schema)PyObjectStrBytes)AnyCallableget_args
get_originis_classvaris_namedtupleis_unionresolve_annotationsupdate_model_forward_refs)DUNDER_ATTRIBUTESROOT_KEYClassAttribute
GetterDictRepresentation
ValueItemsgenerate_model_signatureis_valid_fieldis_valid_private_namelenient_issubclasssequence_likesmart_deepcopyunique_listvalidate_field_name)	Signature)ValidatorListDict)	ModelOrDc)	AbstractSetIntStrAnyClassMethodCallableGeneratorDictAny
DictStrAnyMappingIntStrAnyReprArgsSetStrTupleGeneratorModel	BaseModel)bound)r]   create_modelvalidate_model_Tfieldsreturnc                 C   s   t | dkrtt dd S )Nr   z" cannot be mixed with other fields)len
ValueErrorrC   )rb    rf   gC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\pydantic/v1/main.pyvalidate_custom_root_typea   s   rh   frozenc                 C   s   dt dtfdd}| r|S d S )Nself_rc   c                 S   s   t | jt t| j  S N)hash	__class__tuple__dict__values)rj   rf   rf   rg   hash_functiong   s   z-generate_hash_function.<locals>.hash_function)r   int)ri   rq   rf   rf   rg   generate_hash_functionf   s   rs   .ANNOTATED_FIELD_UNTOUCHED_TYPESUNTOUCHED_TYPESFT)Zkw_only_defaultZfield_specifiersc                       s6   e Zd Ze fddZdedef fddZ  ZS )ModelMetaclassc           (         sj  i }t }i }g g }}	i }
i }|dd}t|tr|hnt|}t }d }t|D ]:}trdt|trd|tkrd|	t
|j t|j|}t|j|}||j7 }|	|j7 }	|	|j |	|j |j}q*dd}dd t|D }fdd |@ D }|d	}|r|rtd
t||fi |}tt||}t|}| D ]}|| ||j}|r|j	| |   qt!|| t"dt#dt$ffdd}|d|dfdkrt%|di |dd }|& D ]o\}}t'|r|(| qt)|||t*r|(| qt+|rQt,|| ||t*}t-t.|r)t/|n|f}||rA|t0krAt1dd |D sAqt2j3||||||d||< q||vr_|j4r_t5 |
|< qt6|j7 |& D ]\}}||vov|| }t|t8rt9|st:d| d| d| d||
|< qi|j4rt9|r|rt5|d|
|< qit+|r||vr|rt,|| t2j3||||t*|||d}||v rt;|j<|| j<r|| j<|_<ntd| d| d|||< qit=|v } | r t>| |?  |j@rtAtB|j@}!ntC}!tD|\}"}#|d u r!tE|jF}||
 B dhB  ||dd |& D p7d dd |& D pBd |jGtH||" d d! d"tH|	|# d#d! d"i tI|!| i ||
||
 B ||d$ fd%d|& D }$tJ jK| |||$fi }%tLd&tM|%jN|||%_O|r|%P  |& D ]\}}&||$vrtQ|&d'd }'tR|'r|'|%| q|%S )(N	__slots__rf   Z__resolve_forward_refs__Tc                 S   s$   h | ]}| d r|d s|qS )__)
startswithendswith.0keyrf   rf   rg   	<setcomp>   s    z)ModelMetaclass.__new__.<locals>.<setcomp>c                    s   i | ]}|  |qS rf   )popr{   )kwargsrf   rg   
<dictcomp>   s    z*ModelMetaclass.__new__.<locals>.<dictcomp>ConfigzYSpecifying config in two places is ambiguous, use either Config attribute or class kwargsvrc   c                    s   t |  p
| jjdkS )NZcython_function_or_method)
isinstancerm   __name__r   )untouched_typesrf   rg   is_untouched   s   z,ModelMetaclass.__new__.<locals>.is_untouched
__module____qualname__)zpydantic.mainr]   __annotations__c                 s   s    | ]
}t t|tV  qd S rk   )rK   r<   r   )r|   Zallowed_typerf   rf   rg   	<genexpr>   s    
z)ModelMetaclass.__new__.<locals>.<genexpr>)namevalue
annotationclass_validatorsconfigzPrivate attributes "zF" must not be a valid field name; Use sunder or dunder names, e. g. "_z" or "__z__")defaultzThe type of .zo differs from the new default value; if you wish to change the type of this field, please use a type annotationc                 S   &   i | ]\}}|j jd ur||j jqS rk   )
field_infoexcluder|   r   fieldrf   rf   rg   r           c                 S   r   rk   )r   includer   rf   rf   rg   r     r   c                 S   s   | j S rk   r   r   rf   rf   rg   <lambda>
  s    z(ModelMetaclass.__new__.<locals>.<lambda>)Zname_factoryc                 S   s
   | d j S )Nr   r   )Zskip_on_failure_and_vrf   rf   rg   r     s   
 )
__config__
__fields____exclude_fields____include_fields____validators____pre_root_validators____post_root_validators____schema_cache____json_encoder____custom_root_type____private_attributes__rw   __hash____class_vars__c                    s   i | ]\}}| vr||qS rf   rf   )r|   nr   )exclude_from_namespacerf   rg   r         __signature____set_name__)Sr    getr   strsetreversed_is_base_model_class_defined
issubclassr]   updaterM   r   r"   r   r   r   r   r   r   r   r   r   dirkeys	TypeErrorr   r   rp   Z
set_configZget_validatorsr   r   Zpopulate_validatorsr#   rt   r   boolr@   itemsr=   addr0   r/   rI   rO   r?   r<   r;   r8   anyr,   ZinferZunderscore_attrs_are_privater.   ru   Zkeep_untouchedr-   rJ   	NameErrorrK   type_rC   rh   Zcheck_for_unusedjson_encodersr   r1   r2   r   rs   ri   
validatorsrN   staticmethodsuper__new__rD   rH   __init__r   __try_update_forward_refs__getattrcallable)(mcsr   bases	namespacer   rb   r   r   Zpre_root_validatorsZpost_root_validatorsZprivate_attributesZbase_private_attributesslotsZ
class_varsZ	hash_funcbaseZresolve_forward_refsZallowed_config_kwargsZconfig_kwargsZconfig_from_namespacevgfZextra_validatorsr   annotationsZann_nameZann_typer   Zallowed_typesvar_nameZcan_be_changedinferredZ_custom_root_typeZjson_encoderZ
pre_rv_newZpost_rv_newZnew_namespaceclsobjset_namerm   )r   r   r   rg   r   z   s4  





















zModelMetaclass.__new__instancerc   c                    s   t |do
t |S )z|
        Avoid calling ABC _abc_subclasscheck unless we're pretty sure.

        See #3829 and python/cpython#92810
        r   )hasattrr   __instancecheck__)selfr   r   rf   rg   r   *  s   z ModelMetaclass.__instancecheck__)	r   r   r   r   r   r   r   r   __classcell__rf   rf   r   rg   rv   x   s
     0rv   c                   @   s6  e Zd ZU eri Zeeeef  e	d< dZ
eeeeef   e	d< dZeeeeef   e	d< i Zeeeef  e	d< eee  e	d< eeeeef   e	d< eZeee  e	d< d	d
 Zeeegef  e	d< i Zed e	d< dZee e	d< ed e	d< eeeef  e	d< ee e	d< e Zee e	d< eZdZ dZ!deddfddZ"e#dd Z$dddZ%dd d!Z&dd"d#Z'dddddddd$d%ee(d&  d'ee(d&  d(ed)ee d*ed+ed,edd-fd.d/Z)ddddddddd0d1	d%ee(d&  d'ee(d&  d(ed)ee d*ed+ed,ed2eeegef  d3ed4edefd5d6Z*e+d7edefd8d9Z,e+d:ed; d7edd;fd<d=Z-e+dd>ddd?d:ed; d@e.dAedBedCe/dDedd;fdEdFZ0e+dd>ddd?d:ed; dGe(ee1f dAedBedCe/dDedd;fdHdIZ2e+d:ed; d7edd;fdJdKZ3e+dd:ed; dLedM dNedd;fdOdPZ4dQd;dNd-dRdMdSedd;f
dTdUZ5dddddVdQd;d%ee(d&  d'ee(d&  dWed- dSedd;fdXdYZ6e+d0e7fd(edZedd-fd[d\Z8e+d0e7d]d(edZed4edefd^d_Z9e+ddadbZ:e+d:ed; dcedd;fdddeZ;e+d:ed; d7ede<fdfdgZ=e+e#dhedied(ed%ee(d&  d'ee(d&  d*ed+ed,edefdjdkZ>e+dleddfdmdnZ?e+dleddfdodpZ@ddrdsZA							ddied(ed%ee(d&  d'ee(d&  d*ed+ed,eddqfdtduZB	dd%edv d'edv d*edWed- deeCe  f
dwdxZDdyedefdzd{ZEdd}d~ZFdS )r]   r   Nr   r   r   r   r   r   c                 C   s   | S rk   rf   )xrf   rf   rg   r   @  s    zBaseModel.<lambda>r   rV   r   Fr   rP   r   r   r   __fields_set__)ro   r    datarc   c              
   K   sf   t | j|\}}}|r|zt| d| W n ty& } ztd|d}~ww t| d| |   dS )z
        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.
        ro   zYModel values must be a dict; you may not have returned a dictionary from a root validatorNr   )r`   rm   object_setattrr   _init_private_attributes)Z__pydantic_self__r   rp   
fields_setvalidation_errorerf   rf   rg   r   L  s   zBaseModel.__init__c                    s*   | j v s	 tv rt|  |S | jjtjur( | jvr(td| j	j
 d  d| jjr0| jjr:td| j	j
 d | jv rR| j  jrRtd| j	j
 d  d| jjri | j |i}| jD ]$}z|| j	|}W qc tttfy } ztt|tdg| j	d }~ww | j d }|r|jjstd|j d fdd	| j D }|j|| | j	d
\}}|rt|g| j	|| < g }	| jD ]/\}
}|
r|	rqz|| j	|}W q tttfy } z|	t|td W Y d }~qd }~ww |	rt|	| j	t| d| n|| j < | j  d S )N"z" object has no field "z3" is immutable and does not support item assignmentz
" object "z2" field is final and does not support reassignmentlocz8" has allow_mutation set to False and cannot be assignedc                    s   i | ]\}}| kr||qS rf   rf   r|   kr   r   rf   rg   r   }  r   z)BaseModel.__setattr__.<locals>.<dictcomp>r   r   ro   )r   rB   r   r   extrar!   allowr   re   rm   r   Zallow_mutationri   r   finalZvalidate_assignmentro   r   AssertionErrorr%   r$   rC   r   r   r   r   validater   appendr   r   )r   r   r   
new_values	validatorexcZknown_fieldZdict_without_original_valueZerror_errorsskip_on_failurerf   r   rg   __setattr___  sV   


zBaseModel.__setattr__c                    s.    fdd j D } j jdd |D dS )Nc                 3   s     | ]}|t  |tfV  qd S rk   )r   r/   )r|   r   r   rf   rg   r     s    z)BaseModel.__getstate__.<locals>.<genexpr>c                 S   s   i | ]\}}|t ur||qS rf   )r/   r   rf   rf   rg   r     r   z*BaseModel.__getstate__.<locals>.<dictcomp>)ro   r   __private_attribute_values__)r   ro   r   )r   Zprivate_attrsrf   r   rg   __getstate__  s
   zBaseModel.__getstate__statec                 C   sJ   t | d|d  t | d|d  |di  D ]
\}}t | || qd S )Nro   r   r   )r   r   r   )r   r   r   r   rf   rf   rg   __setstate__  s
   zBaseModel.__setstate__c                 C   s4   | j  D ]\}}| }|turt| || qd S rk   )r   r   get_defaultr/   r   )r   r   Zprivate_attrr   rf   rf   rg   r     s   z"BaseModel._init_private_attributes)r   r   by_aliasskip_defaultsexclude_unsetexclude_defaultsexclude_noner   )rS   rX   r   r   r   r   r   r  rW   c             
   C   s>   |durt | jj dt |}t| jd||||||dS )z
        Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

        NzF.dict(): "skip_defaults" is deprecated and replaced by "exclude_unset"Tto_dictr   r   r   r   r   r  )warningswarnrm   r   DeprecationWarningdict_iter)r   r   r   r   r   r   r   r  rf   rf   rg   r    s"   zBaseModel.dictT)	r   r   r   r   r   r   r  encodermodels_as_dictr	  r
  dumps_kwargsc       	      
   K   s~   |durt | jj dt |}tttgtf |p| j}t	| j
|	||||||d}| jr3|t }| jj|fd|i|
S )z
        Generate a JSON representation of the model, `include` and `exclude` arguments as per `dict()`.

        `encoder` is an optional function to supply as `default` to json.dumps(), other arguments as per `json.dumps()`.
        NzF.json(): "skip_defaults" is deprecated and replaced by "exclude_unset"r  r   )r  r  rm   r   r  r   r   r   r   r  r  r   rC   r   
json_dumps)r   r   r   r   r   r   r   r  r	  r
  r  r   rf   rf   rg   json  s*   zBaseModel.jsonr   c                 C   sT   | j r(t|tr| thkst|tr$|j thkr$| jt jtv r(t|iS |S rk   )	r   r   r  r   rC   r]   r   shaper*   r   r   rf   rf   rg   _enforce_dict_if_root  s   zBaseModel._enforce_dict_if_rootr   r\   c              
   C   sz   |  |}t|ts6zt|}W n% ttfy5 } zt| j d|jj }tt|t	dg| |d }~ww | di |S )Nz expected dict not r   rf   )
r  r   r  r   re   r   rm   r%   r$   rC   )r   r   r   r   rf   rf   rg   	parse_obj  s   

zBaseModel.parse_objutf8)content_typeencodingprotoallow_picklebr  r  r  r  c             
   C   sZ   zt |||||| jjd}W n tttfy' } z
tt|tdg| d }~ww | 	|S )Nr  r  r  r  
json_loadsr   )
r5   r   r  re   r   UnicodeDecodeErrorr%   r$   rC   r  )r   r  r  r  r  r  r   r   rf   rf   rg   	parse_raw  s   


zBaseModel.parse_rawpathc                C   s"   t |||||| jjd}| |S )Nr  )r4   r   r  r  )r   r  r  r  r  r  r   rf   rf   rg   
parse_file'  s   

zBaseModel.parse_filec                 C   sn   | j jstd| jrt|in| |}| | }t| |\}}}|r%|t|d| t|d| |	  |S )Nz@You must have the config attribute orm_mode=True to use from_ormro   r   )
r   orm_moder&   r   rC   _decompose_classr   r`   r   r   )r   r   mrp   r   r   rf   rf   rg   from_orm;  s   
zBaseModel.from_orm_fields_setrZ   rp   c                 K   s   |  | }i }| j D ](\}}|jr |j|v r ||j ||< q||v r+|| ||< q|js4| ||< q|| t|d| |du rJt	|
 }t|d| |  |S )a  
        Creates a new model setting __dict__ and __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
        ro   Nr   )r   r   r   	alt_aliasaliasrequiredr   r   r   r   r   r   )r   r"  rp   r   Zfields_valuesr   r   rf   rf   rg   	constructI  s"   

zBaseModel.constructr   r   deepc                C   sp   |rt |}| j}||}t|d| t|d| | jD ]}t| |t}|tur5|r/t |}t||| q|S )Nro   r   )r   rm   r   r   r   r   r/   )r   rp   r   r'  r   r   r   r   rf   rf   rg   _copy_and_set_valuesa  s   

zBaseModel._copy_and_set_values)r   r   r   r'  r   c                C   sR   t | jdd||ddfi |pi }|r| j| B }nt| j}| j|||dS )a  
        Duplicate a model, optionally choose which fields to include, exclude and change.

        :param include: fields to include in new model
        :param exclude: fields to exclude from new model, as with values this takes precedence over include
        :param 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
        :param deep: set to `True` to make a deep copy of the model
        :return: new model instance
        F)r  r   r   r   r   r'  )r  r  r   r   r   r(  )r   r   r   r   r'  rp   r   rf   rf   rg   copys  s   
zBaseModel.copyref_templatec                 C   s<   | j ||f}|d ur|S t| ||d}|| j ||f< |S )Nr   r+  )r   r   r7   )r   r   r+  cachedsrf   rf   rg   schema  s   zBaseModel.schemar,  c                K   s.   ddl m} | jj| j||dfd|i|S )Nr   )r2   r,  r   )r  r2   r   r  r/  )r   r   r+  r  r2   rf   rf   rg   schema_json  s   zBaseModel.schema_jsonrU   c                 c   s    | j V  d S rk   )r   )r   rf   rf   rg   __get_validators__  s   zBaseModel.__get_validators__r   c              
   C   s   t || r6| jj}d }|dvrtdt |rd}|dkr d}n|dkr&d}|d u r,|S |j|j|j|dS | 	|}t |t
rG| di |S | jjrP| |S zt
|}W n ttfyh } zt |d }~ww | di |S )	N>   r'  shallownonezJ`copy_on_model_validation` should be a string: 'deep', 'shallow' or 'none'Fr2  r'  Tr)  rf   )r   r   copy_on_model_validationr  r  r  r(  ro   r   r  r  r  r!  r   re   r'   )r   r   r4  Z	deep_copyZvalue_as_dictr   rf   rf   rg   r     s8   



zBaseModel.validatec                 C   s   t |tr|S | j|S rk   )r   rE   r   Zgetter_dictr  rf   rf   rg   r    s   
zBaseModel._decompose_classr   r  c	                    s  t |tr#r|j ||d}	t|	v r|	t S |	S |j||dS |r*t||nd |r3t||nd t |trL fdd| D S t|rq fddt|D }
t	|j
rl|j
|
 S |
|
S t |trtjddr|jS |S )	N)r   r   r   r   r   r  )r   r   c                    s\   i | ]*\}}r |sr|r|j| o"|o(|d qS )r  r   r   r   r   r   r  Zis_excludedZis_included
_get_valuefor_element)r|   Zk_v_r   r   r   r  r   r  value_excludevalue_includerf   rg   r     s*    z(BaseModel._get_value.<locals>.<dictcomp>c                 3   s^    | ]*\}}r |sr|rj| o!|o'|d V  qdS )r5  Nr6  )r|   ir9  r:  rf   rg   r   
  s,    
z'BaseModel._get_value.<locals>.<genexpr>Zuse_enum_valuesF)r   r]   r  rC   r*  rG   r   rL   	enumerater>   rm   r   r   r   r   )r   r   r  r   r   r   r   r   r  Zv_dictZseq_argsrf   r:  rg   r7    s8   

zBaseModel._get_valuelocalnsc                 K   s    t | | j | jj|tf dS )z{
        Same as update_forward_refs but will not raise exception
        when forward references are not defined.
        N)rA   r   rp   r   r   r   r   r?  rf   rf   rg   r   "  s    z%BaseModel.__try_update_forward_refs__c                 K   s   t | | j | jj| dS )z`
        Try to update ForwardRefs on fields based on this Model, globalns and localns.
        N)rA   r   rp   r   r   r@  rf   rf   rg   update_forward_refs*  s   zBaseModel.update_forward_refsr[   c                 c   s    | j  E dH  dS )z(
        so `dict(model)` works
        Nro   r   r   rf   rf   rg   __iter__1  s   zBaseModel.__iter__c                 c   sz   |d us
| j d urt| j |}|d us| jd ur#tj| j|dd}| j|||d}|d u rC|sC|sC|sC|sC|sC| j E d H  d S |d urLt| |nd }	|d urWt| |nd }
| j D ]\\}}|d urj||vsp|rq|d u rqq^|r| j|}t	|ddst	|dt
|krq^|r|| jv r| j| j}n|}|s|
s|	r| j||||
o|
||	o|	||||d}||fV  q^d S )NT)Z	intersect)r   r   r   r%  r   r  )r   rG   merger   _calculate_keysro   r   r   r   r   _missingr$  r7  r8  )r   r  r   r   r   r   r   r  Zallowed_keysr;  r<  Z	field_keyr   Zmodel_fieldZdict_keyrf   rf   rg   r  7  sH   
zBaseModel._iterrX   c                 C   sx   |d u r|d u r|du rd S |r| j  }n| j }|d ur%|| M }|r-|| 8 }|r:|dd | D 8 }|S )NFc                 S   s   h | ]\}}t |r|qS rf   )rG   Zis_truer   rf   rf   rg   r~     r   z,BaseModel._calculate_keys.<locals>.<setcomp>)r   r*  ro   r   r   )r   r   r   r   r   r   rf   rf   rg   rE  p  s   
zBaseModel._calculate_keysotherc                 C   s&   t |tr|  | kS |  |kS rk   )r   r]   r  )r   rG  rf   rf   rg   __eq__  s   
zBaseModel.__eq__rY   c                    s    fdd j  D S )Nc                    s8   g | ]\}}|t vr| jvs j| jjr||fqS rf   )rB   r   r   reprr   r   rf   rg   
<listcomp>  s
     z+BaseModel.__repr_args__.<locals>.<listcomp>rB  r   rf   r   rg   __repr_args__  s   
zBaseModel.__repr_args__)rc   rV   )r   rV   rc   N)rc   Nrk   )rc   rU   )rc   r[   )FFNNFFF)rc   rY   )Gr   r   r   r
   r   r   r   r   r,   r   r   r   r   r   r   r   r:   r   r   r   r    r   r   r   r   r   r   r-   rZ   r   r   r   rw   __doc__r   r   r   r   r   r   r   r  r  classmethodr  r  r9   r3   r  r   r  r!  r&  r(  r*  r6   r/  r0  r1  r   rE   r  r7  r   rA  rC  r  r   rE  rH  rK  rf   rf   rf   rg   r]   6  s  
 

7

	

	

%

	

-


&


 	&

	
I


	
>

)	metaclass)r   __base__r   r   __cls_kwargs____model_namer   rO  r   r   rT   rP  field_definitionsc                K      d S rk   rf   rQ  r   rO  r   r   rP  rR  rf   rf   rg   r_        r_   )r   r   r   rP  c                K   rS  rk   rf   rT  rf   rf   rg   r_     rU  )r   rO  r   r   rP  rw   rw   c                K   sb  |dur
t dt |dur|durtdt|ts|f}nttd tf}|p*i }i }i }	|	 D ]>\}
}t
|
sEt d|
 dt t|trbz|\}}W n tya } ztd|d}~ww d|}}|rm||	|
< |||
< q3|	|d}|r~|| || |rt|t|d	< t|}t| ||d
\}}}||ur||d< || || ||fi |S )a  
    Dynamically create a model.
    :param __model_name: name of the created model
    :param __config__: config class to use for the new model
    :param __base__: base class for the new model to inherit from
    :param __module__: module of the created model
    :param __validators__: a dict of method names and @validator class methods
    :param __cls_kwargs__: a dict for class creation
    :param __slots__: Deprecated, `__slots__` should not be passed to `create_model`
    :param field_definitions: fields of the model (or extra fields if a base is supplied)
        in the format `<name>=(<type>, <default default>)` or `<name>=<default value>, e.g.
        `foobar=(str, ...)` or `foobar=123`, or, for complex use-cases, in the format
        `<name>=<Field>` or `<name>=(<type>, <FieldInfo>)`, e.g.
        `foo=Field(datetime, default_factory=datetime.utcnow, alias='bar')` or
        `foo=(str, FieldInfo(title='Foo'))`
    Nz.__slots__ should not be passed to create_modelzBto avoid confusion __config__ and __base__ cannot be used togetherr\   z3fields may not start with an underscore, ignoring "r   zfield definitions should either be a tuple of (<type>, <default>) or just a default value, unfortunately this means tuples as default values are not allowed)r   r   r   )kwds__orig_bases__)r  r  RuntimeWarningr&   r   rn   r   r   r]   r   rI   re   r   r"   r    r	   r   )rQ  r   rO  r   r   rP  rw   rR  rb   r   f_nameZf_defZf_annotationZf_valuer   r   resolved_basesmetansrV  rf   rf   rg   r_     sT   







model
input_datarW   r   rR   rZ   c                 C   s  i }g }t  }t  }| j}|jtju}|p| }	| jD ].}
z|
|	|}W q tttfyH } zi t  t	t
|tdg|	fW  Y d}~  S d}~ww | j D ]{\}}||jt}d}|tu rn|jrn|jrn||jt}d}|tu r|jr|t
t |jd qN| }|js|js|||< qNn|| |r||r|jn|j |j|||j|	d\}}t|t
r|| qNt|tr|| qN|||< qN|r	t|tr|  | }n|! | }|r	||O }|jtj"u r|D ]}|| ||< qnt#|D ]}|t
t$ |d q| j%D ]4\}}
|r|rqz|
|	|}W q tttfy@ } z|t
|td W Y d}~qd}~ww |rL||t	||	fS ||dfS )z(
    validate data against a model.
    r   NFTr   )&r   r   r   r!   ignorer   re   r   r   r%   r$   rC   r   r   r   r$  rF  Zallow_population_by_field_namer#  r   r%  r   r)   r   Zvalidate_allZvalidate_alwaysr   r   r   listextendrE   Z
extra_keysr   r   sortedr(   r   )r]  r^  r   rp   r   Z
names_usedr   r   Zcheck_extraZcls_r   r   r   r   r   Z
using_namer9  Zerrors_r   r   r   rf   rf   rg   r`     s|   
,




 
r`   rk   )r  abcr   r*  r   enumr   	functoolsr   pathlibr   typesr   r   r	   typingr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Ztyping_extensionsr   r   r   r   r   r   r   r    r!   r"   r#   Zerror_wrappersr$   r%   r   r&   r'   r(   r)   rb   r*   r+   r,   r-   r.   r/   r0   r  r1   r2   parser3   r4   r5   r/  r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   utilsrB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   inspectrP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   __all__ra   r   rh   r   rr   rs   propertytyperM  r   rt   r   ru   r   rv   objectr   r   r]   r   r_   rF  r`   rf   rf   rf   rg   <module>   s   
 H$	(@
,  ;    g


	


	


	

M