o
    "i                     @  sZ  U d dl mZ d dlmZmZ d dl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 d dlmZmZmZmZ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%mZm
Z
m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0mZm1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmZ ddlCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZO ddlPmQZQmRZR ddlSmTZTmUZUmVZVmWZWmXZXmYZYmZZZ ddl[m\Z\m]Z]m^Z^ ddl_m`Z`maZambZb ddlcmdZdmeZemfZfmgZgmhZhmiZimjZj ddlkmhZl ddlkmiZm ddlnmoZo ddlpmqZqmrZrmsZs ddltmuZu g dZvedZwedZxedeTeZ d ZyeeXewgeZf Zzd!e{d"< ed#d$d Z|ed%d&d Z}ed'eTeW d Z~eeXewgeWf Zd!e{d(< ed)d*d Zed+d,d Zed-eZd Zed.eWd Zed/ed ZG d0d1 d1eZd>d6d7ZG d8d9 d9ZG d:d; d;eZeZd!e{d<< d=S )?    )annotations)Counterdeque)CallableIterable)Mapping)MutableMapping)Field)Enum)	Signature)	signature)Path)AnyOptionalTupleTypeVaroverload)	Attributeresolve_types)has)Self   )#ANIESFrozenSetSubscriptabler   r   MutableSequenceNoneTypeOriginAbstractSetOriginMutableSetSequenceSet	TypeAliasfieldsget_final_baseget_newtype_base
get_originr   has_with_genericis_annotatedis_bare
is_counteris_dequeis_frozenset
is_genericis_generic_attrsis_hetero_tuple
is_literal
is_mappingis_mutable_sequenceis_mutable_setis_optionalis_protocolis_tupleis_typeddictis_union_typer   )defaultdict_structure_factory"homogenous_tuple_structure_factoryis_abstract_setis_defaultdictis_namedtupleis_sequenceiterable_unstructure_factorylist_structure_factorymapping_structure_factorymapping_unstructure_factorynamedtuple_structure_factorynamedtuple_unstructure_factory)create_default_dis_funcis_supported_union)HookFactoryMultiStrategyDispatchStructuredValueStructureHook
TargetTypeUnstructuredValueUnstructureHook)IterableValidationErrorIterableValidationNoteStructureHandlerNotFoundError)	Predicateidentityraise_error)AttributeOverrideHeteroTupleUnstructureFnIterableUnstructureFnMappingUnstructureFnmake_dict_structure_fnmake_dict_unstructure_fn make_hetero_tuple_unstructure_fn)rV   )rW   )is_literal_containing_enums)get_type_alias_baseis_type_aliastype_alias_structure_factory)SimpleStructureHook)BaseConverter	ConverterGenConverterUnstructureStrategyTVUnstructureHookFactory)boundr    ExtendedUnstructureHookFactoryAnyUnstructureHookFactoryBasezLHookFactory[UnstructureHook] | ExtendedUnstructureHookFactory[BaseConverter]AnyUnstructureHookFactoryzHHookFactory[UnstructureHook] | ExtendedUnstructureHookFactory[Converter]StructureHookFactoryExtendedStructureHookFactoryAnyStructureHookFactoryBasezHHookFactory[StructureHook] | ExtendedStructureHookFactory[BaseConverter]AnyStructureHookFactoryzDHookFactory[StructureHook] | ExtendedStructureHookFactory[Converter]UnstructureHookTStructureHookTCounterTc                   @  s   e Zd ZdZdZdZdS )ra   z)`attrs` classes unstructuring strategies.asdictastupleN)__name__
__module____qualname____doc__AS_DICTAS_TUPLE rx   rx   Q/var/www/html/premium_crap/venv/lib/python3.10/site-packages/cattrs/converters.pyra      s    ra   factoryr   returnboolc                 C  s0   t | }t|jdkot|j d jtju S )z.Does this factory also accept a converter arg?   r   )inspect_signaturelen
parameterslistvaluesdefaultr   empty)rz   sigrx   rx   ry   _is_extended_factory   s   r   c                   @  sZ  e Zd ZdZdZeejdddd dd fdddZddddZ	e
dddZedd!d"Zedd%d"Z	ddd(d"Zdd+d,Zedd/d0Zedd3d0Zedd5d0Zdd6d0Z	ddd9d:Zedd=d>Zedd@d>Z	dddBd>ZddCdDZeddFdGZeddIdGZeddKdGZddLdGZddPdQZdddRdSZddUdVZddXdYZdd[d\Zdd_d`ZddcddZddedfZddhdiZ	dddldmZeddndoZedpdq Z edrds Z!ddvdwZ"dxdy Z#ddzd{Z$dddZ%dddZ&dddZ'e(fdddZ)dddZ*dddZ+dd Z,dddZ-		ddddZ.dddZ/				ddddZ0dS )r^   z2Converts between structured and unstructured data.)
_dict_factory_prefer_attrib_converters_struct_copy_skip_structure_attrs_structure_func_union_struct_registry_unstruct_copy_skip_unstructure_attrs_unstructure_funcdetailed_validationFTc                 C     t S NrP   _rx   rx   ry   <lambda>       zBaseConverter.<lambda>c                 C  
   t d | S r   rQ   trx   rx   ry   r          dict_factoryCallable[[], Any]unstruct_stratra   prefer_attrib_convertersr|   r   unstructure_fallback_factoryHookFactory[UnstructureHook]structure_fallback_factoryHookFactory[StructureHook]r{   Nonec                   s^  t |}| _| _i  _|t ju r j _ j _n j	 _ j
 _t|  _ jttfttfttfg  jdd  fddft fddfdd  fdddft fdddft jft jft jft jft jfd	d  jft jft j fd
d  jfg t|  _! j!dd dd ft" j#dfdd  j$ftt%dfdd  j&dft' j(ft j)ftt*dft+t,dft- j.ft j/ft0 j1ft j1ft2 j3ft4t5dft j6fg|t ju rt7 j8dfgng t9 j:f fdd jj;dft jf  j!t j<ft j<ft= j<ft> j<ft? j<ft j<fg | _@ jA  _B j!A  _CdS )a  
        :param detailed_validation: Whether to use a slightly slower mode for detailed
            validation errors.
        :param unstructure_fallback_factory: A hook factory to be called when no
            registered unstructuring hooks match.
        :param structure_fallback_factory: A hook factory to be called when no
            registered structuring hooks match.

        ..  versionadded:: 23.2.0 *unstructure_fallback_factory*
        ..  versionadded:: 23.2.0 *structure_fallback_factory*
        ..  versionchanged:: 24.2.0
            The default `structure_fallback_factory` now raises errors for missing handlers
            more eagerly, surfacing problems earlier.
        c                 S     t | d uS r   r#   r   rx   rx   ry   r          z(BaseConverter.__init__.<locals>.<lambda>c                       j | | jdS N)unstructure_asunstructure	__class__oselfrx   ry   r          c                   r   r   r   r   r   rx   ry   r      r   c                 S  r   r   r"   r   rx   rx   ry   r      r   c                        t| S r   )get_unstructure_hookr"   r   r   rx   ry   r          Tc                   r   r   )r   rZ   r   r   rx   ry   r      r   c                 S  s
   t | tS r   )
issubclassr
   r   rx   rx   ry   r         
 c                 S  s   | t v S r   )r   r   rx   rx   ry   r         c                 S  s   | t v p| tu p| d u S r   )r   r   clrx   rx   ry   r     s    c                 S  s   | S r   rx   vr   rx   rx   ry   r     r   c                 S  r   r   r   r   rx   rx   ry   r     r   extendedc                 S  r   r   r   r   rx   rx   ry   r     r   c                   s   t | o|  jv S r   )r6   r   r   r   rx   ry   r   )  s    N)Dra   r   r   r   rv   unstructure_attrs_asdictr   structure_attrs_fromdictr   unstructure_attrs_astuplestructure_attrs_fromtuplerF   r   register_cls_listbytesrP   strr   register_func_listr3   r[   rY   r   r/   _unstructure_mappingr<   _unstructure_seqr1   r*   _unstructure_enumr   r6   _unstructure_unionr   r,   _gen_structure_generic_structure_newtyper\   _structure_final_factoryr.   _structure_simple_literal_structure_enum_literalr8   r0   r>   r)   _structure_deque_structure_setr9   _structure_frozensetr4   _structure_tupler;   rA   _structure_dictrD   _gen_attrs_union_structurer2   _structure_optional__getitem___structure_callintfloatr
   r   get_num_fnsr   r   )r   r   r   r   r   r   r   rx   r   ry   __init__   s   





#


#(zBaseConverter.__init__Nobjr   r   c                 C  s$   | j |d u r|j|S ||S r   r   dispatchr   )r   r   r   rx   rx   ry   r   A  s   zBaseConverter.unstructurec                 C  s   | j | jkr	tjS tjS )z3The default way of unstructuring ``attrs`` classes.)r   r   ra   rv   rw   r   rx   rx   ry   r   F  s
   zBaseConverter.unstruct_stratclsrm   c                 C     d S r   rx   )r   r   rx   rx   ry   register_unstructure_hookO     z'BaseConverter.register_unstructure_hookfuncrK   c                 C  r   r   rx   )r   r   r   rx   rx   ry   r   R  r   UnstructureHook | None"Callable[[UnstructureHook]] | Nonec                   s   |du r }t |}tt|j j |  | |S t r$t  t	 r7| j
 fdd|fg dS t rJ| j
 fdd|fg dS t dur_| j
 fdd|fg dS | j
 |fg dS )a(  Register a class-to-primitive converter function for a class.

        The converter function should take an instance of the class and return
        its Python equivalent.

        May also be used as a decorator. When used as a decorator, the first
        argument annotation from the decorated function will be used as the
        type to register the hook for.

        .. versionchanged:: 24.1.0
            This method may now be used as a decorator.
        .. versionchanged:: 25.1.0
            Modern type aliases are now supported.
        Nc                   s   |  kS r   rx   r   r   rx   ry   r   r  r   z9BaseConverter.register_unstructure_hook.<locals>.<lambda>c                      |  u S r   rx   r   r   rx   ry   r   t  r   c                   r   r   rx   r   r   rx   ry   r   w  r   )r   nextiterr   r   
annotationr   	attrs_hasr   r6   r   r   r[   r#   r   )r   r   r   r   rx   r   ry   r   U  s&   
check_funcrO   c                 C     | j ||fg dS zyRegister a class-to-primitive converter function for a class, using
        a function to check if it's a match.
        N)r   r   r   r   r   rx   rx   ry   register_unstructure_hook_func|     z,BaseConverter.register_unstructure_hook_func	predicateHCallable[[AnyUnstructureHookFactoryBase], AnyUnstructureHookFactoryBase]c                 C  r   r   rx   r   r   rx   rx   ry   !register_unstructure_hook_factory     z/BaseConverter.register_unstructure_hook_factoryrz   rd   c                 C  r   r   rx   r   r   rz   rx   rx   ry   r     r   -ExtendedUnstructureHookFactory[BaseConverter]c                 C  r   r   rx   r   rx   rx   ry   r     s   c                   >   |du r fdd}|S j  |t|rdndfg |S )a  
        Register a hook factory for a given predicate.

        The hook factory may expose an additional required parameter. In this case,
        the current converter will be provided to the hook factory as that
        parameter.

        May also be used as a decorator.

        :param predicate: A function that, given a type, returns whether the factory
            can produce a hook for that type.
        :param factory: A callable that, given a type, produces an unstructuring
            hook for that type. This unstructuring hook will be cached.

        .. versionchanged:: 24.1.0
            This method may now be used as a decorator.
            The factory may also receive the converter as a second, required argument.
        Nc                   8   t | rj | dfg d S j | dfg d S Nr   T)r   r   r   rz   r   r   rx   ry   	decorator     

zBBaseConverter.register_unstructure_hook_factory.<locals>.decoratorr   T)r   r   r   r   r   rz   r   rx   r   ry   r     s   	typecache_resultc                 C     |r| j |S | j |S )al  Get the unstructure hook for the given type.

        This hook can be manually called, or composed with other functions
        and re-registered.

        If no hook is registered, the converter unstructure fallback factory
        will be used to produce one.

        :param cache: Whether to cache the returned hook.

        .. versionadded:: 24.1.0
        )r   r   dispatch_without_cachingr   r  r  rx   rx   ry   r     s
   
z"BaseConverter.get_unstructure_hookr   rn   c                 C  r   r   rx   r   r   rx   rx   ry   register_structure_hook  r   z%BaseConverter.register_structure_hookrH   c                 C  r   r   rx   )r   r   r   rx   rx   ry   r	    r   StructureHook | Nonec                   s   |du r }t |}| |j| |S t rt  t r+|| j < | j  dS t	 r>| j
 fdd|fg dS t durS| j
 fdd|fg dS | j |fg dS )a  Register a primitive-to-class converter function for a type.

        The converter function should take two arguments:
          * a Python object to be converted,
          * the type to convert to

        and return the instance of the class. The type may seem redundant, but
        is sometimes needed (for example, when dealing with generic classes).

        This method may be used as a decorator. In this case, the decorated
        hook must have a return type annotation, and this annotation will be used
        as the type for the hook.

        .. versionchanged:: 24.1.0
            This method may now be used as a decorator.
        .. versionchanged:: 25.1.0
            Modern type aliases are now supported.
        Nc                   r   r   rx   r   r   rx   ry   r      r   z7BaseConverter.register_structure_hook.<locals>.<lambda>c                   r   r   rx   r   r   rx   ry   r     r   )r   r	  return_annotationr   r   r6   r   r   clear_cacher[   r   r#   r   )r   r   r   r   rx   r   ry   r	    s&   

	c                 C  r   r   )r   r   r   rx   rx   ry   register_structure_hook_func  r   z*BaseConverter.register_structure_hook_funcDCallable[[AnyStructureHookFactoryBase], AnyStructureHookFactoryBase]c                 C  r   r   rx   r   rx   rx   ry   register_structure_hook_factory  r   z-BaseConverter.register_structure_hook_factoryri   c                 C  r   r   rx   r   rx   rx   ry   r    r   +ExtendedStructureHookFactory[BaseConverter]c                 C  r   r   rx   r   rx   rx   ry   r    r   c                   r   )a  
        Register a hook factory for a given predicate.

        The hook factory may expose an additional required parameter. In this case,
        the current converter will be provided to the hook factory as that
        parameter.

        May also be used as a decorator.

        :param predicate: A function that, given a type, returns whether the factory
            can produce a hook for that type.
        :param factory: A callable that, given a type, produces a structuring
            hook for that type. This structuring hook will be cached.

        .. versionchanged:: 24.1.0
            This method may now be used as a decorator.
            The factory may also receive the converter as a second, required argument.
        Nc                   r   r   )r   r   r   r   r   rx   ry   r   4  r  z@BaseConverter.register_structure_hook_factory.<locals>.decoratorr   T)r   r   r   r  rx   r   ry   r    s   	rJ   type[T]rb   c                 C  s   | j |||S )z?Convert unstructured Python data structures to structured data.r   r   r   r   r   rx   rx   ry   	structureK  s   zBaseConverter.structurec                 C  r  )ah  Get the structure hook for the given type.

        This hook can be manually called, or composed with other functions
        and re-registered.

        If no hook is registered, the converter structure fallback factory
        will be used to produce one.

        :param cache: Whether to cache the returned hook.

        .. versionadded:: 24.1.0
        )r   r   r  r  rx   rx   ry   get_structure_hookO  s
   
z BaseConverter.get_structure_hookdict[str, Any]c                 C  sP   t |j}| jj}|  }|D ]}|j}t||}||jp|j|||< q|S )z9Our version of `attrs.asdict`, so we can call back to us.)r!   r   r   r   r   namegetattrr  )r   r   attrsr   rvar  r   rx   rx   ry   r   c  s   

z&BaseConverter.unstructure_attrs_asdicttuple[Any, ...]c                 C  sR   t |j}| jj}g }|D ]}|j}t||}|||jp|j| qt|S )z:Our version of `attrs.astuple`, so we can call back to us.)	r!   r   r   r   r  r  appendr  tuple)r   r   r  r   resr  r  r   rx   rx   ry   r   n  s   

z'BaseConverter.unstructure_attrs_astupler
   c                 C  s   |j S )zConvert an enum to its value.)valuer   r   rx   rx   ry   r   y  s   zBaseConverter._unstructure_enumseqSequence[T]c                   s    | j j | fdd|D S )z,Convert a sequence to primitive equivalents.c                 3  s    | ]
} |j |V  qd S r   r   .0er   rx   ry   	<genexpr>  s    z1BaseConverter._unstructure_seq.<locals>.<genexpr>r   )r   r"  rx   r(  ry   r   }  s   zBaseConverter._unstructure_seqmappingMapping[T, V]c                   s$   | j j | fdd| D S )z;Convert a mapping of attr classes to primitive equivalents.c                 3  s0    | ]\}} |j | |j |fV  qd S r   r$  r&  kr   r(  rx   ry   r)    s
    
z5BaseConverter._unstructure_mapping.<locals>.<genexpr>)r   r   r   items)r   r*  rx   r(  ry   r     s   z"BaseConverter._unstructure_mappingc                 C  s   | j |j|S )zh
        Unstructure an object as a union.

        By default, just unstructures the instance.
        r   r!  rx   rx   ry   r     s   z BaseConverter._unstructure_union)SimpleStructureHook[Mapping[str, Any], T]c                 C     t || | jdS )z2Create and return a hook for structuring generics.) _cattrs_prefer_attrib_converters)rV   r   r  rx   rx   ry   r     s   z$BaseConverter._gen_structure_genericuse_literals(Callable[[Any, type[T]], type[T] | None]c                   sB   j ||d t|jv }|rd fdd}|S  fdd}|S )	z
        Generate a structuring function for a union of attrs classes (and maybe None).

        :param use_literals: Whether to consider literal fields.
        )r2  r{   r   c                   s   | d u rd S  |  | S r   r  r   r   dis_fnr   rx   ry   structure_attrs_union  s   zGBaseConverter._gen_attrs_union_structure.<locals>.structure_attrs_unionc                   s    |  | S r   r4  r5  r6  rx   ry   r8    s   N)r{   r   )_get_dis_funcr   __args__)r   r   r2  has_noner8  rx   r6  ry   r     s   

z(BaseConverter._gen_attrs_union_structurec                 C  s   || S )zJust call ``cl`` with the given ``obj``.

        This is just an optimization on the ``_structure_default`` case, when
        we know we can skip the ``if`` s. Use for ``str``, ``bytes``, ``enum``,
        etc.
        rx   )r   r   rx   rx   ry   r     s   zBaseConverter._structure_callc                 C  s    | |j vrt|  d| | S )N not in literal )r:  	Exception)valr  rx   rx   ry   r     s   
z'BaseConverter._structure_simple_literalc                 C  s>   dd |j D }z||  W S  ty   t|  d| d w )Nc                 S  s"   i | ]}t |tr|jn||qS rx   )
isinstancer
   r   )r&  xrx   rx   ry   
<dictcomp>     " z9BaseConverter._structure_enum_literal.<locals>.<dictcomp>r<  )r:  KeyErrorr=  )r>  r  valsrx   rx   ry   r     s   
z%BaseConverter._structure_enum_literalr>  rG   c                 C  s   t |}| |||S r   r#   r  )r   r>  r  baserx   rx   ry   r     s   z BaseConverter._structure_newtypec                   s"   t |}| | |f fdd	S )Nc                   s
    | |S r   rx   )r   r   _BaseConverter__baser  rx   ry   r     r   z8BaseConverter._structure_final_factory.<locals>.<lambda>)r"   r  )r   r  rF  rx   rH  ry   r     s   
z&BaseConverter._structure_final_factoryc                 C  s:   g }t t||D ]\}}| ||}|| q	|| S )z,Load an attrs class from a sequence (tuple).)zipr!   _structure_attributer  )r   r   r   conv_objr  r   	convertedrx   rx   ry   r     s
   z'BaseConverter.structure_attrs_fromtupler  Attribute | Fieldr   c                 C  s^   |j }t|dd}| jr|r|S |du r|S z
| j|||W S  ty.   |r-| Y S  w )z%Handle an individual attrs attribute.	converterN)r  r  r   r   r   rN   )r   r  r   type_attrib_converterrx   rx   ry   rJ    s   
z"BaseConverter._structure_attributeMapping[str, Any]c              	   C  s\   i }t |D ] }z||j }W n	 ty   Y qw | |||t|d|j< q|di |S )z1Instantiate an attrs class from a mapping (dict).aliasNrx   )r!   r  rC  rJ  r  )r   r   r   rK  r  r>  rx   rx   ry   r     s   z&BaseConverter.structure_attrs_fromdictIterable[T]deque[T]c                   s  t |s|jd tv rt|}|S |jd  | j | jr|g }t }d}|D ]F}z?z
||  W n. tyc } z"t	d| d| | }g t
|dg ||_|| W Y d}~nd}~ww W |d7 }q(|d7 }w |rztd||||S t fdd	|D }|S )
z3Convert an iterable to a potentially generic deque.r   Structuring 	 @ index 	__notes__Nr   While structuring c                 3  s    | ]}| V  qd S r   rx   r%  	elem_typehandlerrx   ry   r)  *      z1BaseConverter._structure_deque.<locals>.<genexpr>)r'   r:  r   r   r   r   r   r  r=  rM   r  rW  rL   )r   r   r   r  errorsixr'  msgrx   rY  ry   r     s:   
zBaseConverter._structure_dequestructure_toSet[T]c           
        s:  t |s|jd tv r||S |jd  | j | jrg }t }d}|D ]G}z@z
||  W n/ tyb } z#t	d|j
 d|| }	g t|dg |	|_|| W Y d}~nd}~ww W |d7 }q&|d7 }w |rytd||||tu r|S ||S |tu r fdd	|D S | fd
d|D S )z3Convert an iterable into a potentially generic set.r   rU  z @ element rW  Nr   rX  c                   s   h | ]}| qS rx   rx   r%  rY  rx   ry   	<setcomp>J      z/BaseConverter._structure_set.<locals>.<setcomp>c                   s   g | ]}| qS rx   rx   r%  rY  rx   ry   
<listcomp>K  rc  z0BaseConverter._structure_set.<locals>.<listcomp>)r'   r:  r   r   r   r   setaddr=  rM   rr   r  rW  r  rL   )
r   r   r   r`  r]  r  r^  r'  excr_  rx   rY  ry   r   -  s:   
	zBaseConverter._structure_setFrozenSetSubscriptable[T]c                 C  s   | j ||tdS )z9Convert an iterable into a potentially generic frozenset.)r`  )r   	frozensetr  rx   rx   ry   r   M  s   z"BaseConverter._structure_frozenset
dict[T, V]c                   s  t |s|jttfkrt|S |j\| jr| j}| j}g }i }| D ]m\}}z||}	W n+ tya }
 zt	d||}g t
|
dg ||
_||
 W Y d}
~
q+d}
~
ww z||}|	||< W q+ ty }
 zt	d||}g t
|
dg ||
_||
 W Y d}
~
q+d}
~
ww |rtd||||S tv r| jfdd| D S tv r| j  fdd| D S | j | j fd	d| D S )
z2Convert a mapping into a potentially generic dict.z Structuring mapping value @ key rW  NzStructuring mapping key @ key rX  c                   s   i | ]
\}}| |qS rx   rx   r,  )val_convval_typerx   ry   rA  z      z1BaseConverter._structure_dict.<locals>.<dictcomp>c                   s   i | ]
\}} ||qS rx   rx   r,  )key_convkey_typerx   ry   rA  }  rm  c                   s"   i | ]\}} ||qS rx   rx   r,  rn  ro  rk  rl  rx   ry   rA    rB  )r'   r:  r   dictr   r   r   r.  r=  rM   r  rW  r  rL   r   )r   r   r   key_handlerval_handlerr]  r  r-  r   r   rg  r_  keyrx   rp  ry   r   S  sV   


zBaseConverter._structure_dictc                 C  s@   |d u rd S |j }|d tu r|d n|d }| j|||S )Nr   r   )r:  r   r   r   )r   r   unionunion_paramsotherrx   rx   ry   r     s
   z!BaseConverter._structure_optionalr   tupc                   s  |t tfv rdn|j}|o|d tu }|du s|r#|d tv r#t|S |r|d j jrg }g }d}|D ]F}z?z
| | W n. t	yu }	 z"t
d| d| |}
g t|	dg |
|	_||	 W Y d}	~	nd}	~	ww W |d7 }q:|d7 }w |rtd|||t|S t fd	d
|D S t|}jr7g }g }tt||D ]D\}\}}zj| | || W q t	y }	 z"t
d| d| ||}
g t|	dg |
|	_||	 W Y d}	~	qd}	~	ww t||kr't||k rdnd}t| d|d|}	d| }
g t|	dg |
|	_||	 |r3td|||t|S t||krWt|t|k rIdnd}t| d|d|tfddt||D S )z#Deal with structuring into a tuple.Nr   rU  rV  rW  r   rX  c                 3  s    | ]} |V  qd S r   rx   r%  )convtup_typerx   ry   r)    r\  z1BaseConverter._structure_tuple.<locals>.<genexpr>z
Not enoughzToo manyz values in z to structure as c                   s"   g | ]\}} j |||qS rx   r  )r&  r   r'  r   rx   ry   rd    rB  z2BaseConverter._structure_tuple.<locals>.<listcomp>)r   r  r:  Ellipsisr   r   r   r   r  r=  rM   r  rW  rL   r   	enumeraterI  
ValueError)r   r   rx  
tup_paramshas_ellipsisr]  r  r^  r'  rg  r_  exp_lenr   problemrx   )rz  r   r{  ry   r     sz   

zBaseConverter._structure_tupleru  	overrides#dict[str, AttributeOverride] | NoneCallable[[Any], type]c                 C  sh   |j }t|v rtdd |D }tdd |D std|dt| g|R ||dur/|dS ddS )	z<Fetch or try creating a disambiguation function for a union.c                 s  s    | ]	}|t ur|V  qd S r   )r   r%  rx   rx   ry   r)        z.BaseConverter._get_dis_func.<locals>.<genexpr>c                 s  s     | ]}t t|p
|V  qd S r   )r   r$   r%  rx   rx   ry   r)    s    zeOnly unions of attrs classes and dataclasses supported currently. Register a structure hook manually.)rO  Nfrom_converter)r2  r  )r:  r   r  allrN   rC   )r   ru  r2  r  union_typesrx   rx   ry   r9    s$   
zBaseConverter._get_dis_funcc                 C  s   |   S r   )copy)r   r   rx   rx   ry   __deepcopy__  s   zBaseConverter.__deepcopy__Callable[[], Any] | NoneUnstructureStrategy | Nonebool | Noner   c                 C  s   |  |dur|n| j|dur|n| j| jkrtjntj|dur!|n| j|dur)|n| j}| j	
|j	| j | j
|j| j |S )Create a copy of the converter, keeping all existing custom hooks.

        :param detailed_validation: Whether to use a slightly slower mode for detailed
            validation errors.
        N)r   r   r   r   ra   rv   rw   r   r   r   copy_tor   r   r   )r   r   r   r   r   r  rx   rx   ry   r    s"   zBaseConverter.copy)r   r   r   ra   r   r|   r   r|   r   r   r   r   r{   r   r   )r   r   r   r   r{   r   )r{   ra   )r   rm   r{   rm   )r   r   r   rK   r{   r   NN)r   r   r   r   r{   r   )r   rO   r   rK   r{   r   )r   rO   r{   r   r   rO   rz   rd   r{   rd   )r   rO   rz   r   r{   r   )T)r  r   r  r|   r{   rK   )r   rn   r{   rn   )r   r   r   rH   r{   r   )r   r   r   r
  r{   r   )r   rO   r   rH   r{   r   )r   rO   r{   r  r   rO   rz   ri   r{   ri   )r   rO   rz   r  r{   r  )r   rJ   r   r  r{   rb   )r  r   r  r|   r{   rH   )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   r2  r|   r{   r3  )r   r   r   r  r{   r   )r>  rJ   r{   rG   )r   r  r   r  r{   rb   )r  rM  r   r   r{   r   )r   rQ  r   r  r{   rb   )r   rS  r   r   r{   rT  )r   rS  r   r   r`  r  r{   ra  )r   rS  r   r   r{   rh  )r   r+  r   r   r{   rj  )r   r   rx  r  r{   rb   )TN)ru  r   r2  r|   r  r  r{   r  )r{   r^   )NNNN)
r   r  r   r  r   r  r   r  r{   r   )1rr   rs   rt   ru   	__slots__rq  ra   rv   r   r   propertyr   r   r   r   r   r   r	  r  r  r  r  r   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   r   rJ  r   r   re  r   r   r   r   r   r9  r  r  rx   rx   rx   ry   r^      s     

'
.
+

,







		








 
/
D
r^   c                      sd  e Zd ZdZdZeejddi i dddd dd dfdg fddZe	dhd d!Z
e	did$d!Z
e	djd&d!Z
dk fd(d!	Z
e	dld*d+Ze	dmd-d+Ze	dnd/d+Zdk fd0d+	Zdod4d5Zd6d7 Zdpd9d:Zdqd>d?ZdrdAdBZdsdDdEZdtdGdHZdudJdKZ	'dkdvdNdOZ	'dkdwdQdRZ	'	'dxdydVdWZdzdZd[Zd{d]d^Z	'	'	'	'	'	'	'	'	'd|d}dedfZ  ZS )~r_   zAA converter which generates specialized un/structuring functions.)_unstruct_collection_overridesforbid_extra_keysomit_if_defaulttype_overrides	use_aliasFTc                 C  r   r   r   r   rx   rx   ry   r   '  r   zConverter.<lambda>c                 C  r   r   r   r   rx   rx   ry   r   (  r   r   r   r   ra   r  r|   r  r   Mapping[type, AttributeOverride]unstruct_collection_overridesMapping[type, UnstructureHook]r   r   r   r   r   r   r  c                   s  t  j|||||	|
d | _| _t| _| _dd | D }| _|}t	|v r@t
|vr6|t	 |t
< t|vr@|t	 |t< t
|v rNt|vrN|t
 |t< t|v rft|vr\|t |t< t|vrf|t |t< t|v r~t|vrt|t |t< t|vr~|t |t< t|v rt|vr|t |t< t|v rt|vr|t |t< t|v rt|vr|t |t< |tju r t j  t j  t j  t j  t t!  t" j#  t$ j%  t& fdd  t' fdd  t( j)  t* j+  dd  fdd  t j,  t$ j-  t. j/  t0t1  t* j2  d	d  j3  j45  _6 j75  _8d
S )au  
        :param detailed_validation: Whether to use a slightly slower mode for detailed
            validation errors.
        :param unstructure_fallback_factory: A hook factory to be called when no
            registered unstructuring hooks match.
        :param structure_fallback_factory: A hook factory to be called when no
            registered structuring hooks match.
        :param use_alias: Whether to use the field alias instead of the field name as
            the un/structured dictionary key by default.

        ..  versionadded:: 23.2.0 *unstructure_fallback_factory*
        ..  versionadded:: 23.2.0 *structure_fallback_factory*
        ..  versionchanged:: 24.2.0
            The default `structure_fallback_factory` now raises errors for missing handlers
            more eagerly, surfacing problems earlier.
        ..  versionadded:: 25.2.0 *use_alias*
        )r   r   r   r   r   r   c                 S  s   i | ]\}}t |p||qS rx   )r$   r,  rx   rx   ry   rA  K  s    z&Converter.__init__.<locals>.<dictcomp>c                       j | tdS Nunstructure_to)gen_unstructure_iterablere  r   r   rx   ry   r     r   z$Converter.__init__.<locals>.<lambda>c                   r  r  )r  ri  r   r   rx   ry   r     r   c                 S  r   r   r   r   rx   rx   ry   r     r   c                   r   r   )r   r#   r   r   rx   ry   r     r   c                 S  r   r   r   r   rx   rx   ry   r     r   N)9superr   r  r  rq  r  r  r.  r  r   r   r   re  r   r   r  r   r   r   r   r   ra   rv   r   r%   gen_unstructure_attrs_fromdictr  gen_structure_attrs_fromdictr&   gen_unstructure_annotatedr-   gen_unstructure_hetero_tupler;   rB   r<   r  r/   gen_unstructure_mappingr1   r*   r2   gen_unstructure_optionalr5   gen_unstructure_typeddictgen_structure_annotatedgen_structure_mappingr(   gen_structure_counterr:   r7   gen_structure_typeddictget_structure_newtyper   r   r   r   r   )r   r   r   r  r  r  r  r   r   r   r   r  cor$  r   ry   r     s   !





zConverter.__init__r   rO   r{   @Callable[[AnyUnstructureHookFactory], AnyUnstructureHookFactory]c                 C  r   r   rx   r   rx   rx   ry   r     r   z+Converter.register_unstructure_hook_factoryrz   rd   c                 C  r   r   rx   r   rx   rx   ry   r     r   )ExtendedUnstructureHookFactory[Converter]c                 C  r   r   rx   r   rx   rx   ry   r     r   Nc                      t  ||S r   )r  r   r   r$  rx   ry   r        <Callable[[AnyStructureHookFactory], AnyStructureHookFactory]c                 C  r   r   rx   r   rx   rx   ry   r    r   z)Converter.register_structure_hook_factoryri   c                 C  r   r   rx   r   rx   rx   ry   r    r   'ExtendedStructureHookFactory[Converter]c                 C  r   r   rx   r   rx   rx   ry   r    r   c                   r  r   )r  r  r   r$  rx   ry   r    r  r  r  Callable[[Any, Any], T]c                   s    t | |   fddS )Nc                   s
   |  S r   rx   r   rF  r[  rx   ry   r     r   z1Converter.get_structure_newtype.<locals>.<lambda>rE  r   r  rx   r  ry   r    s   
zConverter.get_structure_newtypec                 C  s   |j }| |S r   )
__origin__r   )r   r  originrx   rx   ry   r    s   
z#Converter.gen_unstructure_annotatedr   c                   s   |j |   fddS )z#A hook factory for annotated types.c                   s
    | S r   rx   r   hookr  rx   ry   r     r   z3Converter.gen_structure_annotated.<locals>.<lambda>)r  r  r  rx   r  ry   r    s   
z!Converter.gen_structure_annotatedr   r   Callable[[dict], dict]c                 C  s
   t || S )zgGenerate a TypedDict unstructure function.

        Also apply converter-scored modifications.
        )make_typeddict_dict_unstruct_fnr  rx   rx   ry   r    s   
z#Converter.gen_unstructure_typeddictCallable[[T], dict[str, Any]]c                   sd   t |}t|p|}t|rtdd |D rt|p|  fdd|D }t| fd ji|S )Nc                 s      | ]	}t |jtV  qd S r   r?  r  r   r&  r  rx   rx   ry   r)    r  z;Converter.gen_unstructure_attrs_fromdict.<locals>.<genexpr>c                   (   i | ]}|j  jv r|j j|j  qS rx   r  r  r  r  r   rx   ry   rA    
    z<Converter.gen_unstructure_attrs_fromdict.<locals>.<dictcomp>_cattrs_omit_if_default)r$   r!   r   anyr   rW   r  )r   r   r  attribsattrib_overridesrx   r   ry   r    s   
z(Converter.gen_unstructure_attrs_fromdictCallable[[T], Any]c                 C  sN   |j }|d tu r|d n|d }t|tr| j}n| |}|fdd}|S )z2Generate an unstructuring hook for optional types.r   r   c                 S  s   | d u rd S || S r   rx   )r>  _handlerrx   rx   ry   unstructure_optional	  s   z@Converter.gen_unstructure_optional.<locals>.unstructure_optional)r:  r   r?  r   r   r   )r   r   rv  rw  r[  r  rx   rx   ry   r    s   

z"Converter.gen_unstructure_optionalCallable[[dict, Any], dict]c                 C  r0  )zeGenerate a TypedDict structure function.

        Also apply converter-scored modifications.
        )_cattrs_detailed_validation)make_typeddict_dict_struct_fnr   r  rx   rx   ry   r    s   z!Converter.gen_structure_typeddict%Callable[[Mapping[str, Any], Any], T]c                   st   t t|rt|p
|n|}t|rtdd |D rt|  fdd|D }t| f j j j	 j
d|S )Nc                 s  r  r   r  r  rx   rx   ry   r)    r  z9Converter.gen_structure_attrs_fromdict.<locals>.<genexpr>c                   r  rx   r  r  r   rx   ry   rA    r  z:Converter.gen_structure_attrs_fromdict.<locals>.<dictcomp>)_cattrs_forbid_extra_keysr1  r  _cattrs_use_alias)r!   r+   r$   r   r  r   rV   r  r   r   r  )r   r   r  r  rx   r   ry   r    s&    
z&Converter.gen_structure_attrs_fromdictr  rT   c                 C  B   | j t|p||pt}t|| |d}| jj||fgdd |S Nr  Tdirect)r  getr$   r   r=   r   r   r   r   r  hrx   rx   ry   r  -     z"Converter.gen_unstructure_iterablerS   c                 C  r  r  )r  r  r$   r  rX   r   r   r  rx   rx   ry   r  7  r  z&Converter.gen_unstructure_hetero_tuplerr  'Callable[[Any, Any | None], Any] | NonerU   c                 C  sD   | j t|p||pt}t|| ||d}| jj||fgdd |S )N)r  rr  Tr  )r  r  r$   rq  r@   r   r   )r   r   r  rr  r  rx   rx   ry   r  A  s   z!Converter.gen_unstructure_mappingtype[CounterT]0SimpleStructureHook[Mapping[Any, Any], CounterT]c                 C  s.   t || tt| jd}| jj||fgdd |S )N)r`  rl  r   Tr  )r?   r   r   r   r   r   )r   r   r  rx   rx   ry   r  P  s   zConverter.gen_structure_counter+SimpleStructureHook[Mapping[Any, Any], Any]c                 C  sL   t |p|}|ttttfv rt}t|| || jd}| jj	||fgdd |S )N)r   Tr  )
r$   r   AbcMutableMappingr   
AbcMappingrq  r?   r   r   r   )r   r   r`  r  rx   rx   ry   r  ]  s   
zConverter.gen_structure_mappingr  r  r  'Mapping[type, AttributeOverride] | None%Mapping[type, UnstructureHook] | Noner   c
                 C  s   | j |dur|n| j|dur|n| j| jkrtjntj|dur!|n| j|dur)|n| j|dur1|n| j	|dur9|n| j
|durA|n| j|durI|n| j|	durQ|	n| jd	}
| jj|
j| jd | jj|
j| jd |
S )r  N)r  )skip)r   r   r   r   ra   rv   rw   r  r  r  r  r   r   r  r   r  r   r   r   )r   r   r   r  r  r  r  r   r   r  r  rx   rx   ry   r  n  s8   $zConverter.copy)r   r   r   ra   r  r|   r  r|   r  r  r  r  r   r|   r   r|   r   r   r   r   r  r|   )r   rO   r{   r  r  )r   rO   rz   r  r{   r  r   )r   rO   r{   r  r  )r   rO   rz   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{   rT   )r   r   r  r   r{   rS   r  )r   r   r  r   rr  r  r{   rU   )r   r  r{   r  )r   r   r{   r  )	NNNNNNNNN)r   r  r   r  r  r  r  r  r  r  r  r  r   r  r   r  r  r  r{   r   )rr   rs   rt   ru   r  rq  ra   rv   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__rx   rx   r$  ry   r_     sr    
 






	

r_   r`   N)rz   r   r{   r|   )
__future__r   collectionsr   r   collections.abcr   r   r   r  r   r  dataclassesr	   enumr
   inspectr   r   r~   pathlibr   typingr   r   r   r   r   r  r   r   r   r   typing_extensionsr   _compatr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   colsr7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   disambiguatorsrC   rD   r   rE   rF   rG   rH   rI   rJ   rK   r]  rL   rM   rN   fnsrO   rP   rQ   genrR   rS   rT   rU   rV   rW   rX   gen.typeddictsr  r  literalsrY   typealiasesrZ   r[   r\   typesr]   __all__rb   rc   rd   rf   __annotations__rg   rh   ri   rj   rk   rl   rm   rn   ro   ra   r   r^   r_   r`   rx   rx   rx   ry   <module>   s    8%$	$	
      p   