o
    Ti9                     @  sh  U d dl mZ d dlZd dlmZmZmZ d dlmZm	Z	m
Z
mZmZ d dlmZmZmZmZ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 dd	lm Z  dd
l!m"Z" ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0m1Z1 ddlm2Z2 ddl3m4Z4 ddl5m6Z6m7Z7 erddl8m9Z9 g dZ:					d]d^d d!Z;ed"Z<i d#d$d%d#fd_d6d7Z=	#	$	%	#d`dad8d9Z>i d%d$d%d%d%d#fdbd>d?Z?	%	$	%	%	%	#dcddd@dAZ@eee	 ge	f ZAeeBe	dBf ge	f ZCdCeDdD< 		dedfdIdJZEeee	e	f ge	f ZF		dedgdNdOZGeGZHdPeDdQ< eIeed%fdhdVdWZJeJZKdPeDdX< 	didjdZd[ZLeLZMdPeDd\< dS )k    )annotationsN)CallableIterableMapping)TYPE_CHECKINGAnyFinalLiteralTypeVar)NOTHING	Attribute	ConverterFactoryevolve)	NoDefault   )	ANIES	TypeAliasadapted_fieldsget_args
get_originis_annotatedis_bareis_bare_final
is_generic)deep_copy_with)UnstructureHook)AttributeValidationNoteClassValidationErrorForbiddenExtraKeysErrorIterableValidationErrorIterableValidationNoteStructureHandlerNotFoundError)identity)SimpleStructureHook   )AttributeOverridealready_generatingneutral)generate_mapping)generate_unique_filename)_annotated_override_or_defaultfind_structure_handler)BaseConverter)make_dict_structure_fn!make_dict_structure_fn_from_attrsmake_dict_unstructure_fn#make_dict_unstructure_fn_from_attrs make_hetero_tuple_unstructure_fnmake_iterable_unstructure_fnmake_mapping_structure_fnmake_mapping_unstructure_fnomit_if_defaultbool | Nonerename
str | Noneomitstruct_hook Callable[[Any, Any], Any] | Noneunstruct_hookCallable[[Any], Any] | Nonereturnr&   c                 C  s   t | ||||S )zOverride how a particular field is handled.

    :param omit: Whether to skip the field or not. `None` means apply default handling.
    )r&   )r6   r8   r:   r;   r=    r@   G/home/ubuntu/.local/lib/python3.10/site-packages/cattrs/gen/__init__.pyoverride5   s   rB   TFTfrom_converterattrslist[Attribute]cltype[T]	converterr-   typevar_mapdict[str, Any]_cattrs_omit_if_defaultbool_cattrs_use_linecache_cattrs_use_alias bool | Literal['from_converter']_cattrs_include_init_falsekwargsCallable[[T], dict[str, Any]]c           $   	   K  s  d|j  }	i }
g }g }i }|dkrt|dd}| D ]}|j}||v r(|| }nt|jt}|tkr6|||< |jr:q|jdu rE|jsE|sEq|jdu r^|sN|n|j	}||kr]t
||d||< n|j}|j}d}|jduro|j}n_|jdur|j}t|tr|j |v r||j  }n|j}nt|rt|st|st|||}|du rt|r|jturt|jts|jj}z	|j|dd}W n ty   |j}Y nw n|j}|tk}|sd| }||
|< |||< | d	| d
}nd| }|tur|r|jdus|jrd| }t|tr#|j|
|< |j||< |jr| dn| d}n
||
|< |||< |}|j}|durd| }t|tra||
|< |||< d| }||
|< |||< | d| d| d
}n#t|trx||
|< |||< | d| d
}n|||
|< ||||< | d| d| d | d| d|  q| d| d| d qd!dd |D }|rd| }|" D ]	\}}||
|< qd|	 d| d gd!g d"d |D  d#g | d$g } d%!| }!t#|d&|r| ng d'}"t$t%|!|"d(|
 |
|	 }#||#_&|#S ))a  
    Generate a specialized dict unstructuring function for a list of attributes.

    Usually used as a building block by more specialized hook factories.

    Any provided overrides are attached to the generated function under the
    `overrides` attribute.

    :param cl: The class for which the function is generated; used mostly for its name,
        module name and qualname.
    :param _cattrs_omit_if_default: if true, attributes equal to their default values
        will be omitted in the result dictionary.
    :param _cattrs_use_alias: If true, the attribute alias will be used as the
        dictionary key by default.
    :param _cattrs_include_init_false: If true, _attrs_ fields marked as `init=False`
        will be included.

    .. versionadded:: 24.1.0
    .. versionchanged:: 25.2.0
        The `_cattrs_use_alias` parameter takes its value from the given converter
        by default.
    .. versionchanged:: 26.1.0
        `typing.Annotated[T, override()]` is now recognized and can be used to customize
        unstructuring.
    .. versionchanged:: 26.1.0
        When `_cattrs_omit_if_default` is true and the attribute has an attrs converter
        specified, the converter is applied to the default value before checking if it
        is equal to the attribute's value.
    unstructure_rD   	use_aliasFNr8   cache_result
__c_unstr_z
(instance.)	instance.__c_def_z
(instance)z()	__c_conv_
__c_field_(z, instance, z  if instance.z != :	    res[''] = 'z': ,, c                 S     g | ]	}| d | qS =r@   .0ir@   r@   rA   
<listcomp>       z7make_dict_unstructure_fn_from_attrs.<locals>.<listcomp>def z	(instance):	  res = {c                 S     g | ]}d | qS z    r@   rj   liner@   r@   rA   rl          z  }  return res
unstructurelinesexec)'__name__getattrnamer+   typer(   r:   initr8   aliasr   defaultr=   
isinstancer
   rx   r   r   r   r   r   r   r   	__class__get_unstructure_hookRecursionErrorr#   r6   factory
takes_selfrI   r   appendjoinitemsr*   evalcompile	overrides)$rE   rG   rI   rJ   rL   rN   rO   rQ   rR   fn_nameglobsrz   invocation_linesinternal_arg_partsa	attr_namerB   kndhandlertis_identityunstruct_handler_nameinvokedef_namedef_strc	conv_name
field_nameinternal_arg_linekvtotal_linesscriptfnameresr@   r@   rA   r1   F   s   
)





















r1   c              	   K  s   t | }t|p| }i }	|dkrt|dd}t| r%t| |	}	|dur%|} ztj}
W n ty9   t }
|
t_Y nw | |
v rAt	 |

|  zt|| ||	f||||d|W |
|  |
sat`S S |
|  |
skt`w )a  
    Generate a specialized dict unstructuring function for an attrs class or a
    dataclass.

    Any provided overrides are attached to the generated function under the
    `overrides` attribute.

    :param _cattrs_omit_if_default: if true, attributes equal to their default values
        will be omitted in the result dictionary.
    :param _cattrs_use_alias: If true, the attribute alias will be used as the
        dictionary key by default.
    :param _cattrs_include_init_false: If true, _attrs_ fields marked as `init=False`
        will be included.

    .. versionadded:: 23.2.0 *_cattrs_use_alias*
    .. versionadded:: 23.2.0 *_cattrs_include_init_false*
    .. versionchanged:: 25.2.0
        The `_cattrs_use_alias` parameter takes its value from the given converter
        by default.
    .. versionchanged:: 26.1.0
        `typing.Annotated[T, override()]` is now recognized and can be used to customize
        unstructuring.
    rD   rU   FN)rL   rN   rO   rQ   )r   r   r}   r   r)   r'   working_setAttributeErrorsetr   addr1   remove)rG   rI   rL   rN   rO   rQ   rR   originrE   mappingr   r@   r@   rA   r0      sN    



	

r0   _cattrs_forbid_extra_keys _cattrs_prefer_attrib_converters_cattrs_detailed_validation)SimpleStructureHook[Mapping[str, Any], T]c
           ,      K  sV  |j }d| }t|ddD ]=}z||j  }W n ty*   |j }td| d|dw t|ddp4t|}tdd	|}td
d|}|d	| 7 }qd|i}i }g }g }g }g }t }|dkrft|dd}|dkrpt|dd}|dkrw|j}|dkr~|j	}|r||d< t
|d< |r|d |d |d t|d< t|d< | D ]}|j}||
v r|
| }nt|jt}|tkr||
|< |jrq|jdu r|js|	sq|j}t|tr||j |}nt|rt|st|st|||}|jdur|j}nt||||}d| }|dur|||< |j}|jdu r/|s|n|j}||kr.t||d|
|< n|j}| | d} |js|j!t"urS||  d| d |  d} ||  d |  d} d| }!|||!< |dur||j#kr|||< ||  d| d | d!| d" n,d| }"|||"< ||  d| d | d!| d#|" d$
 n||  d| d%| d& | dd' } ||  d( |  d} ||  d)|j$ d*| d+| d,| d-
 ||  d. q|j!t"ur||  d| d |  d} ||  d |  d} d| }!|||!< |rG||j#kr2|||< ||  d/| d0| d!| d" n#||  d/| d0| d!| d#|! d$
 n||  d/| d1| d& | dd' } ||  d( |  d} ||  d)|j$ d*| d+| d,| d-
 ||  d. q|r|g d27 }|d3|d4 |sd5gd6g d7d8 |D  d9g d:|d;g }#nd5gd<g d=d8 |D  d9g d:|d;g }#|d> ng }$| D ]9}|j}||
v r|
| }nt|jt}|tkr||
|< |jrq|jdu r
|js
|	s
q|j!t"ur|$| q|j}t|tr(||j |}nt|r=t|s=t|s=t|||}|jdurG|j}nt||||}|jdu rj|sY|n|j}||krit||d|
|< n|j}| | |js|durd| }|||< ||j#kr|||< d?| d | d!| d"}%n"d| }"|||"< d?| d | d!| d#|" d$	}%n	d?| d%| d&}%||% q|rd| }|||< ||j#kr|||< | d!| d@}&nd| }"|||"< | d!| d#|" dA}&ndB| dC}&|j%r
|j dD|& }&||& q|$r;|d |d |$D ]}|j}|
|t}|j}t|tr=||j |}nt|rRt|sRt|sRt|||}|jdur\|j}nt||||}d| }|||< |jdu r|sw|n|j}||krt||d|
|< n|j}| | |js|dE| d |r||j#kr|||< |dF| d | d!| d" q d| }"|||"< |dF| d | d!| d#|" d$	 q |dF| d%| d& q |dE| d |r,||j#kr|||< |dG|j d0| d!| d" q d| }"|||"< |dG|j d0| d!| d#|" d$	 q |dG|j d1| d& q |sLdHgdId8 |D  dJg }#ndKgdLd8 |D  dJg }#|d> |rg|g dM7 }dN&dOd8 |D }'|'| dP| dQ|' dRg|||#|}(dS&|(})t(|dT|r|(ng dU}*t)t*|)|*dV| || }+|
|+_+|+S )Wa  
    Generate a specialized dict structuring function for a list of attributes.

    Usually used as a building block by more specialized hook factories.

    Any provided overrides are attached to the generated function under the
    `overrides` attribute.

    :param _cattrs_forbid_extra_keys: Whether the structuring function should raise a
        `ForbiddenExtraKeysError` if unknown keys are encountered.
    :param _cattrs_use_linecache: Whether to store the source code in the Python
        linecache.
    :param _cattrs_prefer_attrib_converters: If an _attrs_ converter is present on a
        field, use it instead of processing the field normally.
    :param _cattrs_detailed_validation: Whether to use a slower mode that produces
        more detailed errors.
    :param _cattrs_use_alias: If true, the attribute alias will be used as the
        dictionary key by default.
    :param _cattrs_include_init_false: If true, _attrs_ fields marked as `init=False`
        will be included.

    .. versionadded:: 24.1.0
    .. versionchanged:: 25.2.0
        The `_cattrs_use_alias` parameter takes its value from the given converter
        by default.
    .. versionchanged:: 26.1.0
        `typing.Annotated[T, override()]` is now recognized and can be used to customize
        unstructuring.
    
structure___parameters__r@   z"Missing type for generic argument z, specify it when structuring.Nr|   z[\[\.\] ,<>]_z\|u__clrD   forbid_extra_keysFrU   __c_a__c_fekez
  res = {}z  errors = []z**res,__c_cve__c_avn__c_structure_rV   z  zif 'z' in o:ztry:	__c_type_r[   z = z(o['z'])z'], rZ   z = o['z']zexcept Exception as e:zHe.__notes__ = getattr(e, '__notes__', []) + [__c_avn("Structuring class z @ attribute z", "z", __c_type_z)]zerrors.append(e)zres['rb   z'] = o[')(  unknown_fields = set(o.keys()) - __c_a  if unknown_fields:z5    errors.append(__c_feke('', __cl, unknown_fields))z2  if errors: raise __c_cve('While structuring ' + z, errors, __cl)z  try:z    return __cl(c                 S  rq   z      r@   rs   r@   r@   rA   rl     ru   z5make_dict_structure_fn_from_attrs.<locals>.<listcomp>    )z@  except Exception as exc: raise __c_cve('While structuring ' + z, [exc], __cl)z    instance = __cl(c                 S  rq   r   r@   rs   r@   r@   rA   rl   '  ru   z  return instancez  instance.z']),z),zo['z'],rh   z  if 'z    instance.ra   z  return __cl(c                 S  rq   rr   r@   rs   r@   r@   rA   rl     ru   z  )z  instance = __cl(c                 S  rq   rr   r@   rs   r@   r@   rA   rl     ru   )r   r   z,    raise __c_feke('', __cl, unknown_fields)re   c                 S  rf   rg   r@   ri   r@   r@   rA   rl     rm   rn   z(o, _=__cl, ro   rw   	structurery   r{   ),r|   r}   KeyErrorr"   strresubr   detailed_validation_prefer_attrib_convertersr   r   r   r   r~   r+   r   r(   r:   r   r   r
   getr   r   r   r   r;   r,   r   r8   r   r   r   r   _structure_call__qualname__kw_onlyr   updater*   r   r   r   ),rE   rG   rI   rJ   r   rN   r   r   rO   rQ   rR   cl_namer   p	name_basepnr~   r   r   rz   
post_linespi_linesr   allowed_fieldsr   anrB   r   r   struct_handler_nameianr   rk   	type_nametninstantiation_linesnon_requiredpi_lineinvocation_liner   r   r   r   r   r@   r@   rA   r/   H  sZ  -
















 
"


 
"


	






















r/   c              	   K  s   i }	t | rt| }
t| |	}	|
dur|
} t| ddD ]}
t |
r/t|
ds/t|
|	}	 nqt| }ztj}W n t	yH   t
 }|t_Y nw | |v rPt ||  zt|| ||	f||||||d|W ||  |srt`S S ||  |s|t`w )av  
    Generate a specialized dict structuring function for an attrs class or
    dataclass.

    Any provided overrides are attached to the generated function under the
    `overrides` attribute.

    :param _cattrs_forbid_extra_keys: Whether the structuring function should raise a
        `ForbiddenExtraKeysError` if unknown keys are encountered.
    :param _cattrs_use_linecache: Whether to store the source code in the Python
        linecache.
    :param _cattrs_prefer_attrib_converters: If an _attrs_ converter is present on a
        field, use it instead of processing the field normally.
    :param _cattrs_detailed_validation: Whether to use a slower mode that produces
        more detailed errors.
    :param _cattrs_use_alias: If true, the attribute alias will be used as the
        dictionary key by default.
    :param _cattrs_include_init_false: If true, _attrs_ fields marked as `init=False`
        will be included.

    .. versionadded:: 23.2.0 *_cattrs_use_alias*
    .. versionadded:: 23.2.0 *_cattrs_include_init_false*
    .. versionchanged:: 23.2.0
        The `_cattrs_forbid_extra_keys` and `_cattrs_detailed_validation` parameters
        take their values from the given converter by default.
    .. versionchanged:: 24.1.0
        The `_cattrs_prefer_attrib_converters` parameter takes its value from the given
        converter by default.
    .. versionchanged:: 25.2.0
        The `_cattrs_use_alias` parameter takes its value from the given converter
        by default.
    .. versionchanged:: 26.1.0
        `typing.Annotated[T, override()]` is now recognized and can be used to customize
        unstructuring.
    N__orig_bases__r@   ztyping.Generic)r   rN   r   r   rO   rQ   )r   r   r)   r}   r   
startswithr   r'   r   r   r   r   r   r/   r   )rG   rI   r   rN   r   r   rO   rQ   rR   r   baserE   r   r@   r@   rA   r.     sX   1






r.   .r   HeteroTupleUnstructureFnr   unstructure_to	type_argstuple | Nonec           
        s  d}|du r
t | n|} fdd|D }dd t|D }|tur(|p%| |d< g }|d| d	 |tur=|d
 n|d tt|D ]}|| tkrZ|d| d qH|d| d| d qH|turq|d n|d g |d}	ttd	|	dd| || S )zGenerate a specialized unstructure function for a heterogenous tuple.

    :param type_args: If provided, override the type arguments.
    unstructure_tupleNc                   s   g | ]}  |qS r@   )r   )rj   type_argrI   r@   rA   rl   h  ru   z4make_hetero_tuple_unstructure_fn.<locals>.<listcomp>c                 S  s   i | ]
\}}d | |qS )
__cattr_u_r@   )rj   rk   hr@   r@   rA   
<dictcomp>j  s    z4make_hetero_tuple_unstructure_fn.<locals>.<dictcomp>__cattr_seq_clrn   z(tup):z    res = __cattr_seq_cl((z    res = (z        tup[z],z        __cattr_u_z(tup[z]),z    ))r       return resrw    r{   )
r   	enumeratetupler   rangelenr#   r   r   r   )
rG   rI   r   r   r   handlersr   rz   rk   r   r@   r   rA   r2   Y  s*   


r2   key_handler'Callable[[Any, Any | None], Any] | NoneMappingUnstructureFnc                 C  s^  |p|j }|j }d}| }t| dddurHt| }t|dkr#|\}	}
n|t}	}
|p0|j|	dd}|tkr7d}|j|
dd}|tkrDd}t| }||d}|durSdnd	}|dur[d
nd}d| dg}|tu sp|du r|tu r|du rz|du rztS |	d| d| d n|p| |d< |	d| d| d g |d}t
td|dd| || S )zGenerate a specialized unstructure function for a mapping.

    :param unstructure_to: The class to unstructure to; defaults to the
        same class as the mapping being unstructured.
    unstructure_mapping__args__Nr   FrW   )__cattr_k_u__cattr_v_uz__cattr_k_u(k)r   z__cattr_v_u(v)r   rn   z
(mapping):z    return {:  for k, v in mapping.items()}__cattr_mapping_clz    res = __cattr_mapping_cl((re   z) for k, v in mapping.items())r   rw   r   r{   )rx   r}   r   r   r   r   r#   r   dictr   r   r   r   )rG   rI   r   r   khval_handlerr   r   argskey_argval_argr   k_uv_urz   r@   r@   rA   mapping_unstructure_factory  s>   



r  r   r5   structure_tor   r   )SimpleStructureHook[Mapping[Any, Any], T]c                 C  s  d}|dkr	|j }d|i}g }i }	t| st| }
t|
dkr0|
\}}|tu r)|}|tu r/|}n|tur<|tu r<|
\}n|tu rH|turH|
\}n|
\}t}|tv oT|tv }|s|j|dd}||jkre|}|j|dd}||jkrs|}||d< ||d< ||d	< ||d
< ||krdnd}||krdnd}nd}|r|	d n|rt
|	d< t|	d< |tur|nt|	d< |tur|nt|	d< t|d< |	d |	d |	d |	d|  |	d |	d |	d |	d |	d |	d|  |	d |	d |	d  |	d |	d! |	d"t| d# n|	d$| d%| d& |tur4|	d' d(d)d* |	D }|rFd(| }|	 D ]	\}}|||< qJ| |d+< d,| d-| d.}|g|d/}d0|}tt|d1d2| || S )3z8Generate a specialized structure function for a mapping.structure_mappingrD   r   r   FrW   __cattr_k_t__cattr_v_t__cattr_k_s__cattr_v_sz__cattr_k_s(k, __cattr_k_t)z__cattr_k_s(k)z__cattr_v_s(v, __cattr_v_t)z__cattr_v_s(v)Tz  res = dict(mapping)r    r!   val_typekey_typer   z  res = {}; errors = []z  for k, v in mapping.items():z    try:z      value = z    except Exception as e:z      e.__notes__ = getattr(e, '__notes__', []) + [IterableValidationNote(f'Structuring mapping value @ key {k!r}', k, val_type)]z      errors.append(e)z      continuez      key = z      res[key] = valuez      e.__notes__ = getattr(e, '__notes__', []) + [IterableValidationNote(f'Structuring mapping key @ key {k!r}', k, key_type)]z  if errors:z9    raise IterableValidationError('While structuring ' + z, errors, __cattr_mapping_cl)rp   r   r   z  res = __cattr_mapping_cl(res)re   c                 S  rf   rg   r@   ri   r@   r@   rA   rl   8  rm   z-mapping_structure_factory.<locals>.<listcomp>rG   rn   z(mapping, cl=clro   rv   rw   r   r{   )r   r   r   r   r   r   r   get_structure_hookr   r   r    r!   r   reprr   r   r   r   r   )rG   rI   r  r  r  r   r   r   rz   r   r  key_arg_candval_arg_candis_bare_dictr   r  k_sv_sr   r   r   def_liner   r   r@   r@   rA   mapping_structure_factory  s   	
















r  r4   r   c                 C  sv   |j }t| dddvr0| jd }t|tr!t|dt}|tu r!t}|j|dd}|tkr0|p/| S |p3| |fdd	}|S )
zA hook factory for unstructuring iterables.

    :param unstructure_to: Force unstructuring to this type, if provided.

    ..  versionchanged:: 24.2.0
        `typing.NoDefault` is now correctly handled as `Any`.
    r   N)Nr@   r   __default__FrW   c                   s   | fdd| D S )Nc                 3  s    | ]} |V  qd S Nr@   ri   _hookr@   rA   	<genexpr>g  s    zMiterable_unstructure_factory.<locals>.unstructure_iterable.<locals>.<genexpr>r@   )iterable_seq_clr  r@   r  rA   unstructure_iterablef  s   z:iterable_unstructure_factory.<locals>.unstructure_iterable)	rx   r}   r   r   r
   r   r   r   r#   )rG   rI   r   r   r   r!  r@   r@   rA   iterable_unstructure_factoryL  s   


r"  r3   )NNNNN)r6   r7   r8   r9   r:   r7   r;   r<   r=   r>   r?   r&   )rE   rF   rG   rH   rI   r-   rJ   rK   rL   rM   rN   rM   rO   rP   rQ   rM   rR   r&   r?   rS   )FTrD   F)rG   rH   rI   r-   rL   rM   rN   rM   rO   rP   rQ   rM   rR   r&   r?   rS   )rE   rF   rG   rH   rI   r-   rJ   rK   r   rP   rN   rM   r   rP   r   rP   rO   rP   rQ   rM   rR   r&   r?   r   )rD   TrD   rD   rD   F)rG   rH   rI   r-   r   rP   rN   rM   r   rP   r   rP   rO   rP   rQ   rM   rR   r&   r?   r   )NN)
rG   r   rI   r-   r   r   r   r   r?   r   )
rG   r   rI   r-   r   r   r   r   r?   r   )
rG   rH   rI   r-   r  r   r   rP   r?   r	  r  )rG   r   rI   r-   r   r   r?   r   )N
__future__r   r   collections.abcr   r   r   typingr   r   r   r	   r
   rE   r   r   r   r   r   typing_extensionsr   _compatr   r   r   r   r   r   r   r   r   	_genericsr   dispatchr   errorsr   r   r   r    r!   r"   fnsr#   typesr$   _constsr&   r'   r(   r)   _lcr*   _sharedr+   r,   
convertersr-   __all__rB   rC   r1   r0   r/   r.   IterableUnstructureFnr   r   __annotations__r2   r   r  r5   r   r  r4   r"  r3   r@   r@   r@   rA   <module>   s    ,  ;O   0`->| 