
    uYf                     |   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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!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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< ddl=m>Z>m?Z? ddl@mAZAmBZBmCZCmDZD ddlEmFZFmGZGmHZH ddlImJZJmKZK ddlLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZX ddlYmSZZ ddlYmTZ[ g dZ\ e]d      Z^ ed      Z_ ed      Z` G d de	      Zadedeegebf   fdZcdedebfdZddedebfdZe G d d       Zf G d! d"ef      ZgegZhy)#    )Counterdeque)
MutableSet)Field)Enum)	lru_cache)Path)AnyCallableDequeDictIterableListOptionalTupleTypeTypeVarUnion)	Attribute)has)resolve_types   )FrozenSetSubscriptableMappingMutableMappingMutableSequenceOriginAbstractSetOriginMutableSetSequenceSet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_setis_protocolis_sequenceis_tupleis_typeddictis_union_type)create_default_dis_funcis_supported_union)HookFactoryMultiStrategyDispatchStructureHookUnstructureHook)IterableValidationErrorIterableValidationNoteStructureHandlerNotFoundError)identityraise_error)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_fn)rG   )rH   )UnstructureStrategyBaseConverter	ConverterGenConverterNTVc                       e Zd ZdZdZdZy)rM   z)`attrs` classes unstructuring strategies.asdictastupleN)__name__
__module____qualname____doc__AS_DICTAS_TUPLE     Q/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/cattrs/converters.pyrM   rM   Y   s    3GHr]   rM   typreturnc                       fdS )z
a shortcutc                     t        |       S N)
issubclass)clsr_   s    r^   <lambda>z_subclass.<locals>.<lambda>b   s    z#s+ r]   r\   r_   s   `r^   	_subclassrh   `   s	    ++r]   c                 t    t        |       xr, t        | j                  v xr t        | j                        dk(  S )N   )r5   NoneType__args__lenrg   s    r^   is_optionalrn   e   s/    U(cll":Us3<<?PTU?UUr]   c                 T    t        |       xr t        d | j                  D              S )Nc              3   <   K   | ]  }t        |t                y wrc   )
isinstancer   ).0vals     r^   	<genexpr>z.is_literal_containing_enums.<locals>.<genexpr>j   s     "QS:c4#8"Qs   )r.   anyrl   rg   s    r^   is_literal_containing_enumsrv   i   s     c?Qs"QCLL"QQQr]   c                   d   e Zd ZdZdZeej                  ddd d fdeg e	f   ded	e
d
e
dee   dee   ddfdZdEde	de	de	fdZedefd       Zde	deddfdZdee	ge
f   deddfdZdee	ge
f   dee   ddfdZde	deddfdZdeee   ge
f   deddfdZdee	ge
f   dee   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!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'dee   de(e   fd*Z)	 dFde	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/d0 Z0d1 Z1dee	d"f   dee   defd2Z2d3e3e4e5f   d4e	de	fd5Z6de$ee	f   dee   defd6Z7de8e   de	de9e   fd7Z:de8e   de	de;e   fd8Z<e=fde8e   de	d9e>de?e   fd:Z@de8e   de	deAe   fd;ZBde$ee%f   de	deee%f   fd<ZCd= ZDd> ZEde	d?ee   defd@ZFe,dFdAe	d+e
dee	gef   fdB       ZGdGdCZH	 	 	 	 dHde*eg e	f      de*e   d	e*e
   d
e*e
   dd f
dDZIy)IrN   z2Converts 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_validation_struct_copy_skip_unstruct_copy_skipFTc                     t         S rc   r?   _s    r^   rf   zBaseConverter.<lambda>       x r]   c                     t         S rc   r@   r   s    r^   rf   zBaseConverter.<lambda>       ; r]   dict_factoryunstruct_stratprefer_attrib_convertersr   unstructure_fallback_factorystructure_fallback_factoryr`   Nc                     t        |      }| _        | _        |t         j                  u r# j                   _         j                   _        n" j                   _         j                   _         t                j                         _        t        |       _         j                  j                  t         t"        ft$        t"        ft&        t$        fg        j                  j)                  t*         fdfd  fddft,         j.                  ft0         j2                  ft4         j2                  ft6         j2                  ft9        t:               j<                  ft>         j
                  ft@         jB                  fg	       t        |       _"         jD                  j)                  d d ftF         jH                  dfd  jJ                  fd  jL                  dftN         jP                  ftR         jT                  ft0         jV                  ftX         jZ                  ft4         j\                  ft6         j^                  ft`         jb                  ft,         jd                  ftf         jh                  df fd	 jj                  ftl         jn                  ft>         j                  fg        jD                  j                  t$         jp                  ft          jp                  ftr         jp                  ftt         jp                  ft:         jp                  ft&         jp                  fg       | _;        i  _<         j                  j{                          _>         jD                  j{                          _?        y
)  
        :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*
        c                 >    j                  | | j                        S )N)unstructure_as)unstructure	__class__)oselfs    r^   rf   z(BaseConverter.__init__.<locals>.<lambda>   s    d..q.M r]   c                     t        |       d uS rc   r"   ts    r^   rf   z(BaseConverter.__init__.<locals>.<lambda>       nQ/t; r]   c                 L    j                   j                  t        |             S rc   )ry   dispatchr"   r   r   s    r^   rf   z(BaseConverter.__init__.<locals>.<lambda>   s    d44==nQ>OP r]   Tc                 2    | t         u xs | t        u xs | d u S rc   )r
   r   )cls    r^   rf   z(BaseConverter.__init__.<locals>.<lambda>   s    B#IExE2: r]   c                     | S rc   r\   )vr   s     r^   rf   z(BaseConverter.__init__.<locals>.<lambda>   s    TU r]   c                     t        |       d uS rc   r#   r   s    r^   rf   z(BaseConverter.__init__.<locals>.<lambda>   s    +A.d: r]   c                     t        |       d uS rc   r   r   s    r^   rf   z(BaseConverter.__init__.<locals>.<lambda>   r   r]   c                 :    t        |       xr | j                  v S rc   )r5   r}   r   s    r^   rf   z(BaseConverter.__init__.<locals>.<lambda>   s    mA.S18S8S3S r]   N)@rM   r   r   rZ   unstructure_attrs_asdictrz   structure_attrs_fromdictr{   unstructure_attrs_astuplestructure_attrs_fromtupler   _get_dis_funcrx   r9   ry   register_cls_listbytesr?   strr	   register_func_listr1   r/   _unstructure_mappingr2   _unstructure_seqr0   r*   rh   r   _unstructure_enumr   r5   _unstructure_unionr~   r,   _gen_structure_generic_structure_newtype_structure_final_factoryr.   _structure_simple_literalrv   _structure_enum_literal_structure_listr)   _structure_deque_structure_set_structure_frozensetr3   _structure_tuple_structure_dictr7   _gen_attrs_union_structure_structure_unionrn   _structure_optional_structure_callintfloatr|   r}   get_num_fnsr   r   )r   r   r   r   r   r   r   s   `      r^   __init__zBaseConverter.__init__~   s   ( -^<)A&#6  0888&*&C&CD#$($A$AD!&*&D&DD#$($B$BD!*y{4+=+=>!67S!T00Xh$=	
 	11  M
 <P
 T667d334!6!67t4454$"8"89d--. 7 78!	
0  55OP//E~V!4#>#>E:D<S<ST;11
 T;;<,d.J.JKd2234001!4!45t8894001T112#T%D%DdKS)) d667d++,/	
8 	..d**+,,-d**+,,-t++,t++,		
 * OQ##'#9#9#E#E#G !%!5!5!A!A!Cr]   objr   c                 r     | j                   j                  ||j                        |      S |      |      S rc   ry   r   r   )r   r   r   s      r^   r   zBaseConverter.unstructure   sH    
t%%..+3CMM

 	9G

 	r]   c                 t    | j                   | j                  k(  rt        j                  S t        j                  S )z3The default way of unstructuring ``attrs`` classes.)rz   r   rM   rZ   r[   )r   s    r^   r   zBaseConverter.unstruct_strat   s8    
 &&$*G*GG  ''	
 %--	
r]   re   funcc                 "   t              rt               t              r"| j                  j	                  fd|fg       yt              "| j                  j	                  fd|fg       y| j                  j                  |fg       y)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 rc   r\   r   re   s    r^   rf   z9BaseConverter.register_unstructure_hook.<locals>.<lambda>  s    !s( r]   Nc                     | u S rc   r\   r   s    r^   rf   z9BaseConverter.register_unstructure_hook.<locals>.<lambda>  s    !s( r]   )	attrs_hasr   r5   ry   r   r#   r   )r   re   r   s    ` r^   register_unstructure_hookz'BaseConverter.register_unstructure_hook   s{     S>#""558JD7Q6RSc".""558JD7Q6RS""44sDk]Cr]   
check_funcc                 @    | j                   j                  ||fg       yzyRegister a class-to-primitive converter function for a class, using
        a function to check if it's a match.
        Nry   r   r   r   r   s      r^   register_unstructure_hook_funcz,BaseConverter.register_unstructure_hook_func  s      	11J3E2FGr]   	predicatefactoryc                 B    | j                   j                  ||dfg       y)a]  
        Register a hook factory for a given predicate.

        :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.
        TNr   r   r   r   s      r^   !register_unstructure_hook_factoryz/BaseConverter.register_unstructure_hook_factory  s"     	11Iw3M2NOr]   r   c                 2   t              rt               t              r*|| j                  <   | j                  j                          yt              "| j                  j                  fd|fg       y| j                  j                  |fg       y)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 rc   r\   )r   r   s    r^   rf   z7BaseConverter.register_structure_hook.<locals>.<lambda>1  s    R r]   )	r   r   r5   r}   r~   clear_cacher#   r   r   )r   r   r   s    ` r^   register_structure_hookz%BaseConverter.register_structure_hook   s     R=".2D''+  ,,.b!-  336G5N4OP  22RJ<@r]   c                 @    | j                   j                  ||fg       yr   r~   r   r   s      r^   register_structure_hook_funcz*BaseConverter.register_structure_hook_func5  s      	//*d1C0DEr]   c                 B    | j                   j                  ||dfg       y)aX  
        Register a hook factory for a given predicate.

        :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.
        TNr   r   s      r^   register_structure_hook_factoryz-BaseConverter.register_structure_hook_factory=  s"     	//)Wd1K0LMr]   c                 F     | j                   j                  |      ||      S )z?Convert unstructured Python data structures to structured data.)r~   r   r   r   r   s      r^   	structurezBaseConverter.structureJ  s"    0t##,,R0b99r]   c                    t        |j                        }| j                  j                  }| j	                         }|D ]C  }|j
                  }t        ||      }  ||j                  xs |j                        |      ||<   E |S )z9Our version of `attrs.asdict`, so we can call back to us.)r!   r   ry   r   r|   namegetattrtype)r   r   attrsr   rvar   r   s           r^   r   z&BaseConverter.unstructure_attrs_asdictO  s|    s}}%))22! 	:A66DT"A6x 5!++6q9BtH	: 	r]   .c                    t        |j                        }| j                  j                  }g }|D ]O  }|j                  }t        ||      }|j                    ||j                  xs |j                        |             Q t        |      S )z:Our version of `attrs.astuple`, so we can call back to us.)	r!   r   ry   r   r   r   appendr   tuple)r   r   r   r   resr   r   r   s           r^   r   z'BaseConverter.unstructure_attrs_astupleZ  s|    s}}%))22 	;A66DT"AJJ6x 5!++6q9:	; Szr]   c                     |j                   S )zConvert an enum to its value.)valuer   r   s     r^   r   zBaseConverter._unstructure_enume  s    yyr]   seqc                 d    | j                   j                  |j                  fd|D              S )z,Convert a sequence to primitive equivalents.c              3   N   K   | ]  }  |j                         |        y wrc   r   )rr   er   s     r^   rt   z1BaseConverter._unstructure_seq.<locals>.<genexpr>m  s"     C!2Xakk215Cs   "%r   )r   r   r   s     @r^   r   zBaseConverter._unstructure_seqi  s+     ))22}}CsCCCr]   mappingc                     | j                   j                  |j                  fd|j                         D              S )z;Convert a mapping of attr classes to primitive equivalents.c              3      K   | ]7  \  }}  |j                         |        |j                         |      f 9 y wrc   r   )rr   kr   r   s      r^   rt   z5BaseConverter._unstructure_mapping.<locals>.<genexpr>u  sC      !
1 #Xakk"1%'<x'<Q'?@!
s   =A )ry   r   r   items)r   r   r   s     @r^   r   z"BaseConverter._unstructure_mappingo  s<    
 ))22   !
!
 
 	
r]   c                 X     | j                   j                  |j                        |      S )zh
        Unstructure an object as a union.

        By default, just unstructures the instance.
        r   r   s     r^   r   z BaseConverter._unstructure_union}  s&     >t%%..s}}=cBBr]   c                 2    t        || | j                        S )z2Create and return a hook for structuring generics.) _cattrs_prefer_attrib_converters)rG   r   r   r   s     r^   r   z$BaseConverter._gen_structure_generic  s    %t7U7U
 	
r]   use_literalsc                 z      j                  ||      t        |j                  v }|rd|f fd}|S  fd}|S )z
        Generate a structuring function for a union of attrs classes (and maybe None).

        :param use_literals: Whether to consider literal fields.
        )r  r`   c                 :    | y j                  |  |             S rc   r   r   r   dis_fnr   s     r^   structure_attrs_unionzGBaseConverter._gen_attrs_union_structure.<locals>.structure_attrs_union  s     ;~~c6#;77r]   c                 4    j                  |  |             S rc   r	  r
  s     r^   r  zGBaseConverter._gen_attrs_union_structure.<locals>.structure_attrs_union  s    ~~c6#;77r]   )r   rk   rl   )r   r   r  has_noner  r  s   `    @r^   r   z(BaseConverter._gen_attrs_union_structure  sL     ##B\#Br{{*8 8 %$8 %$r]   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.
        r\   )r   r   s     r^   r   zBaseConverter._structure_call  s     #wr]   c                 B    | |j                   vrt        |  d|       | S Nz not in literal )rl   	Exception)rs   r   s     r^   r   z'BaseConverter._structure_simple_literal  s*    dmm#se#3D6:;;
r]   c                     |j                   D ci c]!  }t        |t              r|j                  n||# }}	 ||    S c c}w # t        $ r t        |  d|       d w xY wr  )rl   rq   r   r   KeyErrorr  )rs   r   xvalss       r^   r   z%BaseConverter._structure_enum_literal  so    DHMMRqJq$/Q:RR	F9 S  	Fse#3D6:;E	Fs   &=A Ac                 \    t        |      } | j                  j                  |      ||      S rc   r#   r~   r   )r   rs   r   bases       r^   r   z BaseConverter._structure_newtype  s,    %2t##,,T23==r]   c                      t        |       j                  j                         j                  k(  r fdS fdS )Nc                 (    j                  |       S rc   )r   )r   r   r  r   s     r^   rf   z8BaseConverter._structure_final_factory.<locals>.<lambda>  s     4 4Q = r]   c                      |       S rc   r\   )r   r   r  r   s     r^   rf   z8BaseConverter._structure_final_factory.<locals>.<lambda>  s    C4L r]   )r"   r~   r   r   )r   r   r  r   s   ` @@r^   r   z&BaseConverter._structure_final_factory  s=    d#""++D1$&&&==((r]   c                     g }t        t        |      |      D ](  \  }}| j                  ||      }|j                  |       *  || S )z,Load an attrs class from a sequence (tuple).)zipr!   _structure_attributer   )r   r   r   conv_objr   r   	converteds          r^   r   z'BaseConverter.structure_attrs_fromtuple  sO    F2J, 	'HAu11!U;IOOI&	'
 8}r]   r   r   c                     |j                   }t        |dd      }| j                  r|r|S ||S 	  | j                  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   type_attrib_converters        r^   r  z"BaseConverter._structure_attribute  sv    "1k48)).>
 L=L	74''007uEE, 			s   !A A" A"c                     i }t        |      D ]<  }	 ||j                     }| j                  ||      |t	        |d|j                        <   >  |di |S # t        $ r Y Rw xY w)z1Instantiate an attrs class from a mapping (dict).aliasr\   )r!   r   r  r  r   )r   r   r   r   r   rs   s         r^   r   z&BaseConverter.structure_attrs_fromdict  sy      	VA!&&k
 594M4MaQT4UHWQ01	V ~H~  s   A	A! A!c                 4   t        |      s|j                  d   t        u rt        |      }|S |j                  d   }| j                  j                  |      }| j                  r?g }g }d}|D ]   }	 |j                   |||             |dz  }" |rt        d|||      |S |D cg c]  } |||       }}|S # t        $ rD}t        d| d| ||      }	g t        |dg       |	|_        |j                  |       Y d}~{d}~ww xY w# |dz  }w xY wc c}w )z2Convert an iterable to a potentially generic list.r   Structuring 	 @ index 	__notes__Nr   While structuring )r'   rl   r
   listr~   r   r   r   r  r=   r   r+  r<   )
r   r   r   r   	elem_typehandlererrorsixr   msgs
             r^   r   zBaseConverter._structure_list  sK   2;"++a.C/s)C2 
/ AI**33I>G'' 
 A	 

71i#89 a
  1,RF3VR 
 
 7::wq),::
 % )4*2$it<b) 'J;(C&IS&Ia(() a ;s0   0B;'D;	D:D>DDDDc                 J  	 t        |      s|j                  d   t        u rt        d |D              }|S |j                  d   | j                  j                        	| j                  rGg }t               }d}|D ]   }	 |j                   	|             |dz  }" |rt        d|||      |S t        	fd	|D              }|S # t        $ rD}t        d| d| |      }g t        |dg       ||_        |j                  |       Y d}~zd}~ww xY w# |dz  }w xY w)
z3Convert an iterable to a potentially generic deque.r   c              3       K   | ]  }|  y wrc   r\   rr   r   s     r^   rt   z1BaseConverter._structure_deque.<locals>.<genexpr>  s     'a's   r)  r*  r+  Nr   r,  c              3   0   K   | ]  } |        y wrc   r\   )rr   r   r.  r/  s     r^   rt   z1BaseConverter._structure_deque.<locals>.<genexpr>5  s     ?aGAy1?   )r'   rl   r
   r   r~   r   r   r   r  r=   r   r+  r<   )
r   r   r   r   r0  r1  r   r2  r.  r/  s
           @@r^   r   zBaseConverter._structure_deque  sG   2;"++a.C/'3''C2 
/ AI**33I>G''g 
 A	 

71i#89 a
  1,RF3VR 
 
 ?3??
 % )4*2$it<b) 'J;(C&IS&Ia(() as*   C	D:DDDDD"structure_toc           	         t        |      s|j                  d   t        u r ||      S |j                  d   }| j                  j	                  |      }| j
                  rWg }t               }d}|D ]   }		 |j                   ||	|             |dz  }" |rt        d|||      |t        u r|S  ||      S |t        u r|D 	ch c]  }	 ||	|       c}	S  ||D 	cg c]  }	 ||	|       c}	      S # t        $ rN}
t        d|j                   d|	||      }g t        |
dg       ||
_        |j                  |
       Y d}
~
d}
~
ww xY w# |dz  }w xY wc c}	w c c}	w )z3Convert an iterable into a potentially generic set.r   r)  z @ element r+  Nr   r,  )r'   rl   r
   r~   r   r   setaddr  r=   rV   r   r+  r   r<   )r   r   r   r8  r.  r/  r0  r   r1  r   excr2  s               r^   r   zBaseConverter._structure_set8  s}    2;"++a.C/$$KKN	&&//	:##F%CB GGGAy12 !GB -0B2&.I6SUVV&#-3D<3DD3367aGAy)77C@qWQ	2@AA ! '0&|'<'<&=[N!C
 %Jgc;&C$IS$ICMMM#&&' !GB
 8@s7   3C2EE2	E	;AE?EE		EEc                 2    | j                  ||t              S )z9Convert an iterable into a potentially generic frozenset.)r8  )r   	frozensetr   s      r^   r   z"BaseConverter._structure_frozensetX  s     ""3"CCr]   c           	         t        |      s|j                  t        t        fk(  rt        |      S |j                  \  }}|t        u rF| j                  j                  |      }|j                         D ci c]  \  }}| |||       c}}S |t        u rF| j                  j                  |      }|j                         D ci c]  \  }} |||      | c}}S | j                  j                  |      }| j                  j                  |      }|j                         D ci c]  \  }} |||       |||       c}}S c c}}w c c}}w c c}}w )z2Convert a mapping into a potentially generic dict.)r'   rl   r
   dictr~   r   r  )	r   r   r   key_typeval_typeval_convr   r   key_convs	            r^   r   zBaseConverter._structure_dict^  s$   2;"++#s39[[(s?++44X>H9<EAAx8,,EEs?++44X>H9<EAHQ)1,EE''00:''00:ILUAH%x8'<<UU F F Vs   5EE	$Ec                     |y |j                   }|d   t        u r|d   n|d   } | j                  j                  |      ||      S )Nr   r   )rl   rk   r~   r   )r   r   unionunion_paramsothers        r^   r   z!BaseConverter._structure_optionalm  sN    ;~~#/?h#>QLQRO3t##,,U3C??r]   c                 2    | j                   |   } |||      S )zDeal with structuring a union.)r}   )r   r   rF  r/  s       r^   r   zBaseConverter._structure_unionu  s    --e4sE""r]   tupc           
      F   |t         t        fv rdn|j                  }|xr |d   t        u }||r|d   t        u rt        |      S |r|d   | j
                  j                        | j                  rHg }g }d}|D ]   }	 |j                   |             |dz  }" |rt        d|||      t        |      S t        fd	|D              S t        |      }	 t        |      }||kD  r|}	 | j                  rg }g }t!        t#        ||            D ]<  \  }\  }}	 | j
                  j                  |      |j                   ||             > t        |      |k  rZt        |      t        |      k  rd
nd}t%        | d|d|      }	d| }
g t        |	dg       |
|	_        |j                  |	       |rt        d|||      t        |      S t        t#        ||      D cg c]'  \  }} | j
                  j                  |      ||      ) c}}      }t        |      |k  r.t        |      t        |      k  rd
nd}t%        | d|d|      |S # t        $ rE}	t        d| d| |      }
g t        |	dg       |
|	_        |j                  |	       Y d}	~	d}	~	ww xY w# |dz  }w xY w# t        $ r Y w xY w# t        $ rE}	t        d| d| ||      }
g t        |	dg       |
|	_        |j                  |	       Y d}	~	d}	~	ww xY wc c}}w )z#Deal with structuring into a tuple.Nr   r)  r*  r+  r   r,  c              3   0   K   | ]  } |        y wrc   r\   )rr   r   convtup_types     r^   rt   z1BaseConverter._structure_tuple.<locals>.<genexpr>  s     8qa*8r7  z
Not enoughzToo manyz values in z to structure as )r   r   rl   Ellipsisr
   r~   r   r   r   r  r=   r   r+  r<   rm   	TypeError	enumerater  
ValueError)r   r   rJ  
tup_paramshas_ellipsisr0  r   r1  r   r<  r2  exp_lenlen_objr   problemrN  rO  s                  @@r^   r   zBaseConverter._structure_tuplez  sv    UEN2T
!@jn&@,:a=C3G:!!}H''00:D'' 
 A	 

48#45 a
  1,SG4fc  Sz!8C888 j/	"#hG  !##FC'J(<= 	'
FQ'//88;DJJtAqz*	' 3x'!*-c(S_*D,* G9Kw>OPSw!WX$SE* E'#{B"? E Ec"-0B3'.JFTWXX:@CJPS@TU1-T!!**1-a3U
 s8g&)#hZ&@ljGyC7:KC7STT
k % +4*3%y=r8 )N'#{B*G(M(Mc**+ a  		 ! '0&se9RD92qC %Jgc;&C$IS$ICMMM#&&'" VsZ   I!J< !3K/,L
!	J/*:J*$J2*J//J22J9<	K	K		L:LLrF  c                     | j                   }t        |v rt        d |D              }t        d |D              st	        d|       t        |d|iS )z<Fetch or try creating a disambiguation function for a union.c              3   2   K   | ]  }|t         us|  y wrc   )rk   r5  s     r^   rt   z.BaseConverter._get_dis_func.<locals>.<genexpr>  s       !8*; s   c              3   L   K   | ]  }t        t        |      xs |        y wrc   )r   r$   r5  s     r^   rt   z.BaseConverter._get_dis_func.<locals>.<genexpr>  s     @q3z!})*@s   "$zQOnly unions of attrs classes supported currently. Register a loads hook manually.)r$  r  )rl   rk   r   allr>   r6   )rF  r  union_typess      r^   r   zBaseConverter._get_dis_func  se     nn{"    &  K @K@@/=  'O,OOr]   c                 "    | j                         S rc   )copy)r   r   s     r^   __deepcopy__zBaseConverter.__deepcopy__  s    yy{r]   c                    | j                  ||n| j                  ||n8| j                  | j                  k(  rt        j
                  nt        j                  ||n| j                  ||n| j                        }| j                  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.
        )r   r|   rz   r   rM   rZ   r[   r   r   ry   copy_tor   r~   r   )r   r   r   r   r   r   s         r^   r_  zBaseConverter.copy  s     nn(4L$:L:L)  **d.K.KK $++(11 (3 %//".  ))
" 	&&s'<'<d>V>VW$$S%8%8$:P:PQ
r]   rc   )T)r`   rN   )NNNN)JrV   rW   rX   rY   	__slots__r@  rM   rZ   r   r
   boolr8   r;   r:   r   r   propertyr   r   r   r   r   r   rQ   r   r   r   r   r   r   r   r   r   r   r   r   r   rR   r   r   rB   r   r   r   staticmethodr   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^   rN   rN   m   sM   <I  +/.A.I.I).$(EWAVmDr3w'mD ,mD #'	mD
 "mD '2/&BmD %0$>mD 
mD^s C 3 
 
 3 
 
DS D DD D H"C5$;/H7FH	HP!3%+.P9D_9UP	PA# A] At A*F"DG9d?3F;HF	FN!3%+.N9D]9SN	N:S :d1g :! :
	C 	DcN 		S 	U38_ 	T c DHQK DHQK D	
GAqDM 	
gadm 	
Cc Cc C
a 
_Q5G 
 -1%%%)%	3Q.(47"33	4%2 S d1g #    
 F F>)U38_ $q' a eIu,<&= c c ,GCH,= 47 q  8A; C DG <HQK S U1X > ?BBA;B$'B7;B	QB@DA;D$'D		"DV71a4= Vc Vd1a4j V@#
GC Gd1g G! GR PS P P#PT@U P P*
 598<37.2 xC01  !!45  #+4.	 
 &d^  
 r]   rN   c                       e Zd ZdZdZeej                  ddi i dd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
dee   dee   f fdZdee   dee	e	gef   fdZd ZdefdZde	deegef   fdZdee   deegeee	f   f   fdZdee   deege	f   fdZde	deege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 )(rO   zAA converter which generates specialized un/structuring functions.)omit_if_defaultforbid_extra_keystype_overrides_unstruct_collection_overridesFTc                     t         S rc   r   r   s    r^   rf   zConverter.<lambda>  r   r]   c                     t         S rc   r   r   s    r^   rf   zConverter.<lambda>  r   r]   r   r   ri  rj  rk  unstruct_collection_overridesr   r   r   r   c                     t            |||||	|
       | _        | _        t	        |       _        |j                         D ci c]  \  }}t        |      xs || }}}| _        |}t        |v r@t        |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 r0t         |vr|t           |t         <   t"        |vr|t           |t"        <   t         |v r0t$        |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.        j0                  u r@ j3                  t4         j6                          j9                  t4         j:                          j3                  t<         j>                          j3                  t@         jB                          j3                  tD         jF                          j3                  tH         jJ                          j3                  tL         fd        j3                  tN         fd        j3                  tP         jR                          j3                  tT         jV                          j3                  d  fd        j9                  t<         jX                          j9                  tH         jZ                          j9                  t\         j^                          j9                  tT         j`                          j9                  d  jb                          jd                  jg                          _4         jj                  jg                          _6        yc c}}w )r   )r   r   r   r   r   r   c                 2    j                  | t              S Nunstructure_to)gen_unstructure_iterabler:  r   r   s    r^   rf   z$Converter.__init__.<locals>.<lambda>t  s    t44R4L r]   c                 2    j                  | t              S rr  )ru  r>  rv  s    r^   rf   z$Converter.__init__.<locals>.<lambda>x  s    t44R	4R r]   c                     t        |       d uS rc   r   r   s    r^   rf   z$Converter.__init__.<locals>.<lambda>      &q)5 r]   c                 L    j                   j                  t        |             S rc   )ry   r   r#   r   s    r^   rf   z$Converter.__init__.<locals>.<lambda>  s    d,,556Fq6IJ r]   c                     t        |       d uS rc   r   r   s    r^   rf   z$Converter.__init__.<locals>.<lambda>  ry  r]   N)7superr   ri  rj  r@  rk  r  r$   rl  r   r   AbcMutableSetr   r:  r>  r   r   r   r-  r   r   r   r   rM   rZ   r   r%   gen_unstructure_attrs_fromdictr   gen_structure_attrs_fromdictr&   gen_unstructure_annotatedr-   gen_unstructure_hetero_tupler2   ru  r/   gen_unstructure_mappingr0   r*   rn   gen_unstructure_optionalr4   gen_unstructure_typeddictgen_structure_annotatedgen_structure_mappingr(   gen_structure_countergen_structure_typeddictget_structure_newtyper~   r   r   ry   r   )r   r   r   ri  rj  rk  ro  r   r   r   r   r   r   cor   s   `             r^   r   zConverter.__init__	  s   0 	%)%= 3)E'A 	 	
  /!2">2 /L.Q.Q.S)
&*aJqMQ!)
% )
 /L+ + "r)')*;'<#$$&'8$9=!%R/-/0A-B)* r!cm)*BsG!R'56ByM r>b(&(l?#BxL5	 b 2~o.4B/5	 b=^25!#GB~ RDN.)BtH 2:'+T(BwK088822 $"E"E 00 $"C"C 	..$88	
 	..T>>	
 	..66	
 	..z4;W;WX..L	
 	..R	
 	..66	
 	..$88	
 	..5J	

 	,,\4;W;WX,,Z9S9ST,,Z9S9ST,,\4;W;WX,,5t7Q7Q	

 "&!5!5!A!A!C#'#9#9#E#E#G E)
s   	O5r   r`   c                 ^    t        |      | j                  j                        fdS )Nc                      |       S rc   r\   )r   r   r  r/  s     r^   rf   z1Converter.get_structure_newtype.<locals>.<lambda>  s    GAt, r]   r  )r   r   r  r/  s     @@r^   r  zConverter.get_structure_newtype  s)    %&&//5,,r]   c                 P    |j                   }| j                  j                  |      S rc   )
__origin__ry   r   )r   r   origins      r^   r  z#Converter.gen_unstructure_annotated  s"    %%..v66r]   c                 `    |j                   | j                  j                        fdS )z#A hook factory for annotated types.c                      |       S rc   r\   )r   r   hookr  s     r^   rf   z3Converter.gen_structure_annotated.<locals>.<lambda>  s    DFO r]   )r  r~   r   )r   r   r  r  s     @@r^   r  z!Converter.gen_structure_annotated  s(    ##,,V4++r]   r   c                     t        ||       S )zgGenerate a TypedDict unstructure function.

        Also apply converter-scored modifications.
        )make_typeddict_dict_unstruct_fnr  s     r^   r  z#Converter.gen_unstructure_typeddict  s    
 /r488r]   c                 T   t        |      }t        |xs |      }t        |      rt        d |D              rt	        |       |D ci c]>  }|j
                  | j                  v r$|j                  | j                  |j
                     @ }}t        || fd| j                  i|S c c}w )Nc              3   P   K   | ]  }t        |j                  t                 y wrc   rq   r   r   rr   r   s     r^   rt   z;Converter.gen_unstructure_attrs_fromdict.<locals>.<genexpr>        JQAFFC!8 J   $&_cattrs_omit_if_default)
r$   r!   r   ru   r   r   rk  r   rH   ri  )r   r   r  attribsr   attrib_overridess         r^   r~  z(Converter.gen_unstructure_attrs_fromdict  s     B2&R=S J' JJ" 
vv,,, FFD''//
 
 (
.2.B.B
FV
 	

s   AB%c                     |j                   }|d   t        u r|d   n|d   }|t        u st        |t              r| j
                  }n| j                  j                  |      }|fd}|S )z2Generate an unstructuring hook for optional types.r   r   c                     | d S  ||       S rc   r\   )rs   _handlers     r^   unstructure_optionalz@Converter.gen_unstructure_optional.<locals>.unstructure_optional  s    ;49HSM9r]   )rl   rk   r
   rq   r   r   ry   r   )r   r   rG  rH  r/  r  s         r^   r  z"Converter.gen_unstructure_optional  si    {{#/?h#>QLQRO C<:eW5&&G,,55e<G/6 	: $#r]   c                 2    t        || | j                        S )zeGenerate a TypedDict structure function.

        Also apply converter-scored modifications.
        )_cattrs_detailed_validation)make_typeddict_dict_struct_fnr   r  s     r^   r  z!Converter.gen_structure_typeddict  s    
 -$2J2J
 	
r]   c                    t        t        |      rt        |      xs |n|      }t        |      rt	        d |D              rt        |       |D ci c]>  }|j                  | j                  v r$|j                  | j                  |j                     @ }}t        || f| j                  | j                  | j                  d|S c c}w )Nc              3   P   K   | ]  }t        |j                  t                 y wrc   r  r  s     r^   rt   z9Converter.gen_structure_attrs_fromdict.<locals>.<genexpr>  r  r  )_cattrs_forbid_extra_keysr  r  )r!   r+   r$   r   ru   r   r   rk  r   rG   rj  r   r   )r   r   r  r   r  s        r^   r  z&Converter.gen_structure_attrs_fromdict  s     BB-2RHR=S J' JJ" 
vv,,, FFD''//
 

 &
 '+&<&<-1-K-K(,(@(@
 
 	

s   ACrt  c                     | j                   j                  t        |      xs ||xs t              }t	        || |      }| j
                  j                  ||fgd       |S Nrs  Tdirect)rl  getr$   r-  rJ   ry   r   r   r   rt  hs       r^   ru  z"Converter.gen_unstructure_iterable  sa     <<@@rN b."8D
 )T.Q002q'40Hr]   c                     | j                   j                  t        |      xs ||xs t              }t	        || |      }| j
                  j                  ||fgd       |S r  )rl  r  r$   r-  rI   ry   r   r  s       r^   r  z&Converter.gen_unstructure_hetero_tuple  sa     <<@@rN b."8D
 -RnU002q'40Hr]   key_handlerc                     | j                   j                  t        |      xs ||xs t              }t	        || ||      }| j
                  j                  ||fgd       |S )N)rt  r  Tr  )rl  r  r$   r@  rL   ry   r   )r   r   rt  r  r  s        r^   r  z!Converter.gen_unstructure_mapping  sh     <<@@rN b."8D
 (^
 	002q'40Hr]   c                     t        || t        t        | j                        }| j                  j                  ||fgd       |S )N)r8  rB  r   Tr  )rK   r   r   r   r~   r   r   r   r  s      r^   r  zConverter.gen_structure_counter
  sG    %  $ 8 8
 	..Qy.Fr]   c                 v    t        || | j                        }| j                  j                  ||fgd       |S )N)r   Tr  )rK   r   r~   r   r  s      r^   r  zConverter.gen_structure_mapping  s?    %$*B*B
 	..Qy.Fr]   c	           
      4   | j                  ||n| j                  ||n8| 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                  |	j                   | j"                         |	S )rb  )skip)r   r|   rz   r   rM   rZ   r[   ri  rj  rk  rl  r   r   ry   rc  r   r~   r   )
r   r   r   ri  rj  rk  ro  r   r   r   s
             r^   r_  zConverter.copy  s     nn(4L$:L:L)  **d.K.KK $++(11.:O@T@T , '',8Nd>Q>Q,8 *44'3 %//".  ))-
2 	&&!!(@(@ 	' 	
 	$$S%8%8t?U?U$V
r]   rc   )NN)NNNNNNNN))rV   rW   rX   rY   rd  r@  rM   rZ   r   r
   re  r   r   rA   r8   r;   r:   r   rQ   r  r  r  r   r  r   r~  r  r  r  rD   ru  rC   r  r   rF   r  rE   r  r  r_  __classcell__r   s   @r^   rO   rO     sC   KI +/.A.I.I %"';=AC).$(EWAVFHr3w'FH ,FH 	FH
  FH  &7 78FH (/tX~'>FH #'FH "FH '2/&BFH %0$>FHP-$q' -hSz1}6M -
7,x ,9C 9HdVT\4J 9
q'
	1#tCH~%	&
$$47 $xS7I $ 
# 
(D64<2H 

q'
	738$c*A-	.
, .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^. 
.r]   rO   )icollectionsr   r   collections.abcr   r}  dataclassesr   enumr   	functoolsr   pathlibr	   typingr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   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   r3   r4   r5   disambiguatorsr6   r7   r   r8   r9   r:   r;   r0  r<   r=   r>   fnsr?   r@   genrA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   gen.typeddictsr  r  __all__r   rk   rQ   rR   rM   re  rh   rn   rv   rN   rO   rP   r\   r]   r^   <module>r     s0   & 7         "        @ H X X 
 '    T W
O:CLCL$ ,4 ,HdVT\2 ,
VT Vd VRT Rd RO
 O
dK K\
 r]   