
    o im                       d Z ddl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 ddlmZ ddl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 ddlm Z  ddl!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0m1Z1 er ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: ddl;m<Z<  G d de.          Z=d]d#Z>e	d^d%            Z?d_d.Z@d`dad6ZAdbd<ZBdcd?ZCdddBZDh dCZEh dDZFddEdedLZGdfdOZHdddPdgdSZIdhdUZJdidWZKdidXZLdjd\ZMdS )kzmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)Mapping)cache)	Parameterismethoddescriptor	signature)Pattern)TYPE_CHECKINGAnyCallableTypeVar)PydanticUndefined)TypeIs)AnnotationSource)PydanticDeprecatedSince211)PydanticUserError   )AliasGenerator   )	_generics_typing_extra)ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info)
NsResolver)Representation)can_be_positionalget_first_not_noneBaseMetadata)	FieldInfo)	BaseModel)PydanticDataclassStandardDataclass)DecoratorInfosc                      e Zd ZdZdZdS )PydanticMetadataz0Base class for annotation markers like `Strict`. N)__name__
__module____qualname____doc__	__slots__r)       Q/var/www/findabus/venv/lib/python3.11/site-packages/pydantic/_internal/_fields.pyr(   r(   &   s        ::IIIr/   r(   metadatar   returnr!   c                 0     t                      |           S )zCreate a new `_PydanticGeneralMetadata` class with the given metadata.

    Args:
        **metadata: The metadata to add.

    Returns:
        The new `_PydanticGeneralMetadata` class.
    )_general_metadata_cls)r1   s    r0   pydantic_general_metadatar5   ,   s     # ""8,,,r/   type[BaseMetadata]c                 :    ddl m}   G d dt          |           }|S )zCDo it this way to avoid importing `annotated_types` at import time.r   r    c                      e Zd ZdZddZdS )7_general_metadata_cls.<locals>._PydanticGeneralMetadataz,Pydantic general metadata like `max_digits`.r1   r   c                    || _         d S N)__dict__)selfr1   s     r0   __init__z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__@   s    $DMMMr/   N)r1   r   )r*   r+   r,   r-   r>   r)   r/   r0   _PydanticGeneralMetadatar9   =   s.        ::	% 	% 	% 	% 	% 	%r/   r?   )annotated_typesr!   r(   )r!   r?   s     r0   r4   r4   8   sK     -,,,,,% % % % %#3\ % % % $#r/   protected_namespacestuple[str | Pattern[str], ...]ann_namestrbasestuple[type[Any], ...]cls_nameNonec                R   t                      }| D ]}d}t          |t                    r|                    |          d u}n*t          |t                    r|                    |          }|r5|D ]\}t          ||          rJt          ||          r|t          |di           v s't          d|dt          ||           d|d          ]g }| D ]y}	t          |	t                    r4|	                    |          s|
                    d|	j        d           K|                    |	          s|
                    d	|	 d	           zd
d                    |           t          |          dk    rdnd }
t          j        d|d|d|d|
 d	t           d           d S )NF__pydantic_fields__Field z conflicts with member z of protected namespace .zre.compile()'(z, r   z,)z in z$ conflicts with protected namespace zX.

You may be able to solve this by setting the 'protected_namespaces' configuration to    
stacklevel)r   
isinstancer	   matchrD   
startswithhasattr
issubclassgetattr
ValueErrorappendpatternjoinlenwarningswarnUserWarning)rA   rC   rE   rG   r#   protected_namespacens_violationbvalid_namespacespnvalid_namespaces_strs              r0   _check_protected_namespacesrg   F   se    )**I3    )733 	D.44X>>dJLL+S11 	D#../BCCL 	  1h'' &q)44 WQPegiEjEj9j9j(PX P PPQS[H\H\ P P7JP P P  
 /1 . ? ?B!"g.. ?!xx11 S,334Q"*4Q4Q4QRRR'22266 ?,33IIII>>>'u4995E+F+F'uPSTdPePeijPjPjps'u'u$DX D DX D D]p D D mAD D D 	   7   r/   Fcls	type[Any]fieldsdict[str, FieldInfo]use_inspectboolc                    t          | |          }|                                D ]\  }}|j        ||v r||         |_        d S )Nrl   )r   itemsdescription)rh   rj   rl   fields_docsrC   
field_infos         r0   _update_fields_from_docstringsrt   q   s[    -c{KKKK & ; ;*!)h+.E.E%0%:J"; ;r/   title_generatorCallable[[str, FieldInfo], str]
field_namers   r"   c                    |j         D | ||          }t          |t                    st          d|  d|j                   ||_         d S d S )Nzfield_title_generator  must return str, not )titlerS   rD   	TypeError	__class__)ru   rw   rs   rz   s       r0   *_apply_field_title_generator_to_field_infor}   x   sj    
 
J77%%% 	om_mm\a\kmmnnn 
  r/   alias_generator%Callable[[str], str] | AliasGeneratorc                   |j         !|j         dk    s|j        |j        |j        d\  }}}t	          | t
                    r|                     |          \  }}}nIt          |           r: | |          }t	          |t                    st          d|  d|j
                   |j         |j         dk    rd|_         |j         dk    r1t          ||          |_        t          ||          |_        ||_        |j        ||_        |j        t          ||          |_        |j        t          ||          |_        dS dS dS )av  Apply an alias generator to aliases on a `FieldInfo` instance if appropriate.

    Args:
        alias_generator: A callable that takes a string and returns a string, or an `AliasGenerator` instance.
        field_name: The name of the field from which to generate the alias.
        field_info: The `FieldInfo` instance to which the alias generator is (maybe) applied.
    Nr   )NNNzalias_generator ry   )alias_priorityaliasvalidation_aliasserialization_aliasrS   r   generate_aliasescallablerD   r{   r|   r   )r~   rw   rs   r   r   r   s         r0   $_apply_alias_generator_to_field_infor      s    	!)$))#&.)17G4!4o~66 	m;J;[;[\f;g;g8E#%8%8o&& 	m#OJ//EeS)) m k? k kZ_Zi k klll
 $,
0IQ0N0N()J% $))-?@SUZ-[-[J**<=Mu*U*UJ'$J #$J)1-?@SUZ-[-[J*&.*<=Mu*U*UJ'''; 218 /.r/   config_wrapperr   c                    |j         p| j         }|t          |||           | j        t          | j        ||           dS dS )ap  Update the `FieldInfo` instance from the configuration set on the model it belongs to.

    This will apply the title and alias generators from the configuration.

    Args:
        config_wrapper: The configuration from the model.
        field_name: The field name the `FieldInfo` instance is attached to.
        field_info: The `FieldInfo` instance to update.
    N)field_title_generatorr}   r~   r   )r   rw   rs   r   s       r0   update_field_from_configr      s\     '<d@d(23H*V`aaa%1,^-KZYcddddd 21r/   >   copydictjson_iter_calculate_keys_copy_and_set_values>
   schemafrom_ormvalidate	construct	parse_obj	parse_raw
_get_value
parse_fileschema_jsonupdate_forward_refs)typevars_maptype[BaseModel]ns_resolverNsResolver | Noner   Mapping[TypeVar, Any] | None%tuple[dict[str, FieldInfo], set[str]]c                  t                      }t                      | j        }i }t          |          D ]*}t	          |dd          x}r|                    |           +t          j        | |          }	t          j        |           }
i }t                      }|	
                                D ]_\  }\  }}|dk    rt          |j        ||| j                   t          j        |          r|                    |           Wt	          | |t                     t           urYt#          fdt$          D                       s1t'          d          r(t#          fdt(          D                       rt           t+          |          s| j        r|d	k    rt/          d
|d          t	          | di                               d          }|D ]}d t3          j        |          rt3          j        |          ndD             }t'          ||          r?||u rK||v rP||
vrUt9          j        d| d| j         d|j         dt>          d           t           u rW||
v s||vr3|                     |tB          j"                  }|sd|_#        ||_$        n"||         %                                }ntM          |          r@tO          j(                  r,j(        )                    d|           }|_(        |j*        d<   |+                    |tB          j"                  }|_,        |sd|_#        ||_$        nZd|j-        v rQ|.                                s=t9          j        d|d|d|dt^          d           |                    |           	 ta          | |           n# tb          $ r Y nw xY w| j2        d         }||j3        v rti          d |d!| j        d"          |||<   |j#        rtk          |||           a|r3|6                                D ]}|j#        r|7                    |           |j8        rts          | |           ||fS )#a*  Collect the fields and class variables names of a nascent Pydantic model.

    The fields collection process is *lenient*, meaning it won't error if string annotations
    fail to evaluate. If this happens, the original annotation (and assigned value, if any)
    is stored on the created `FieldInfo` instance.

    The `rebuild_model_fields()` should be called at a later point (e.g. when rebuilding the model),
    and will make use of these stored attributes.

    Args:
        cls: BaseModel or dataclass.
        config_wrapper: The config wrapper instance.
        ns_resolver: Namespace resolver to use when getting model annotations.
        typevars_map: A dictionary mapping type variables to their concrete types.

    Returns:
        A two-tuple containing model fields and class variables names.

    Raises:
        NameError:
            - If there is a conflict between a field name and protected namespaces.
            - If there is a field other than `root` in `RootModel`.
            - If a field shadows an attribute in the parent model.
    rJ   N)r   model_config)rA   rC   rE   rG   c              3  >   K   | ]}t          |d           u V  d S r;   )rX   .0	depr_name
BaseModel_assigned_values     r0   	<genexpr>z'collect_model_fields.<locals>.<genexpr>  s4      qq9
It44Fqqqqqqr/   __func__c              3  f   K   | ]+}t          t          |d           dd           j        u V  ,d S )Nr   )rX   r   r   s     r0   r   z'collect_model_fields.<locals>.<genexpr>"  sX        ! GJ	4@@*dSSWeWnn     r/   rootzUnexpected field with name z4; only 'root' is allowed as a field of a `RootModel`__pydantic_generic_metadata__originc                    h | ]	}|j         
S r)   name)r   fields     r0   	<setcomp>z'collect_model_fields.<locals>.<setcomp>6  s'          $
     r/   r)   zField name "z" in "z"" shadows an attribute in parent ""   rQ   _sourceFdefaultfinalzAnnotation z= is marked as final and has a default value. Pydantic treats zz as a class variable, but it will be considered as a normal field in V3 to be aligned with dataclasses. If you still want zV to be considered as a class variable, annotate it as: `ClassVar[<type>] = <default>.`)categoryrR   __pydantic_decorators__rK   z
 of class zf overrides symbol of same name in a parent class. This override with a computed_field is incompatible.):r   r   	__bases__reversedrX   updater   get_model_type_hintssafe_get_annotationssetrp   rg   rA   r*   is_classvar_annotationaddr   any_deprecated_method_namesrV   _deprecated_classmethod_namesis_valid_field_name__pydantic_root_model__	NameErrorgetdataclassesis_dataclassrj   r^   r_   r,   r`   from_annotationr   CLASS	_complete_original_annotation_copyrS   r   r   __get___attributes_setfrom_annotated_attribute_original_assignment_qualifiersis_requiredr   delattrAttributeErrorr<   computed_fieldsr{   r   valuesapply_typevars_mapuse_attribute_docstringsrt   )rh   r   r   r   
FieldInfo_rE   parent_fields_lookupbasemodel_fields
type_hintsr   rj   
class_varsrC   ann_type	evaluatedgeneric_origindataclass_fieldsrs   r   
decoratorsr   r   r   s                         @@r0   collect_model_fieldsr      s   > *++J)++JME13 6 6"4)>EEE< 	6 ''5553C[QQQJ  4S99K#%F55J+5+;+;+=+= JK JK''8Y~%% #!/!D\		
 	
 	
 	
 /99 	NN8$$$ h0ABB!222qqqqqXpqqqqq 3
 
33 3      %B     3 /N"8,, 	& 	8v+=+=nhnnn   !&ErJJNNxXX 	 	D   EPE]^bEcEc)k);D)A)A)Aik      tX&& >))/// ;..-8 - -33C - -)- - - 	    ...;&&(:N*N*N (77JZJ`7aa
  ?+0J( 7?J3 2(;AACC

 .*55 D:L^Mc:d:d D )088sCC)0&<C.y9#<<X~_o_u<vvJ /=J+ ',
$2:
//J222:;Q;Q;S;S2E( E Eks E E"*E E E 8     x(((
X&&&&!   
 &)\2K%L
z111G G Gs| G G G   &x 	K$^XzJJJ 7]]__ 	7 	7E 7((666. 4&sF333:s    N11
N>=N>r   Mapping[TypeVar, Any]c               H   t                      }i }|                    |           5  | j                                        D ]\  }}|j        r|||<   |j        }t          j        |j        g|j	        R  }	t          j        |	|          }	|j        x}
t          u r"|                    |	t          j                  }n"|                    |	|
t          j                  }|j        |j        n||_        t%          |||           |||<   	 ddd           n# 1 swxY w Y   |S )a  Rebuild the (already present) model fields by trying to reevaluate annotations.

    This function should be called whenever a model with incomplete fields is encountered.

    Raises:
        NameError: If one of the annotations failed to evaluate.

    Note:
        This function *doesn't* mutate the model fields in place, as it can be called during
        schema generation, where you don't want to mutate other model's fields.
    r   N)r   pushrJ   rp   r   rq   r   	eval_typer   types_namespacer   replace_typesr   r   r   r   r   r   r   )rh   r   r   r   r   rebuilt_fieldsf_namers   existing_descannassign	new_fields               r0   rebuild_model_fieldsr     s   $ *++J+-N			#		 3 3"%"9"?"?"A"A 	3 	3FJ# 3)3v&& * 6#-3 0    -c<@@(==FBSSS * : :3HXH^ : _ _II * C CCYiYo C p pIAJAVAb	(=(=hu	%(KKK)2v&&%	33 3 3 3 3 3 3 3 3 3 3 3 3 3 3* s   C$DDD)r   r   type[StandardDataclass]dict[Any, Any] | Nonec          
        t                      }i }|pt                      }| j        }t          | j                  D ]}t          j        |          s|                    |          5  |                                D ]\  }}	t          j
        |          }
||
vr|j        \  }}t          j        |	j        ||          \  }}t          j        |          r\|	j        s'|	j        t
          j        u r|	j        t
          j        u rt'          |	j        |          rd|	j        j        r$|	j        j        du rt+          d| dd          |                    ||	j        t.          j                  }|	j        |_        n)|                    ||	t.          j                  }|	|_        |sd|_        ||_        |||<   t9          |||           |j        t:          ur5t'          t=          | ||          |          rt?          | ||j                   	 ddd           n# 1 swxY w Y   |r,|                                 D ]}|!                    |           |j"        r!tG          | |tI          | d           	           |S )
a|  Collect the fields of a dataclass.

    Args:
        cls: dataclass.
        config_wrapper: The config wrapper instance.
        ns_resolver: Namespace resolver to use when getting dataclass annotations.
            Defaults to an empty instance.
        typevars_map: A dictionary mapping type variables to their concrete types.

    Returns:
        The dataclass fields.
    FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)coder   N__is_pydantic_dataclass__ro   )%r   r   __dataclass_fields__r   __mro__r   r   r   rp   r   r   r   try_eval_typetyper   initr   MISSINGdefault_factoryrS   init_varr   r   r   	DATACLASSr   r   r   r   r   rX   setattrr   r   r   rt   rV   )rh   r   r   r   r   rj   r   r   rC   dataclass_field	base_annsglobalnslocalnsr   r   rs   r   s                    r0   collect_dataclass_fieldsr    sT   & *++J#%F-K/
 %% ;? ;?'-- 	d## 7	? 7	?-=-C-C-E-E 6? 6?)/)>tDD	9,, $/$?!'&3&A/BVX`bi&j&j#) 7AA  (,'/;3FFF'7;;NNN o5zBB F&.7 !*275@@"3 !B8  !B  !B  !B%A# # #  !!+!D!D /"9CSC] "E " "J 7F6MJ33!+!D!D /;K;U "E " "J 7FJ3  ?+0J(6>J3#-x (:NNN%->>>:C:66
D D> C:+=>>>m6?7	? 7	? 7	? 7	? 7	? 7	? 7	? 7	? 7	? 7	? 7	? 7	? 7	? 7	? 7	?r  3]]__ 	3 	3E $$\2222. 
& $C)DEEE	
 	
 	
 	
 Ms   )F,H""H&	)H&	type[PydanticDataclass]c                  t                      }i }|                    |           5  | j                                        D ]\  }}|j        r|||<   |j        }t          j        |j        g|j	        R  }	t          j        |	|          }	|                    |	|j        t          j                  }
|
j        |
j        n||
_        t!          |||
           |
||<   	 ddd           n# 1 swxY w Y   |S )a  Rebuild the (already present) dataclass fields by trying to reevaluate annotations.

    This function should be called whenever a dataclass with incomplete fields is encountered.

    Raises:
        NameError: If one of the annotations failed to evaluate.

    Note:
        This function *doesn't* mutate the dataclass fields in place, as it can be called during
        schema generation, where you don't want to mutate other dataclass's fields.
    r   N)r   r   rJ   rp   r   rq   r   r   r   r   r   r   r   r   r   r  r   )rh   r   r   r   r   r   r   rs   r   r   r   s              r0   rebuild_dataclass_fieldsr  8  so   $ *++J+-N			#		 3 3"%"9"?"?"A"A 	3 	3FJ# 3)3v&& * 6#-3 0    -c<@@&??3,6 @  	 BKAVAb	(=(=hu	%(KKK)2v&&'	33 3 3 3 3 3 3 3 3 3 3 3 3 3 3, s   B7C**C.1C.r   c                .    |                      d           S )N_rU   r   s    r0   r   r   f  s    s####r/   c                X    |                      d          o|                      d           S )Nr  __r  r   s    r0   is_valid_privateattr_namer  j  s(    ??3=(=(=$==r/   r  3Callable[[], Any] | Callable[[dict[str, Any]], Any]'TypeIs[Callable[[dict[str, Any]], Any]]c                "   	 t          |           }n# t          t          f$ r Y dS w xY wt          |j                                                  }t          |          dk    o-t          |d                   o|d         j        t          j
        u S )zMWhether the provided default factory callable has a validated data parameter.Fr   r   )r   rY   r{   list
parametersr   r]   r   r   r   empty)r  sigr  s      r0   takes_validated_data_argumentr  n  s    ((	"    uu
 cn++--..Jz??aq$5jm$D$DqTUI^bkbqIqqs    '')r1   r   r2   r!   )r2   r6   )
rA   rB   rC   rD   rE   rF   rG   rD   r2   rH   )F)rh   ri   rj   rk   rl   rm   r2   rH   )ru   rv   rw   rD   rs   r"   )r~   r   rw   rD   rs   r"   )r   r   rw   rD   rs   r"   r2   rH   )
rh   r   r   r   r   r   r   r   r2   r   )
rh   r   r   r   r   r   r   r   r2   rk   )
rh   r   r   r   r   r   r   r   r2   rk   )
rh   r  r   r   r   r   r   r   r2   rk   )r   rD   r2   rm   )r  r  r2   r  )Nr-   
__future__r   _annotationsr   r^   collections.abcr   	functoolsr   inspectr   r   r   rer	   typingr
   r   r   r   pydantic_corer   typing_extensionsr   typing_inspection.introspectionr   pydanticr   pydantic.errorsr   aliasesr    r   r   _configr   _docs_extractionr   _import_utilsr   r   _namespace_utilsr   _reprr   _utilsr   r   r@   r!   rj   r"   mainr#   _dataclassesr$   r%   _decoratorsr&   r(   r5   r4   rg   rt   r}   r   r   r   r   r   r   r  r  r   r  r  r)   r/   r0   <module>r4     s   s s 2 2 2 2 2 2      # # # # # #       < < < < < < < < < <       8 8 8 8 8 8 8 8 8 8 8 8 + + + + + + $ $ $ $ $ $ < < < < < < / / / / / / - - - - - - $ $ $ $ $ $ & & & & & & & & " " " " " " 9 9 9 9 9 9 M M M M M M M M ( ( ( ( ( ( ! ! ! ! ! ! 9 9 9 9 9 9 9 9 ,,,,,,,""""""      BBBBBBBB++++++    ~   	- 	- 	- 	- 
$ 
$ 
$ 
$( ( ( (V; ; ; ; ;
! 
! 
! 
!/V /V /V /Vde e e e" hgg ! ! ! & 26D D D D D DN* * * *b &**.i i i i i iX+ + + +\$ $ $ $> > > >r r r r r rr/   