
    iV'                         S SK Jr  S SKJrJrJr  S SKJrJr  SSK	J
r
  SSKJrJrJrJr  SSKJr  / SQrS	\S
\4S jr\S\4S\S\
S\\/\4   S\S\\\4   S
S4S jjr SS\S\
S\S
S4S jjrg)    )defaultdict)AnyCallableUnion)NOTHINGNothingType   )BaseConverter)get_newtype_base
is_literalis_subclassis_union_type)is_type_alias)configure_tagged_unionconfigure_union_passthroughdefault_tag_generatortypreturnc                     U R                   $ )zReturn the class name.)__name__)r   s    X/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/cattrs/strategies/_unions.pyr   r      s    <<    _typeunion	convertertag_generatortag_namedefaultNc                   ^^ [        U 5      (       a  U R                  n U R                  n0 n0 n0 nT[        Lax  UR	                  T5      n	TU	4S[
        4S jjm[        U4S j5      n[        U4S j5      n[        USS5      (       a  UUU	T4S[
        SU 4S jjn
OGUUU	T4S[
        SU 4S	 jjn
O3[        USS5      (       a  Xc4S[
        SU 4S
 jjn
OXc4S[
        SU 4S jjn
UUU4SU S[
        4S jjnUR                  X5        UR                  X
5        U HY  nU" U5      nUR	                  U5      nUR                  U5      nX4S[
        SU4S jjnU4SU S[
        4S jjnUXm'   UX|'   XU'   M[     g)at  
Configure the converter so that `union` (which should be a union, or a type alias
of one) is un/structured with the help of an additional piece of data in the
unstructured payload, the tag.

:param converter: The converter to apply the strategy to.
:param tag_generator: A `tag_generator` function is used to map each
    member of the union to a tag, which is then included in the
    unstructured payload. The default tag generator returns the name of
    the class.
:param tag_name: The key under which the tag will be set in the
    unstructured payload. By default, `'_type'`.
:param default: An optional class to be used if the tag information
    is not present when structuring.

The tagged union strategy currently only works with the dict
un/structuring base strategy.

.. versionadded:: 23.1.0

..  versionchanged:: 25.1
    Type aliases of unions are now also supported.
valc                     U" X5      $ N r    _cl_hs      r   structure_default1configure_tagged_union.<locals>.structure_default?       c<r   c                     > T $ r"   r#   )r'   s   r   <lambda>(configure_tagged_union.<locals>.<lambda>B   s    *;r   c                     > T $ r"   r#   )r   s   r   r+   r,   C   s    r   forbid_extra_keysFr   c                 n    X0;   a)  U R                  5       n X R                  U5         " U 5      $ U" X5      $ r"   copypopr    __tag_to_hook	_tag_name_dh_defaults         r   structure_tagged_union6configure_tagged_union.<locals>.structure_tagged_unionG   s7     #((*C'	(:;C@@3))r   c                 6    X0;   a  X U      " U 5      $ U" X5      $ r"   r#   r3   s         r   r9   r:   V   s'     #'I7<<3))r   c                 T    U R                  5       n X R                  U5         " U 5      $ r"   r0   r    r4   
_tag_to_clr6   s       r   r9   r:   e   s&     hhj!'')"45c::r   c                     X U      " U 5      $ r"   r#   r=   s       r   r9   r:   m   s     "i.1#66r   c                 N    XR                      " U 5      nX R                      XC'   U$ r"   )	__class__)r    _exact_cl_unstruct_hooks
_cl_to_tagr6   ress        r   unstructure_tagged_union8configure_tagged_union.<locals>.unstructure_tagged_unionr   s(     '}}5c:#MM2
r   c                     U" X5      $ r"   r#   r$   s      r   structure_union_member6configure_tagged_union.<locals>.structure_union_member   r)   r   c                     U" U 5      $ r"   r#   )r    r&   s     r   unstructure_union_member8configure_tagged_union.<locals>.unstructure_union_member   s    c7Nr   N)r   	__value____args__r   get_structure_hookdictr   getattrregister_unstructure_hookregister_structure_hookget_unstructure_hook)r   r   r   r   r   argstag_to_hookexact_cl_unstruct_hooks	cl_to_tagdefault_handlerr9   rE   cltagstruct_handlerunstruct_handlerrH   rK   r'   s       `             @r   r   r      s   < U>>DK Ig#66w?-4 	 4 	  "";<0	91599
 )"# ** *$ )"# 
*
* 
* 91599 *5;;; *5777 "9	
 
 ''H%%eDB"55b9$99"=24 	  	 B 	  5E 	% 	 	 2&>#" r   accept_ints_as_floatsc                    ^^^ [        U R                  5      mS[        S[        4UUU4S jjnS[        S[        4U4S jjnTR                  XC5        g)a  
Configure the converter to support validating and passing through unions of the
provided types and their subsets.

For example, all mature JSON libraries natively support producing unions of ints,
floats, Nones, and strings. Using this strategy, a converter can be configured
to efficiently validate and pass through unions containing these types.

The most important point is that another library (in this example the JSON
library) handles producing the union, and the converter is configured to just
validate it.

Literals of provided types are also supported, and are checked by value.

NewTypes of provided types are also supported.

The strategy is designed to be O(1) in execution time, and independent of the
ordering of types in the union.

If the union contains a class and one or more of its subclasses, the subclasses
will also be included when validating the superclass.

:param accept_ints_as_floats: When set (the default), if the provided union
    contains both ints and floats, actual unions containing only floats will also accept
    ints. See https://typing.python.org/en/latest/spec/special-types.html#special-cases-for-float-and-complex
    for more information.

.. versionadded:: 23.2.0
.. versionchanged:: 25.2.0
    Introduced the `accept_ints_as_floats` parameter.

exact_typer   c                 ~  >^^	 U R                    VVs1 s H*  n[        U5      (       d  M  UR                     H  o"iM     M,     nnnU R                    VVs1 s H5  n[        U5      (       d  M  UR                     H  nUR                  iM     M7     snnm	U R                    Vs1 s HC  n[        U5      (       a  M  [        U5      =(       d    UT;   d  M/  [        U5      =(       d    UiME     nnUT V^s1 s H!  m[	        U4S jU 5       5      (       d  M  TiM#     sn-  nU R                    Vs1 s H1  n[        U5      =(       d    UU;  d  M  [        U5      (       a  M/  UiM3     nnT
(       a=  [
        T;   a3  [        T;   a)  [        U;   a  [
        U;  a  UR                  [
        5        U(       aS  [        U5      S:  a  [        [        U5         O[        [        U5      5      nUUTU4S[        S[        SU 4U	4S jjjnU$ XC4S[        S[        SU 4U	4S jjjnU$ s  snnf s  snnf s  snf s  snf s  snf )Nc              3   <   >#    U  H  n[        TU5      v   M     g 7fr"   )r   ).0cas     r   	<genexpr>Sconfigure_union_passthrough.<locals>.make_structure_native_union.<locals>.<genexpr>   s     "R>Q;q!#4#4>Qs      r    r4   r   c                 x   > U R                   T;   a  X;   a  U $ U R                   U;   a  U $ UR                  X5      $ r"   )rA   	structure)r    r4   classesvalsr   	spilloverliteral_classess         r   structure_native_union`configure_union_passthrough.<locals>.make_structure_native_union.<locals>.structure_native_union   s<     ==O3J==G+J **3::r   c                    > U R                   T;   a  X;   a  U $ U R                   U;   a  U $ [        U  SU R                    SU 35      e)Nz (z) not part of )rA   	TypeError)r    r4   rk   rl   rn   s       r   ro   rp      sK     ==O3J==G+J3%r#--qc JKKr   )rN   r   rA   r   anyintfloataddlenr   tuplenextiterr   )r`   tvliteral_valuesnon_literal_classesre   rm   spillover_typero   rn   r^   rU   r   s        `   @r   make_structure_native_union@configure_union_passthrough.<locals>.make_structure_native_union   s=    "**
*!jmAQZZAZA* 	 
  ((
(!}  ZZ KK   (
  ((
(a= %'7':'?aD&H %Q$1$( 	 
 	 
!s"R>Q"RRAt 
 	
  ((
( #(q1DD  qM ( 	 
 "t,,..##C(+.y>A+=eI&'4YCX  ,##(;;; ; ;2 &% +>LL LL L &%[


 

sF   H$H$H*.$H*$H0<H0H06H5H51H:H:#H:c                   > [        U 5      (       a  [        U R                  5      n[        U5      S:X  a  [	        S5      U;   a  gU VVs1 s H5  n[        U5      (       d  M  UR                    H  nUR                  iM     M7     nnnU Vs1 s H)  n[        U5      (       a  M  [        U5      =(       d    UiM+     nnXE-  T-  $ gs  snnf s  snf )zCan we handle this type?r	   NF)r   setrN   rw   typer   rA   r   )r`   	type_argsr{   lit_argrn   non_literal_typesrU   s         r   contains_native_union:configure_union_passthrough.<locals>.contains_native_union  s    $$J//0I 9~"tDzY'> #"Aa= "  !zzG !!  * ""   3<!2;Q:a=( #(q()  ! $74??!s   C#$CC&CN)r   rN   r   r   boolregister_structure_hook_factory)r   r   r^   r   r   rU   s    ``  @r   r   r      sW    D u~~DO& O& O& O&b# $ , --r   )T)collectionsr   typingr   r   r   attrsr   r    r
   _compatr   r   r   r   typealiasesr   __all__r   strr   r   r   r   r#   r   r   <module>r      s    # ' ' &  N N 't   ,A(/vvv TFCK(v 	v
 4$%v 
vt IMMM(MAEM	Mr   