
    gB                       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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& erddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0  G d de$      Z1d(dZ2 ed      d)d       Z3d*dZ4dd	 	 	 	 	 	 	 	 	 	 	 d+d Z5d,d!Z6d-d"Z7dddd#	 	 	 	 	 	 	 	 	 d.d$Z8d/d%Z9d/d&Z:	 	 	 	 d0d'Z;y)1zmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)copy)	lru_cache)	Parameterismethoddescriptor	signature)TYPE_CHECKINGAnyCallablePattern)PydanticUndefined)TypeIs)PydanticUserError   )_typing_extra)ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info)
NsResolver)Representation)can_be_positionalBaseMetadata   )	FieldInfo)	BaseModel)StandardDataclass)DecoratorInfosc                      e Zd ZdZdZy)PydanticMetadataz0Base class for annotation markers like `Strict`. N)__name__
__module____qualname____doc__	__slots__r"       O/var/www/openai/venv/lib/python3.12/site-packages/pydantic/_internal/_fields.pyr!   r!   "   s
    :Ir(   r!   c                 "     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)metadatas    r)   pydantic_general_metadatar-   (   s     # "8,,r(   )maxsizec                 2    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y)7_general_metadata_cls.<locals>._PydanticGeneralMetadataz,Pydantic general metadata like `max_digits`.c                    || _         y N)__dict__)selfr,   s     r)   __init__z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__<   s	    $DMr(   N)r,   r
   )r#   r$   r%   r&   r6   r"   r(   r)   _PydanticGeneralMetadatar1   9   s
    :	%r(   r7   )annotated_typesr   r!   )r   r7   s     r)   r+   r+   4   s     -%#3\ % $#r(   c                    |j                   r@t        |       }|j                         D ]!  \  }}|j                  ||v s||   |_        # y y r3   )use_attribute_docstringsr   itemsdescription)clsfieldsconfig_wrapperfields_docsann_name
field_infos         r)   _update_fields_from_docstringsrC   B   sO    ..1#6$*LLN Hj%%-(k2I)4X)>
& %3 /r(   )typevars_mapc               	   t               }t               }i }t        |      D ]#  }t        |dd      x}	s|j	                  |	       % t        j                  | |      }
| j                  j                  di       }i }t               }|
j                         D ]L  \  }\  }}|dk(  r|j                  D ].  }d}t        |t              r|j                  |      du}n!t        |t              r|j!                  |      }|sN|D ]I  }t#        ||      st%        ||      r|t        |di       v r,t'        d| dt        ||       d	| d
       d}|j                  D ]Q  }t        |t              r'|j                  |      r%|d|j(                   dfz  }:|j!                  |      rL||fz  }S t+        j,                  d| d| j.                   d| d| d	t0               1 t        j2                  |      r|j5                  |       vt7        |t        | |t8                    r|j5                  |       t;        |      s| j<                  r|dk7  rt'        d|d      t        | di       j                  d      }|D ]  }t?        j@                  |      rt?        jB                  |      ndD ch c]  }|jD                   }}t#        ||      sS||u rX||v r]||vrbt+        j,                  d| d| jF                   d|jF                   dt0                	 t        | |t8              }|t8        u rtH        	 tK        ||       t        ||      r6tM        |jN                        r!|jN                  jQ                  d|       |_'        |jS                  ||      }||_*        	 tW        | |       | j                  d   }||j\                  v rt_        d      |||<   O |r&|ja                         D ]  }|jc                  |        te        | ||       ||fS c c}w # tH        $ r Y yw xY w# tH        $ rK ||v r|jY                  |      }||_*        n+||v rt[        ||         }n|jY                  |      }||_*        Y w xY w)ab  Collect the fields of a nascent pydantic model.

    Also collect the names of any ClassVars present in the type hints.

    The returned value is a tuple of two items: the fields dict, and the set of ClassVar names.

    Args:
        cls: BaseModel or dataclass.
        bases: Parents of the class, generally `cls.__bases__`.
        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 tuple contains fields and class variables.

    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.
    __pydantic_fields__N)ns_resolver__annotations__model_configFzField "z" conflicts with member z of protected namespace "z".r"   zre.compile()z" in z( has conflict with protected namespace "z_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = z`.rootzUnexpected field with name z4; only 'root' is allowed as a field of a `RootModel`__pydantic_generic_metadata__originzField name "z" in "z"" shadows an attribute in parent ""__pydantic_decorators__z0you can't override a field with a computed field)3r   r   reversedgetattrupdater   get_model_type_hintsr4   getsetr;   protected_namespaces
isinstancer   matchstr
startswithhasattr
issubclass	NameErrorpatternwarningswarnr#   UserWarningis_classvar_annotationadd_is_finalvar_with_default_valr   is_valid_field_name__pydantic_root_model__dataclassesis_dataclassr>   namer%   AttributeError#_warn_on_nested_alias_in_annotationr   default__get__from_annotated_attribute	evaluateddelattrfrom_annotationr   computed_fields
ValueErrorvaluesapply_typevars_maprC   )r=   basesr?   rG   rD   r   
FieldInfo_parent_fields_lookupbasemodel_fields
type_hintsr   r>   
class_varsrA   ann_typero   protected_namespacens_violationbvalid_namespacespngeneric_originfielddataclass_fieldsrl   rB   
decoratorss                               r)   collect_model_fieldsr   J   s   < )*I)+J13"4)>EE<E ''5   33C[QJ ,,""#4b9K#%F5J+5+;+;+=''8Y~% #1#F#F!&L-w7288B$N/5'223FGAq(+ *1i 8XQRTikmIn=n"+")(3KGTUW_L`Ka";<O;PPR!T#   (*$,AA%b'2#%88H#5 0{2::,a5P4R R 0#+#6#6r#: 0RE 9 0 B MM!(5>fgzf{ |DDTCUUWY $	3 $G> //9NN8$(73J[3\]NN8$"8,&&8v+=-h\9mn  !&ErJNNxXDEPE]E]^bEc););D)Aik)k )ku

)k    tX&>)// ;."8*F33C3C2D E))*!-% 0&	c8->?G++$$ ,( 0(C':.3Egoo3V
 #*//"9"9$"D#<<XwOJ#,J X& &)\\2K%L
z111OPP%xw ,>z ]]_E$$\2 % #3?:W x " C  	5;&'77A
'0
$ 33 "&&:8&D!EJ
 ",!;!;H!EJ+4J(!	5s+   7P #P4+P%%	P10P14ARRc                   t               }t        | dd       }|rr|D ]l  }t        j                  |      st        j                  |      D ]<  }t        ||      s|j                  t        j                  d| dt                 y  n y y )N__args__z `alias` specification on field "z5" must be set on outermost annotation to take effect.)
r   rQ   r   is_annotatedget_argsrW   aliasr_   r`   ra   )r}   rA   r   argsanno_arganno_type_args         r)   rk   rk      s    (*I8Z.DH))(3%2%;%;H%EM!-;@S@S@_ >xjH}~'  &F  r(   c                    t               }t        j                  |       sy|t        u ryt	        ||      r|j
                  t        u r|j                  yy)NFT)r   r   is_finalvarr   rW   rl   default_factory)type_valr   s      r)   rd   rd     sN    (*I$$U+	!	!	C	#8I)IcNaNaNir(   )rG   rD   r?   c          
        t               }i }|xs
 t               }| j                  }t        | j                        D ]  }t        j                  |      s|j                  |      5  |j                         D ]  \  }}	||j                  j                  di       vr&|j                  \  }
}t        j                  |	j                  |
|      \  }}t        j                  |      ro|	j                   s9|	j"                  t
        j$                  u r|	j&                  t
        j$                  u rt)        |	j"                  |      r^|	j"                  j*                  r+|	j"                  j                   du rt-        d| dd      |j/                  ||	j"                        }n|j/                  ||	      }|||<   |j"                  t0        usSt)        t3        | ||      |      slt5        | ||j"                          	 ddd        |r&|j7                         D ]  }|j9                  |        |t;        | ||       |S # 1 sw Y   xY w)a|  Collect the fields of a dataclass.

    Args:
        cls: dataclass.
        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.
        config_wrapper: The config wrapper instance.

    Returns:
        The dataclass fields.
    rH   FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)codeN)r   r   __dataclass_fields__rP   __mro__rg   rh   pushr;   r4   rT   types_namespacer   try_eval_typetyperb   initrl   MISSINGr   rW   init_varr   rn   r   rQ   setattrrt   ru   rC   )r=   rG   rD   r?   rw   r>   r   ry   rA   dataclass_fieldglobalnslocalnsr}   _rB   r   s                   r)   collect_dataclass_fieldsr     s(   & *+J#%F-K//
 %''-d#-=-C-C-E)/4==#4#45F#KK $/$?$?!'+99/:N:NPXZab! 77A (,,'//;3F3FF'77;;N;NN o55zB&..77*22775@"3"28*  =A  !B%A#  !!+!D!DXOfOf!gJ!+!D!DX!_J#-x %%->>:C:6
D C:+=+=>S .F $#	 &` ]]_E $$\2	 % !&sFNCMm $#s   'E"II$II	c                &    | j                  d       S )Nr   rZ   ri   s    r)   re   re   s  s    s###r(   c                L    | j                  d      xr | j                  d       S )Nr   __r   r   s    r)   is_valid_privateattr_namer   w  s"    ??3=(=$==r(   c                   	 t        |       }t        |j                  j                               }t        |      dk(  xr/ t        |d         xr |d   j                  t        j                  u S # t        t        f$ r Y yw xY w)zMWhether the provided default factory callable has a validated data parameter.Fr   r   )r   rs   	TypeErrorlist
parametersrt   lenr   rl   r   empty)r   sigr   s      r)   takes_validated_data_argumentr   {  s    ( cnn++-.Jz?aq$5jm$DqTUI^I^bkbqbqIqq 	"  s   A/ /B B)r,   r
   returnr   )r   ztype[BaseMetadata])r=   	type[Any]r>   dict[str, FieldInfo]r?   r   r   None)r=   ztype[BaseModel]rv   ztuple[type[Any], ...]r?   r   rG   NsResolver | NonerD   dict[Any, Any] | Noner   z%tuple[dict[str, FieldInfo], set[str]])r}   r   rA   rY   r   r   )r   r   r   r
   r   bool)
r=   ztype[StandardDataclass]rG   r   rD   r   r?   zConfigWrapper | Noner   r   )ri   rY   r   r   )r   z3Callable[[], Any] | Callable[[dict[str, Any]], Any]r   z'TypeIs[Callable[[dict[str, Any]], Any]])<r&   
__future__r   _annotationsrg   r_   r   	functoolsr   inspectr   r   r   typingr	   r
   r   r   pydantic_corer   typing_extensionsr   pydantic.errorsr    r   _configr   _docs_extractionr   _import_utilsr   r   _namespace_utilsr   _reprr   _utilsr   r8   r   r>   r   mainr   _dataclassesr   _decoratorsr   r!   r-   r+   rC   r   rk   rd   r   re   r   r   r"   r(   r)   <module>r      s?   s 2     < < 8 8 + $ -  " 9 M ( ! %," /+~ 	- 4
$ 
$? +/p	p p "p #	p (p +pf 
  &**.+/V	 V #V (	V
 )V Vr$>rHr,rr(   