o
    wi9                     @  s  U d Z ddlmZ ddl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mZmZmZ ddlZdd	lmZmZ erKdd
l
mZ G dd deZddddddddddd
ZdOddZdPd d!ZdPd"d#ZedQd'd(ZeejZd)ed*< G d+d, d,eZ G d-d. d.e d/Z!G d0d1 d1Z"ere"ne!Z#d)ed2< erdd3lm$Z$ e$j%Z%ej&Z&ej'Z'ej(Z(ej)Z)dS dd4l*m+Z+ ed5 Z,e+Z%d6dd7dRd?d@Z&dSdAdBZ'edTdEdFZ(edUdIdFZ(	dVdWdLdFZ(G dMdN dNZ)dS )Xz<Provides partial support for compatibility with Pydantic v1.    )annotationsN)cache)	signature)
attrgetter)TYPE_CHECKINGAnyCallableClassVarLiteraloverload   )IS_PYDANTIC_V2to_json)Protocolc                   @  s   e Zd ZU ed#ddZded	< d
ed< ded< ed$ddZed%ddZed%ddZed%ddZ	d&ddZ
d'ddZd(d d!Zd"S ))V1Modelvaluesdictby_aliasboolreturnc                 C     d S N )clsr   r   r   r   M/home/ubuntu/.local/lib/python3.10/site-packages/wandb/_pydantic/v1_compat.py_dump_json_vals      zV1Model._dump_json_valszClassVar[type]
__config__zClassVar[dict[str, Any]]
__fields__set[str]__fields_set__argsr   kwargsNonec                 O  r   r   r   r   r!   r"   r   r   r   update_forward_refs    r   zV1Model.update_forward_refsc                 O  r   r   r   r$   r   r   r   	construct"   r   zV1Model.constructc                 O  r   r   r   r$   r   r   r   	parse_obj$   r   zV1Model.parse_objc                 O  r   r   r   r$   r   r   r   	parse_raw&   r   zV1Model.parse_rawdict[str, Any]c                 K  r   r   r   selfr"   r   r   r   r   )       zV1Model.dictstrc                 K  r   r   r   r*   r   r   r   json*   r,   zV1Model.jsonc                 K  r   r   r   r*   r   r   r   copy+   r,   zV1Model.copyN)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"   r   r   r   )__name__
__module____qualname__classmethodr   __annotations__r%   r&   r'   r(   r   r.   r/   r   r   r   r   r      s"   
 

r   allow_population_by_field_nameanystr_loweranystr_strip_whitespaceanystr_upperkeep_untouchedmax_anystr_lengthmin_anystr_lengthorm_modeschema_extravalidate_all)
populate_by_namestr_to_lowerstr_strip_whitespacestr_to_upperignored_typesstr_max_lengthstr_min_lengthfrom_attributesjson_schema_extravalidate_default	v2_configr)   r   c                 C  s   i dd |   D ddiS )zIInternal helper: Return a copy of the v2 ConfigDict with renamed v1 keys.c                 S  s   i | ]\}}t |||qS r   )_V1_CONFIG_KEYSget.0kvr   r   r   
<dictcomp>B   s    z%convert_v2_config.<locals>.<dictcomp>underscore_attrs_are_privateT)items)rK   r   r   r   convert_v2_config>   s
   rU   ann_strr-   r   c                 C  s   |    dS )N)zlist[zoptional[list[)striplower
startswithrV   r   r   r   _is_list_like_annL   s   r[   c                 C  s   |    dv S )N>   optional[str]r-   )rW   rX   rZ   r   r   r   _is_str_like_annQ      r]   funcr   r   c                 C  s   t t| jS )zIInternal helper: Return the names of args accepted by the given function.)setr   
parametersr_   r   r   r   allowed_arg_namesV   s   rc   typePydanticModelMetaclassc                      s,   e Zd Zd fd	d
ZedddZ  ZS )V1MixinMetaclassnamer-   basestuple[type, ...]	namespacer)   r"   r   c                   s   t r	ddlm} nddlm} |dd  }r!tddt||d< |d }r\| D ]/\}}	t	|	 }
|r[|| }r[t
|rOd\|
_|
_d\|
_|
_q,t|r[|
jdd |
_q,t j| |||fi |S )	Nr   )	FieldInfomodel_configConfigr   r6   )NNpattern)r   pydantic.v1.fieldsrk   pydantic.fieldspoprd   rU   rM   rT   
isinstancer[   	max_items
max_length	min_items
min_lengthr]   extraregexsuper__new__)r   rg   rh   rj   r"   rk   config_dictr   
field_nameobjfieldann	__class__r   r   rz   c   s$   

zV1MixinMetaclass.__new__r   c                 C     | j S r   )r   r+   r   r   r   model_fields      zV1MixinMetaclass.model_fields)rg   r-   rh   ri   rj   r)   r"   r   )r   r)   )r2   r3   r4   rz   propertyr   __classcell__r   r   r   r   rf   b   s    :rf   c                      s   e Zd Zed%ddZed& fddZed'ddZed(ddZed(ddZed(ddZ	d)ddZ
d*ddZd+d d!Zed,d#d$Z  ZS )-V1Mixinr   r)   r   r   r   c                   sH   dd | j  D }t|rdnd}tt||  fdd| D S )zLReserialize values from `Json`-typed fields after dumping the model to dict.c                 s  s    | ]}|j r|V  qd S r   )
parse_jsonrO   fr   r   r   	<genexpr>   s    z*V1Mixin._dump_json_vals.<locals>.<genexpr>aliasrg   c                   s.   i | ]\}}||d ur| v rt |n|qS r   )r   rN   json_field_keysr   r   rR      s    z+V1Mixin._dump_json_vals.<locals>.<dictcomp>)r   r   r   r`   maprT   )r   r   r   json_fieldsget_keyr   r   r   r      s   
zV1Mixin._dump_json_valsr   type[V1Model]localnsr   r#   c                   s(   t t  }dr|jdi | d S d S )N__try_update_forward_refs__r   )hasattrry   r   )r   r   supr   r   r   r      s   z#V1Mixin.__try_update_forward_refs__r!   r"   c                 O     | j |i |S r   )r%   r$   r   r   r   model_rebuild   r^   zV1Mixin.model_rebuildr   c                 O  r   r   )r&   r$   r   r   r   model_construct   r^   zV1Mixin.model_constructc                 O  r   r   )r'   r$   r   r   r   model_validate   r^   zV1Mixin.model_validatec                 O  r   r   )r(   r$   r   r   r   model_validate_json   r^   zV1Mixin.model_validate_jsonr+   c                   sZ   t | j  @ }| jdi  fdd|D } ddr+ dd}| j||dS |S )Nc                      i | ]}| | qS r   r   rO   rP   r"   r   r   rR          z&V1Mixin.model_dump.<locals>.<dictcomp>
round_tripFr   r   r   )rc   r   keysrM   r   )r+   r"   allowed_keysdict_r   r   r   r   
model_dump   s   zV1Mixin.model_dumpr-   c                   sj   t | j  @ }| jdi  fdd|D } ddr3 dd}t|}t| j||dS |S )Nc                   r   r   r   r   r   r   r   rR      r   z+V1Mixin.model_dump_json.<locals>.<dictcomp>r   Fr   r   r   )rc   r.   r   rM   loadsdumpsr   )r+   r"   r   json_r   r   r   r   r   model_dump_json   s   
zV1Mixin.model_dump_jsonc                   s0   t | j  @ }| jdi  fdd|D S )Nc                   r   r   r   r   r   r   r   rR      r   z&V1Mixin.model_copy.<locals>.<dictcomp>r   )rc   r/   r   )r+   r"   r   r   r   r   
model_copy   s   zV1Mixin.model_copyr   c                 C  r   r   )r    r   r   r   r   model_fields_set   r   zV1Mixin.model_fields_set)r   r)   r   r   r   r)   )r   r   r   r   r   r#   r0   r1   )r+   r   r"   r   r   r)   )r+   r   r"   r   r   r-   )r+   r   r"   r   r   r   )r+   r   r   r   )r2   r3   r4   r5   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s$    


r   )	metaclassc                   @  s   e Zd ZdS )V2MixinN)r2   r3   r4   r   r   r   r   r      s    r   PydanticCompatMixin)alias_generators)to_lower_camel)beforeafterwrapplainr   )modecheck_fieldsfieldsr   V2ValidatorModer   bool | None_r   c                 O  s   t j|| dkdt|ddS )Nr   T)prealwaysr   allow_reuse)pydantic	validatorr   )r   r   r   r   r   r   r   field_validator  s   r   c                 K  s(   | dkrddd}|S t j| dkd	d
S )Nr   	v2_methodr   r   r   c                   s$   d fdd}t jdd	d
t|S )Nr   r   r   r)   r   c                   s(   | j di |  fdd jD S )Nc                   s   i | ]}|t  |qS r   )getattrr   v_selfr   r   rR   A  s    zJmodel_validator.<locals>._decorator.<locals>.v1_method.<locals>.<dictcomp>r   )r&   r   )r   r   r   r   r   	v1_method7  s   z6model_validator.<locals>._decorator.<locals>.v1_methodFTr   r   )r   r   r   r)   r   r)   )r   root_validatorr5   )r   r   r   r   r   
_decorator/  s   z#model_validator.<locals>._decoratorr   Tr   )r   r   r   r   )r   r   )r   r   r   r   r   r   model_validator,  s   
r   Callable | propertyr   c                C  r   r   r   rb   r   r   r   computed_fieldK  r   r   r#   )Callable[[Callable | property], property]c                K  r   r   r   )r_   r   r   r   r   r   M  s   Callable | property | None4property | Callable[[Callable | property], property]c                K  s   ddd}| du r|S || S )	z?Compatibility wrapper for Pydantic v2's `computed_field` in v1.r   r   r   r   c                 S  s   t | tr| S t| S r   )rr   r   )r   r   r   r   always_propertyW  s   z'computed_field.<locals>.always_propertyN)r   r   r   r   r   )r_   r   r   r   r   r   r   R  s   
c                   @  s$   e Zd ZU dZded< dddZdS )	AliasChoiceszHPlaceholder for Pydantic v2's AliasChoices to retain partial v1 support.z	list[str]aliasesr-   c                 G  s   t || _d S r   )listr   )r+   r   r   r   r   __init__c  s   zAliasChoices.__init__N)r   r-   )r2   r3   r4   __doc__r6   r   r   r   r   r   r   ^  s   
 r   )rK   r)   r   r)   )rV   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   )r_   r#   r   r   r   r   r   )r_   r   r   r   r   r   )-r   
__future__r   r.   	functoolsr   inspectr   operatorr   typingr   r   r   r	   r
   r   r   utilsr   r   r   r   rL   rU   r[   r]   rc   rd   	BaseModelre   r6   rf   r   r   r   r   to_camelr   r   r   r   pydantic.utilsr   r   r   r   r   r   <module>   sl     


CN

