
    tAcג                     h   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mZmZ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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.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJ  eKd          ZL ed          ZM ed          ZN G d de          ZOdedeegePf         fdZQdedePfdZRdedePfdZSdedePfdZTdedePfdZU G d d          ZV G d deV          ZWeWZXdS )     )Counter)
MutableSet)Field)Enum)	lru_cache)AnyCallableDictIterableListNoReturnOptionalTupleTypeTypeVarUnion)	Attribute)has)resolve_types)IterableValidationErrorStructureHandlerNotFoundError   )FrozenSetSubscriptableMappingMutableMappingMutableSequenceOriginAbstractSetOriginMutableSetSequenceSetfieldsget_newtype_base
get_originr   has_with_genericis_annotatedis_bare
is_counteris_frozenset
is_genericis_generic_attrsis_hetero_tuple
is_literal
is_mappingis_mutable_setis_protocolis_sequenceis_tupleis_union_type)create_uniq_field_dis_func)MultiStrategyDispatch)AttributeOverrideDictStructureFnHeteroTupleUnstructureFnIterableUnstructureFnMappingStructureFnMappingUnstructureFnmake_dict_structure_fnmake_dict_unstructure_fn make_hetero_tuple_unstructure_fnmake_iterable_unstructure_fnmake_mapping_structure_fnmake_mapping_unstructure_fnNTVc                       e Zd ZdZdZdZdS )UnstructureStrategyz)`attrs` classes unstructuring strategies.asdictastupleN)__name__
__module____qualname____doc__AS_DICTAS_TUPLE     3/usr/lib/python3/dist-packages/cattrs/converters.pyrD   rD   M   s        33GHHHrN   rD   typreturnc                       fdS )z
a shortcutc                 $    t          |           S N)
issubclass)clsrP   s    rO   <lambda>z_subclass.<locals>.<lambda>V   s    z#s++ rN   rM   rP   s   `rO   	_subclassrY   T   s    +++++rN   c                 \    t          |           ot          d | j        D                       S )Nc              3   R   K   | ]"}t          t          |          p|          V  #d S rT   r   r#   .0es     rO   	<genexpr>z!is_attrs_union.<locals>.<genexpr>Z   s5      %T%T!c*Q--*<1&=&=%T%T%T%T%T%TrN   r2   all__args__rX   s    rO   is_attrs_unionrd   Y   s.    T#%T%Ts|%T%T%T"T"TTrN   c                 \    t          |           ot          d | j        D                       S )Nc              3   d   K   | ]+}|t           u pt          t          |          p|          V  ,d S rT   )NoneTyper   r#   r]   s     rO   r`   z)is_attrs_union_or_none.<locals>.<genexpr>^   sO       & &56X0Z]]/a00& & & & & &rN   ra   rX   s    rO   is_attrs_union_or_nonerh   ]   sA     # & &:=,& & & # # rN   c                 l    t          |           o%t          | j        v ot          | j                  dk    S )N   )r2   rg   rc   lenrX   s    rO   is_optionalrl   c   s1    U(cl":Us3<?P?PTU?UUrN   c                 \    t          |           ot          d | j        D                       S )Nc              3   @   K   | ]}t          |t                    V  d S rT   )
isinstancer   )r^   vals     rO   r`   z.is_literal_containing_enums.<locals>.<genexpr>h   s,      "Q"QS:c4#8#8"Q"Q"Q"Q"Q"QrN   )r,   anyrc   rX   s    rO   is_literal_containing_enumsrr   g   s,    c??Qs"Q"QCL"Q"Q"QQQQrN   c                      e Zd ZdZdZeej        ddfdeg e	f         dede
de
d	d
f
dZd?de	de	d	e	fdZed	efd            Zde	dee	ge	f         d	d
fdZdee	ge
f         dee	ge	f         d	d
fdZdee	ge
f         dee	gee	ge	f         f         d	d
fdZde	dee	ee         gef         d	d
fdZdeee         ge
f         dee	ee         gef         d	d
fdZdee	ge
f         dee	gee	e	ge	f         f         d	d
fdZde	dee         d	efdZde	d	eee	f         fdZde	d	ee	df         fdZded	e	fd Zeded	efd!            Z d"e!e         d	e!e         fd#Z"d$e#ee$f         d	e#ee$f         fd%Z%de	d	e	fd&Z&eded	e'fd'            Z(dee         d	e)e         fd(Z*de	d	ee	ee         ge+ee                  f         fd)Z,ede	dee         d	e	fd*            Z-ed+             Z.ed,             Z/d- Z0dee	df         dee         d	efd.Z1d/e2e3e4f         d0e	d	e	fd1Z5de#ee	f         dee         d	efd2Z6de7e         de	d	e8e         fd3Z9e:fde7e         de	d4e;d	e<e         fd5Z=de7e         de	d	e>e         fd6Z?de#ee$f         de	d	eee$f         fd7Z@d8 ZAd9 ZBde	d:ee         d	efd;ZCed	edef         fd<            ZDd@d=ZE	 	 	 	 dAde+eg e	f                  de+e         de+e
         de+e
         d	d f
d>ZFd
S )BBaseConverterz2Converts between structured and unstructured data.)	_dis_func_cache_unstructure_func_unstructure_attrs_structure_attrs_dict_factory_union_struct_registry_structure_func_prefer_attrib_convertersdetailed_validationFTdict_factoryunstruct_stratprefer_attrib_convertersr}   rQ   Nc                 L    t          |          }| _        | _        |t           j        u r j         _         j         _        n j         _         j	         _         t                       j                   _        t           j                   _         j                            t"           j        ft$           j        fg            j                            t(           fdft*           j        ft.           j        ft2           j        ft4           j        ft7          t8                     j        ft<           j        ft>           j         fg           t          tB          j"                   _#         j#                            d d ftH           j%        dfd  j&        ftN           j(        ftR           j*        ft.           j+        ft2           j,        ft4           j-        ft\           j/        ft*           j0        ftb           j2        df fd j3        fth           j5        ft<           j        fg            j#                            t$           j6        ft"           j6        ftn           j6        ftp           j6        ft8           j6        fg           | _9        i  _:        d S )Nc                 <                         | | j                  S )N)unstructure_as)unstructure	__class__)oselfs    rO   rW   z(BaseConverter.__init__.<locals>.<lambda>   s    d..q.MM rN   c                 .    | t           u p| t          u p| d u S rT   )r   r   )cls    rO   rW   z(BaseConverter.__init__.<locals>.<lambda>   s    B#IExE2: rN   c                     | S rT   rM   )v_s     rO   rW   z(BaseConverter.__init__.<locals>.<lambda>   s    TU rN   Tc                 $    t          |           d uS rT   r"   ts    rO   rW   z(BaseConverter.__init__.<locals>.<lambda>   s    +A..d: rN   c                 4    t          |           o| j        v S rT   )r2   rz   r   r   s    rO   rW   z(BaseConverter.__init__.<locals>.<lambda>   s    mA..S18S3S rN   );rD   r|   r}   rK   unstructure_attrs_asdictrw   structure_attrs_fromdictrx   unstructure_attrs_astuplestructure_attrs_fromtupler   _get_dis_funcru   r4   _unstructure_identityrv   register_cls_listbytesstrregister_func_listr/   r-   _unstructure_mappingr0   _unstructure_seqr.   r(   rY   r   _unstructure_enumr   r2   _unstructure_unionrt   _structure_errorr{   r*   _gen_structure_generic_structure_newtyper,   _structure_simple_literalrr   _structure_enum_literal_structure_list_structure_set_structure_frozensetr1   _structure_tuple_structure_dictrh   _gen_attrs_union_structure_structure_unionrl   _structure_optional_structure_callintfloatry   rz   )r   r~   r   r   r}   s   `    rO   __init__zBaseConverter.__init__z   s    -^<<)A&#6  0888&*&CD#$($AD!!&*&DD#$($BD!*y{{4+=>>!6t7Q!R!R00T/038R2ST	
 	
 	
 	11  MMMM T67d34!67t454$"89d-. 78	
 	
 	
&  5]5STT//EE~~V!4#>E::D<STT;<,d.JKd23!45t89401T12')H$OSSSS) d67d+,#	
 	
 	
, 	..d*+,-d*+,-t+,	
 	
 	
 * OQ###rN   objr   c                 Z     | j                             ||j        n|          |          S rT   rv   dispatchr   )r   r   r   s      rO   r   zBaseConverter.unstructure   s<    
t%..+3CMM
 

  	rN   c                 R    | j         | j        k    rt          j        nt          j        S )z3The default way of unstructuring ``attrs`` classes.)rw   r   rD   rK   rL   )r   s    rO   r   zBaseConverter.unstruct_strat   s+    
 &$*GGG  ''$-	
rN   rV   funcc                 B   t                    rt                     t                    r"| j                            fd|fg           dS t                    "| j                            fd|fg           dS | j                            |fg           dS )zRegister a class-to-primitive converter function for a class.

        The converter function should take an instance of the class and return
        its Python equivalent.
        c                     | k    S rT   rM   r   rV   s    rO   rW   z9BaseConverter.register_unstructure_hook.<locals>.<lambda>   s    !s( rN   Nc                     | u S rT   rM   r   s    rO   rW   z9BaseConverter.register_unstructure_hook.<locals>.<lambda>   s    !s( rN   )	attrs_hasr   r2   rv   r   r"   r   )r   rV   r   s    ` rO   register_unstructure_hookz'BaseConverter.register_unstructure_hook   s     S>> 	# 	D"558J8J8J8JD7Q6RSSSSSc""."558J8J8J8JD7Q6RSSSSS"44sDk]CCCCCrN   
check_funcc                 @    | 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rv   r   r   r   r   s      rO   register_unstructure_hook_funcz,BaseConverter.register_unstructure_hook_func   s)     	11J3E2FGGGGGrN   	predicatefactoryc                 B    | j                             ||dfg           dS )aP  
        Register a hook factory for a given predicate.

        A predicate is a function that, given a type, returns whether the factory
        can produce a hook for that type.

        A factory is a callable that, given a type, produces an unstructuring
        hook for that type. This unstructuring hook will be cached.
        TNr   r   r   r   s      rO   !register_unstructure_hook_factoryz/BaseConverter.register_unstructure_hook_factory   s+     	11Iw3M2NOOOOOrN   r   c                 H   t                    rt                     t                    r%|| j        <   | j                                         dS t                    "| j                            fd|fg           dS | j                            |fg           dS )an  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).
        Nc                     | u S rT   rM   )r   r   s    rO   rW   z7BaseConverter.register_structure_hook.<locals>.<lambda>  s    R rN   )	r   r   r2   rz   r{   clear_cacher"   r   r   )r   r   r   s    ` rO   register_structure_hookz%BaseConverter.register_structure_hook  s     R== 	" 	A.2D'+ ,,.....b!!- 336G6G6G6G5N4OPPPPP 22RJ<@@@@@rN   c                 @    | j                             ||fg           dS r   r{   r   r   s      rO   register_structure_hook_funcz*BaseConverter.register_structure_hook_func  s)     	//*d1C0DEEEEErN   c                 B    | j                             ||dfg           dS )aK  
        Register a hook factory for a given predicate.

        A predicate is a function that, given a type, returns whether the factory
        can produce a hook for that type.

        A factory is a callable that, given a type, produces a structuring
        hook for that type. This structuring hook will be cached.
        TNr   r   s      rO   register_structure_hook_factoryz-BaseConverter.register_structure_hook_factory"  s+     	//)Wd1K0LMMMMMrN   c                 J     | j                             |          ||          S )z?Convert unstructured Python data structures to structured data.r{   r   r   r   r   s      rO   	structurezBaseConverter.structure2  s'     1t#,,R00b999rN   c                     t          |j                  }| j        j        }|                                 }|D ]<}|j        }t          ||          }  ||j        p|j                  |          ||<   =|S )z9Our version of `attrs.asdict`, so we can call back to us.)r!   r   rv   r   ry   namegetattrtype)r   r   attrsr   rvar   r   s           rO   r   z&BaseConverter.unstructure_attrs_asdict8  s    s}%%)2!! 	: 	:A6DT""A6xx 5!+66q99BtHH	rN   .c                    t          |j                  }| j        j        }t	                      }|D ]L}|j        }t          ||          }|                      ||j        p|j                  |                     Mt          |          S )z:Our version of `attrs.astuple`, so we can call back to us.)
r!   r   rv   r   listr   r   appendr   tuple)r   r   r   r   resr   r   r   s           rO   r   z'BaseConverter.unstructure_attrs_astupleC  s    s}%%)2ff 	; 	;A6DT""AJJ6xx 5!+66q99::::SzzrN   c                     |j         S )zConvert an enum to its value.)valuer   r   s     rO   r   zBaseConverter._unstructure_enumN  s
    yrN   c                     | S )zJust pass it through.rM   )r   s    rO   r   z#BaseConverter._unstructure_identityR  s	     
rN   seqc                 ^    | j         j        |                    fd|D                       S )z,Convert a sequence to primitive equivalents.c              3   J   K   | ]}  |j                   |          V  d S rT   r   )r^   r_   r   s     rO   r`   z1BaseConverter._unstructure_seq.<locals>.<genexpr>[  s:      CC!2XXak22155CCCCCCrN   r   )r   r   r   s     @rO   r   zBaseConverter._unstructure_seqW  s7     )2}}CCCCsCCCCCCrN   mappingc                     | j         j        |                    fd|                                D                       S )z;Convert a mapping of attr classes to primitive equivalents.c              3      K   | ]9\  }}  |j                   |            |j                   |          fV  :d S rT   r   )r^   kr   r   s      rO   r`   z5BaseConverter._unstructure_mapping.<locals>.<genexpr>c  sm       !
 !
1 #XXak""1%%'<xx'<'<Q'?'?@!
 !
 !
 !
 !
 !
rN   )rv   r   r   items)r   r   r   s     @rO   r   z"BaseConverter._unstructure_mapping]  sV    
 )2   !
 !
 !
 !
!
 !
 !
 
 
 	
rN   c                 R     | j                             |j                  |          S )zh
        Unstructure an object as a union.

        By default, just unstructures the instance.
        r   r   s     rO   r   z BaseConverter._unstructure_unionk  s'     >t%..s}==cBBBrN   c                 N    d                     |          }t          ||          )zGAt the bottom of the condition stack, we explode if we can't handle it.z:Unsupported type: {0!r}. Register a structure hook for it.type_)formatr   )r   r   msgs      rO   r   zBaseConverter._structure_erroru  s,     NTTUWXX+Cr::::rN   c                 4    t          || | j                  }|S )z2Create and return a hook for structuring generics.) _cattrs_prefer_attrib_converters)r;   r|   )r   r   fns      rO   r   z$BaseConverter._gen_structure_generic{  s'    #t7U
 
 
 	rN   c                 n                           |          t          |j        v }|r fd}n fd}|S )zNGenerate a structuring function for a union of attrs classes (and maybe None).c                 J    | d S                      |  |                     S rT   r   r   r   dis_fnr   s     rO   structure_attrs_unionzGBaseConverter._gen_attrs_union_structure.<locals>.structure_attrs_union  s)    ;4~~c66#;;777rN   c                 B                         |  |                     S rT   r   r   s     rO   r   zGBaseConverter._gen_attrs_union_structure.<locals>.structure_attrs_union  s    ~~c66#;;777rN   )r   rg   rc   )r   r   has_noner   r   s   `   @rO   r   z(BaseConverter._gen_attrs_union_structure  sv     ##B''r{* 
	88 8 8 8 8 8 88 8 8 8 8 8 %$rN   c                      ||           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.
        rM   )r   r   s     rO   r   zBaseConverter._structure_call  s     r#wwrN   c                 @    | |j         vrt          |  d|           | S )N not in literal )rc   	Exception)rp   r   s     rO   r   z'BaseConverter._structure_simple_literal  s0    dm##s::D::;;;
rN   c                 |    d |j         D             }	 ||          S # t          $ r t          |  d|           d w xY w)Nc                 L    i | ]!}t          |t                    r|j        n||"S rM   )ro   r   r   )r^   xs     rO   
<dictcomp>z9BaseConverter._structure_enum_literal.<locals>.<dictcomp>  s/    RRRqJq$//6QRRRrN   r  )rc   KeyErrorr  )rp   r   valss      rO   r   z%BaseConverter._structure_enum_literal  sd    RRDMRRR	F9 	F 	F 	Fs::D::;;E	Fs     ;c                 h    t          |          } | j                            |          ||          S rT   r"   r{   r   )r   rp   r   bases       rO   r   z BaseConverter._structure_newtype  s2    %%2t#,,T223===rN   c                     g }t          t          |          |          D ]0\  }}|                     ||          }|                    |           1 || S )z,Load an attrs class from a sequence (tuple).)zipr!   _structure_attributer   )r   r   r   conv_objr   r   	converteds          rO   r   z'BaseConverter.structure_attrs_fromtuple  s`    F2JJ,, 	' 	'HAu11!U;;IOOI&&&&r8}rN   r   r   c                     |j         }t          |dd          }| j        r|r|S ||S 	  | j                            |          ||          S # t
          $ r |r|cY S  w xY w)z%Handle an individual attrs attribute.	converterN)r   r   r|   r{   r   r   )r   r   r   r   attrib_converters        rO   r  z"BaseConverter._structure_attribute  s    "1k488) 	.> 	 L=L	74'0077uEEE, 	 	 	 	s   #A AAc                     i }t          |          D ]R}|j        }	 ||         }n# t          $ r Y w xY w|d         dk    r
|dd         }|                     ||          ||<   S |di |S )z1Instantiate an attrs class from a mapping (dict).r   r   r   NrM   )r!   r   r  r  )r   r   r   r  r   r   rp   s          rO   r   z&BaseConverter.structure_attrs_fromdict  s      	? 	?A6D$i    Aw#~~ABBx!66q#>>HTNNr~~H~~s   %
22c                 $  	 t          |          s|j        d         t          u rd |D             }n|j        d         | j                                      	| j        rg }g }d}|D ]}	 |                     	|                     nN# t          $ rA}d| d| }t          |dg           |gz   |_	        |                    |           Y d}~nd}~ww xY w|dz  }w# |dz  }w xY w|rt          d|||          n	fd	|D             }|S )
z2Convert an iterable to a potentially generic list.r   c                     g | ]}|S rM   rM   r]   s     rO   
<listcomp>z1BaseConverter._structure_list.<locals>.<listcomp>  s    """1"""rN   Structuring 	 @ index 	__notes__Nr   While structuring c                 (    g | ]} |          S rM   rM   r^   r_   	elem_typehandlers     rO   r  z1BaseConverter._structure_list.<locals>.<listcomp>  s%    :::wwq),,:::rN   )r&   rc   r   r{   r   r}   r   r  r   r  r   )
r   r   r   r   errorsixr_   r   r  r   s
           @@rO   r   zBaseConverter._structure_list  s   2;; 	;"+a.C//""c"""CCAI*33I>>G' ;    A 

771i#8#89999$ ) ) )>R>>">>&-ab&A&ASE&Ia(((((((()
 aa 13R33VR  
 ;::::c:::
s0   ,BC 
C7CC CC  C'structure_toc                   	
 t          |          s|j        d         t          u r ||          S |j        d         	| j                            	          
| j        rg }t                      }|D ]u}	 |                     
|	                     ## t          $ rF}d|j	         d|}t          |dg           |gz   |_        |                    |           Y d}~nd}~ww xY w|rt          d|||          |t          u r|n
 ||          S |t          u r	
fd|D             S  |	
fd|D                       S )	z3Convert an iterable into a potentially generic set.r   r  z @ element r  Nr  c                 (    h | ]} |          S rM   rM   r  s     rO   	<setcomp>z/BaseConverter._structure_set.<locals>.<setcomp>  s%    777aGGAy))777rN   c                 (    g | ]} |          S rM   rM   r  s     rO   r  z0BaseConverter._structure_set.<locals>.<listcomp>  s%     D D D1I!6!6 D D DrN   )r&   rc   r   r{   r   r}   setaddr  rG   r   r  r   r   )r   r   r   r#  r!  r   r_   excr   r  r   s            @@rO   r   zBaseConverter._structure_set  s    2;; 	%"+a.C//<$$$KN	&//	::# 	FF%%C ' ''GGGGAy112222  ' ' 'P)>PP1PPC$+A{B$?$?3%$GCMMM#&&&&&&&&'  W-.I2.I.I6SUVVV&#--33<<3D3DDS  7777737777< D D D D D D D DEEEs   4B
C$<CC$c                 <    |                      ||t                    S )z9Convert an iterable into a potentially generic frozenset.)r#  )r   	frozensetr   s      rO   r   z"BaseConverter._structure_frozenset  s     ""3"CCCrN   c                 F   t          |          s|j        t          t          fk    rt          |          S |j        \  t          u r;| j                                      fd|                                D             S t          u r;| j                                      fd|                                D             S | j                                      | j                                      fd|                                D             S )z2Convert a mapping into a potentially generic dict.c                 0    i | ]\  }}| |          S rM   rM   )r^   r   r   val_convval_types      rO   r  z1BaseConverter._structure_dict.<locals>.<dictcomp>-  s+    IIITQ88Ax00IIIrN   c                 0    i | ]\  }} |          |S rM   rM   )r^   r   r   key_convkey_types      rO   r  z1BaseConverter._structure_dict.<locals>.<dictcomp>0  s+    IIITQH--qIIIrN   c                 D    i | ]\  }} |           |          S rM   rM   )r^   r   r   r2  r3  r/  r0  s      rO   r  z1BaseConverter._structure_dict.<locals>.<dictcomp>4  sD       EIQHHQ))88Ax+@+@  rN   )r&   rc   r   dictr{   r   r   )r   r   r   r2  r3  r/  r0  s      @@@@rO   r   zBaseConverter._structure_dict%  s2   2;; 	"+#s3399!#Hh3/88BBIIIIISYY[[IIIIS/88BBIIIIISYY[[IIII/88BB/88BB      MPYY[[   rN   c                     |d S |j         }|d         t          u r|d         n|d         } | j                            |          ||          S )Nr   r   )rc   rg   r{   r   )r   r   unionunion_paramsothers        rO   r   z!BaseConverter._structure_optional8  sV    ;4~#/?h#>#>QLQRO3t#,,U33C???rN   c                 4    | j         |         } |||          S )zDeal with structuring a union.)rz   )r   r   r7  r   s       rO   r   zBaseConverter._structure_union@  s!    -e4wsE"""rN   tupc                     |t           t          fv rd}n|j        }|o|d         t          u }||r|d         t          u rt          |          S |r|d          j                                       j        rg }g }t          |          D ]s\  }}	 |	                     |                     &# t          $ rA}	d| d| }
t          |dg           |
gz   |	_        |	                    |	           Y d}	~	ld}	~	ww xY w|rt          d|||          t          |          S t          fd|D                       S t          |          }	 t          |          }||k    r|}n# t          $ r Y nw xY w j        rYg }g }t          t!          ||                    D ]\  }\  }}	  j                            |          |	                     ||                     C# t          $ rA}	d| d| }
t          |dg           |
gz   |	_        |	                    |	           Y d}	~	d}	~	ww xY wt          |          |k     rot          |          t          |          k     rd	nd
}t#          | d|d|          }	d| }
t          |dg           |
gz   |	_        |	                    |	           |rt          d|||          t          |          S t           fdt!          ||          D                       }t          |          |k     r;t          |          t          |          k     rd	nd
}t#          | d|d|          |S )z#Deal with structuring into a tuple.Nr   r  r  r  r  c              3   0   K   | ]} |          V  d S rT   rM   )r^   r_   convtup_types     rO   r`   z1BaseConverter._structure_tuple.<locals>.<genexpr>c  s/      <<1TT!X..<<<<<<rN   z
Not enoughzToo manyz values in z to structure as c                 ^    g | ])\  }} j                             |          ||          *S rM   r   )r^   r   r_   r   s      rO   r  z2BaseConverter._structure_tuple.<locals>.<listcomp>  sJ        Aq 9,55a88A>>  rN   )r   r   rc   Ellipsisr   r{   r   r}   	enumerater   r  r   r  r   rk   	TypeErrorr  
ValueError)r   r   r;  
tup_paramshas_ellipsisr!  r   r"  r_   r*  r   exp_lenlen_objr   problemr?  r@  s   `              @@rO   r   zBaseConverter._structure_tupleE  sN   5%.  JJJ!@jn&@,:a=C3G3G:: C	!!}H'00::D' =&s^^ + +EB+

448#4#45555$ + + +?S??2??(/;(C(Cse(Kc********+  14S44fc   Szz!<<<<<<<<<<< *ooG&c(( W$$%G	    
 ' $"+C
C,@,@"A"A + +JBA+#3<<Q??

441::....$ + + +?S??2??(/;(C(Cse(Kc********+ s88g%%.1#hhZ.H.HlljG$"NNsNNsNN C /..C$+A{B$?$?3%$GCMMM#&&& 14S44fc   Szz!   $'
C$8$8    s88g%%.1#hhZ.H.HlljG$"NNsNNsNN   
sB   B55
D ?7C;;D E, ,
E98E9.9G((
H327H..H3c                     | j         }t          |v rt          d |D                       }t          d |D                       st	          d|           t          | S )z<Fetch or try creating a disambiguation function for a union.c              3   ,   K   | ]}|t           u|V  d S rT   )rg   r]   s     rO   r`   z.BaseConverter._get_dis_func.<locals>.<genexpr>  s5          !8*;*;*;*;*;*;   rN   c              3   R   K   | ]"}t          t          |          p|          V  #d S rT   r\   r]   s     rO   r`   z.BaseConverter._get_dis_func.<locals>.<genexpr>  s5      @@q3z!}})**@@@@@@rN   zQOnly unions of attrs classes supported currently. Register a loads hook manually.r   )rc   rg   r   rb   r   r3   )r7  union_typess     rO   r   zBaseConverter._get_dis_func  s     n{""      &       K @@K@@@@@ 	/=   
 *;77rN   c                 *    |                                  S rT   )copy)r   r   s     rO   __deepcopy__zBaseConverter.__deepcopy__  s    yy{{rN   c                 <   |                      ||n| j        ||n'| j        | j        k    rt          j        nt          j        ||n| j        ||n| j                  }| j	        
                    |j	                   | j        
                    |j                   |S rT   )r   ry   rw   r   rD   rK   rL   r|   r}   rv   copy_tor{   )r   r~   r   r   r}   r   s         rO   rP  zBaseConverter.copy  s     nn(4LL$:L) N *d.KKK $++(1 (3 %$/".  )
 
" 	&&s'<===$$S%8999
rN   rT   )rQ   rt   )NNNN)GrG   rH   rI   rJ   	__slots__r5  rD   rK   r	   r   boolr   r   propertyr   r   r   r   r   rA   r   r   r   r   r
   r   r   r   r   r   r   staticmethodr   r   r   r   rB   r   r   r   r   r6   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   rQ  rP  rM   rN   rO   rt   rt   k   s       <<
I +/.A.I).$(QQ QQr3w'QQ ,QQ #'	QQ
 "QQ 
QQ QQ QQ QQf s C 3    
 
 3 
 
 
 X
DS D#8L DQU D D D D H"C5$;/H7?s
7KH	H H H HPSE4K(P 3%3%*!556P 
	P P P P AA%sDGna&78A	A A A A.F"DG9d?3F;CS$q'NTUDU;VF	F F F FNSE4K(N 3%3*c/!::;N 
	N N N N :S :d1g :! : : : :	C 	DcN 	 	 	 		S 	U38_ 	 	 	 	T c     1     \DHQK DHQK D D D D	
GAqDM 	
gadm 	
 	
 	
 	
Cc Cc C C C C ; ; ; ; ; \;
a _Q5G    %%	3Q.(47"33	4% % % %* S d1g #    \   \
 F F \F> > >U38_ $q' a    eIu,<&= c c    ,GCH,= 47 q    (8A; C DG    : ?BF FA;F$'F7;F	QF F F F4DA;D$'D		"D D D D71a4= c d1a4j    &@ @ @# # #
MC Md1g M! M M M M^ 8d 3 8 8 8 \8$   
 598<37.2 xC01 !!45 #+4.	
 &d^ 
     rN   rt   c                       e Zd ZdZdZeej        ddi i ddfdeg e	f         dede
de
d	eeef         d
eeef         de
de
f fdZdee         dee	e	gef         fdZd Zd Zdee         deegeee	f         f         fdZdee         deeee	f         e	gef         fdZ	 dde	de	defdZ	 dde	de	defdZ	 	 d de	de	deee	ee	         ge	f                  defdZde	dee         fdZde	dee         fdZ 	 	 	 	 	 	 	 	 d!deeg e	f                  dee         dee
         dee
         d	eeeef                  d
eeeef                  dee
         dee
         dd fdZ! xZ"S )"	ConverterzAA converter which generates specialized un/structuring functions.)omit_if_defaultforbid_extra_keystype_overrides_unstruct_collection_overrides_struct_copy_skip_unstruct_copy_skipFTr~   r   rZ  r[  r\  unstruct_collection_overridesr   r}   c	                     t                                          ||||           | _        | _        t	          |           _        d |                                D             }| _        |}	t          |	v rQt          |	vr*|	t                   |	t          <   |	t                   |	t          <   t          |	vr|	t                   |	t          <   t          |	v rt          |	vr|	t                   |	t          <   t          |	v r|	t                   |	t          <   t          |	v r<t          |	vr|	t                   |	t          <   t           |	vr|	t                   |	t           <   t          |	v rt"          |	vr|	t                   |	t"          <   t$          |	v rt&          |	vr|	t$                   |	t&          <   t&          |	v rt          |	vr|	t&                   |	t          <   t          |	v rt(          |	vr|	t                   |	t(          <   |t*          j        u r@                     t0           j                                        t0           j                                        t8           j                                        t<           j                                        t@           j!                                        tD           j#                                        tH           fd                                tJ           fd                                d  fd                                t8           j&                                        tD           j'                                        tP           j)                                        d  j*                    j+        ,                                 _-         j.        ,                                 _/        d S )N)r~   r   r   r}   c                 8    i | ]\  }}t          |          p||S rM   )r#   )r^   r   r   s      rO   r  z&Converter.__init__.<locals>.<dictcomp>  s6     )
 )
 )
&*aJqMMQ)
 )
 )
rN   c                 <                         | t                    S Nunstructure_to)gen_unstructure_iterabler(  r   r   s    rO   rW   z$Converter.__init__.<locals>.<lambda>1  s    t44R4LL rN   c                 <                         | t                    S rd  )rg  r,  rh  s    rO   rW   z$Converter.__init__.<locals>.<lambda>5  s    t44R	4RR rN   c                 $    t          |           d uS rT   r   r   s    rO   rW   z$Converter.__init__.<locals>.<lambda>8      &q))5 rN   c                 R    j                             t          |                     S rT   )rv   r   r"   r   s    rO   rW   z$Converter.__init__.<locals>.<lambda>9  s!    d,556Fq6I6IJJ rN   c                 $    t          |           d uS rT   r   r   s    rO   rW   z$Converter.__init__.<locals>.<lambda>?  rk  rN   )0superr   rZ  r[  r5  r\  r   r]  r   r   AbcMutableSetr   r(  r,  r   r   r   r   r   r   r   rD   rK   r   r$   gen_unstructure_attrs_fromdictr   gen_structure_attrs_fromdictr%   gen_unstructure_annotatedr+   gen_unstructure_hetero_tupler0   rg  r-   gen_unstructure_mappingr.   r(   gen_structure_annotatedgen_structure_mappingr'   gen_structure_counterget_structure_newtyper{   get_num_fnsr^  rv   r_  )r   r~   r   rZ  r[  r\  r`  r   r}   cor   s   `         rO   r   zConverter.__init__  s    	%)%= 3	 	 	
 	
 	
  /!2">22)
 )
.K.Q.Q.S.S)
 )
 )
% /L+ + ""r))')*;'<#$$&'8$9=!%R//-/0A-B)* r!!"}}-.3!R''56ByM r>>b((&(l?#BxL5	 b  2~~o.4 b==R''%'[>" R2~~n-4 2::b   h7088822 $"E   00 $"C   	..$8	
 	
 	
 	..T>	
 	
 	
 	..6	
 	
 	
 	..z4;WXXX..LLLL	
 	
 	
 	..RRRR	
 	
 	
 	..55JJJJ	
 	
 	
 	,,\4;WXXX,,Z9STTT,,Z9STTT,,55t7Q	
 	
 	

 "&!5!A!A!C!C#'#9#E#E#G#G   rN   r   rQ   c                 d    t          |          | j                                      fdS )Nc                      |           S rT   rM   )r   r   r  r   s     rO   rW   z1Converter.get_structure_newtype.<locals>.<lambda>I  s    GGAt,, rN   r  )r   r   r  r   s     @@rO   rx  zConverter.get_structure_newtypeF  s9    %%&//55,,,,,,rN   c                 H    |j         }| j                            |          }|S rT   )
__origin__rv   r   r   r   originhs       rO   rr  z#Converter.gen_unstructure_annotatedK  s$    "++F33rN   c                 H    |j         }| j                            |          }|S rT   )r~  r{   r   r  s       rO   ru  z!Converter.gen_structure_annotatedP  s$     ))&11rN   r   c                      t          |          }t          |p|          }t          |          r(t          d |D                       rt	          |            fd|D             }t          | fd j        i|}|S )Nc              3   J   K   | ]}t          |j        t                    V  d S rT   ro   r   r   r^   r   s     rO   r`   z;Converter.gen_unstructure_attrs_fromdict.<locals>.<genexpr>Z  .       J JQAFC!8!8 J J J J J JrN   c                 \    i | ](}|j         j        v |j        j        |j                  )S rM   r   r\  r   r^   r   r   s     rO   r  z<Converter.gen_unstructure_attrs_fromdict.<locals>.<dictcomp>]  A     
 
 
v,,, FD'/,,,rN   _cattrs_omit_if_default)r#   r!   r   rq   r   r<   rZ  )r   r   r  attribsattrib_overridesr  s   `     rO   rp  z(Converter.gen_unstructure_attrs_fromdictU  s     B2&&R== 	S J J' J J JJJ 	"
 
 
 

 
 
 %
 
.2.B
FV
 
 rN   c                 .    t          t          |          rt          |          n|          }t          |          r(t	          d |D                       rt          |            fd|D             }t          | f j         j         j	        d|}|S )Nc              3   J   K   | ]}t          |j        t                    V  d S rT   r  r  s     rO   r`   z9Converter.gen_structure_attrs_fromdict.<locals>.<genexpr>l  r  rN   c                 \    i | ](}|j         j        v |j        j        |j                  )S rM   r  r  s     rO   r  z:Converter.gen_structure_attrs_fromdict.<locals>.<dictcomp>o  r  rN   )_cattrs_forbid_extra_keysr   _cattrs_detailed_validation)
r!   r)   r#   r   rq   r   r;   r[  r|   r}   )r   r   r  r  r  s   `    rO   rq  z&Converter.gen_structure_attrs_fromdicth  s     :b>>ABrBBR== 	S J J' J J JJJ 	"
 
 
 

 
 

 #
 '+&<-1-K(,(@
 
 
 
 rN   Nrf  c                     | j                             t          |          p||pt                    }t	          || |          }| j                            ||fgd           |S Nre  Tdirect)r]  getr#   r   r>   rv   r   r   r   rf  r  s       rO   rg  z"Converter.gen_unstructure_iterable  sn     <@@rNN b."8D
 
 )T.QQQ002q'40HHHrN   c                     | j                             t          |          p||pt                    }t	          || |          }| j                            ||fgd           |S r  )r]  r  r#   r   r=   rv   r   r  s       rO   rs  z&Converter.gen_unstructure_hetero_tuple  sn     <@@rNN b."8D
 
 -RnUUU002q'40HHHrN   key_handlerc                     | j                             t          |          p||pt                    }t	          || ||          }| j                            ||fgd           |S )N)rf  r  Tr  )r]  r  r#   r5  r@   rv   r   )r   r   rf  r  r  s        rO   rt  z!Converter.gen_unstructure_mapping  sy     <@@rNN b."8D
 
 (^
 
 
 	002q'40HHHrN   c                     t          || t          t          | j                  }| j                            ||fgd           |S )N)r#  r0  r}   Tr  )r?   r   r   r}   r{   r   r   r   r  s      rO   rw  zConverter.gen_structure_counter  sQ    %  $ 8
 
 
 	..Qy.FFFrN   c                 r    t          || | j                  }| j                            ||fgd           |S )N)r}   Tr  )r?   r}   r{   r   r  s      rO   rv  zConverter.gen_structure_mapping  sI    %$*B
 
 
 	..Qy.FFFrN   c	           
         |                      ||n| j        ||n'| j        | j        k    rt          j        nt          j        ||n| j        ||n| j        ||n| j	        ||n| j
        ||n| j        ||n| j                  }	| j                            |	j        | j                   | j                            |	j        | j                   |	S )N)skip)r   ry   rw   r   rD   rK   rL   rZ  r[  r\  r]  r|   r}   rv   rS  r_  r{   r^  )
r   r~   r   rZ  r[  r\  r`  r   r}   r   s
             rO   rP  zConverter.copy  s    nn(4LL$:L) N *d.KKK $++(1.:OO@T , ',8NNd>Q,8 *)4'3 %$/".  )-
 
2 	&&!(@ 	' 	
 	
 	
 	$$S%8t?U$VVV
rN   rT   )NN)NNNNNNNN)#rG   rH   rI   rJ   rT  r5  rD   rK   r	   r   rU  r   r   r5   r   rA   rx  rr  ru  r
   r   rp  rq  r8   rg  r7   rs  r   r:   rt  r9   rw  rv  rP  __classcell__r   s   @rO   rY  rY    s       KKI +/.A.I %"';=AC).$(pH pHr3w'pH ,pH 	pH
  pH  &7 78pH (/tX~'>pH #'pH "pH pH pH pH pH pHd-$q' -hSz1}6M - - - -
  
  
q'	1#tCH~%	&   &q'	738$c*A-	.   0 .2 '*	    .2 '*	!    #EI	   hXc]';S'@AB	
 
   	 	0B10E 	 	 	 	 0B10E     598<*.,0EIKO37.2) )xC01) !!45) "$	)
 $D>) !/@)@!AB) (0h0G'H) #+4.) &d^) 
) ) ) ) ) ) ) )rN   rY  )Ycollectionsr   collections.abcr   ro  dataclassesr   enumr   	functoolsr   typingr   r	   r
   r   r   r   r   r   r   r   r   attrr   r   r   r   cattrs.errorsr   r   _compatr   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   disambiguatorsr3   r   r4   genr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   r   rg   rA   rB   rD   rU  rY   rd   rh   rl   rr   rt   rY  GenConverterrM   rN   rO   <module>r     s         7 7 7 7 7 7                                                  ! ! ! ! ! !       P P P P P P P P                                                         : 7 6 6 6 6 6 + + + + + +                            4::GCLLGCLL    $   ,4 ,HdVT\2 , , , ,
U U U U U U     VT Vd V V V VRT Rd R R R RZ	 Z	 Z	 Z	 Z	 Z	 Z	 Z	zU U U U U U U Up rN   