o
    "“is(  ã                   @  sÄ  d Z ddlmZ ddlmZ ddl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 ddlmZ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  dd
lm!Z" ddl#m$Z$m%Z% ddl&m'Z'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 ddl+m3Z4 erŒddl5m6Z6 g d¢Z7dGdd„Z8dGdd„Z9dHdd„Z:dIdd „Z;ed!ƒZ<dJd#d$„Z=dJd%d&„Z>	'dKdLd+d,„Z?dMd-d.„Z@dNd0d1„ZA	2	3	4dOdPd;d<„ZB	3	4dQdRd>d?„ZCdHd@dA„ZDefdSdEdF„ZEd'S )Tz"Utility functions for collections.é    )Úannotations)Údefaultdict)ÚCallableÚIterable)Úpartial)ÚTYPE_CHECKINGÚAnyÚDefaultDictÚLiteralÚ
NamedTupleÚTypeVarÚget_type_hints)ÚNOTHINGÚ	AttributeÚNothingTypeé   )
ÚANIESÚAbcSetÚget_argsÚ
get_originÚis_bareÚis_frozensetÚ
is_mappingÚis_mutable_sequenceÚis_sequenceÚis_subclass)Úis_mutable_set)ÚStructureHookÚUnstructureHook)ÚIterableValidationErrorÚIterableValidationNote)Úidentity)ÚAttributeOverrideÚalready_generatingÚ!make_dict_structure_fn_from_attrsÚ#make_dict_unstructure_fn_from_attrsÚ make_hetero_tuple_unstructure_fnÚmapping_structure_factoryÚmapping_unstructure_factory)Úmake_iterable_unstructure_fn)ÚBaseConverter)Údefaultdict_structure_factoryÚ"homogenous_tuple_structure_factoryÚis_abstract_setÚ
is_any_setÚis_defaultdictr   r   r   Úis_namedtupler   Úis_setÚiterable_unstructure_factoryÚlist_structure_factoryr'   r(   Ú!namedtuple_dict_structure_factoryÚ#namedtuple_dict_unstructure_factoryÚnamedtuple_structure_factoryÚnamedtuple_unstructure_factoryÚreturnÚboolc                 C  s   t | ƒpt| ƒS )z5A predicate function for both mutable and frozensets.)r1   r   ©Útype© r<   úK/var/www/html/premium_crap/venv/lib/python3.10/site-packages/cattrs/cols.pyr.   I   s   r.   c                 C  s   | t u pt| ddƒt u S )z8A predicate function for abstract (collection.abc) sets.Ú
__origin__N)r   Úgetattrr:   r<   r<   r=   r-   N   s   r-   r;   r   c                 C  s8   t | tƒr|  ¡ D ]}|j dd¡}t|v r dS q	dS )z&A predicate function for named tuples.Ú__orig_bases__r<   TF)r   ÚtupleÚmroÚ__dict__Úgetr   )r;   ÚclÚ
orig_basesr<   r<   r=   r0   S   s   
ÿr0   útype[tuple]Ú	converterr*   c                   s   t ‡ fdd„| j ¡ D ƒƒS )zZIf all fields would be passed through, this class should not be processed
    either.
    c                 3  s   � | ]
}ˆ   |¡tkV  qd S ©N)Úget_unstructure_hookr!   )Ú.0Út©rH   r<   r=   Ú	<genexpr>b   s
   € ÿ
ÿz"_is_passthrough.<locals>.<genexpr>)ÚallÚ__annotations__Úvalues)r;   rH   r<   rM   r=   Ú_is_passthrough^   s   þrR   ÚTr   c                   s”   t ˆƒsˆjd tv rˆfddd	„}|S ˆjd ‰ z| ˆ ¡‰W n ty,   |j‰Y nw |jr?ˆˆˆ fd‡ ‡‡fd
d	„}|S ˆˆˆ fddd	„}|S )zXA hook factory for structuring lists.

    Converts any given iterable into a list.
    r   ÚobjúIterable[T]Ú_r;   r8   úlist[T]c                 S  ó   t | ƒS rI   )Úlist©rT   rV   r<   r<   r=   Ústructure_lists   ó   z.list_structure_factory.<locals>.structure_listc           	        s¸   g }g }d}| D ]F}z?z
|  ˆ||ƒ¡ W n. tyC } z"tdˆ› d|› �|ˆ ƒ}g t|dg ƒ¢|‘|_|  |¡ W Y d }~nd }~ww W |d7 }q|d7 }w |rZtdˆ›�|ˆƒ‚|S )Nr   zStructuring z	 @ index Ú	__notes__r   zWhile structuring )ÚappendÚ	Exceptionr    r?   r]   r   )	rT   rV   Ú_handlerÚ
_elem_typeÚerrorsÚresÚixÚeÚmsg©Ú	elem_typeÚhandlerr;   r<   r=   r[   ‚   s*   ÿ€û€ÿc                   s   ‡ ‡fdd„| D ƒS )Nc                   ó   g | ]}ˆ|ˆ ƒ‘qS r<   r<   ©rK   re   ©ra   r`   r<   r=   Ú
<listcomp>Ÿ   ó    zBlist_structure_factory.<locals>.structure_list.<locals>.<listcomp>r<   ©rT   rV   r`   ra   r<   rl   r=   r[   œ   s   N)rT   rU   rV   r;   r8   rW   )r   Ú__args__r   Úget_structure_hookÚRecursionErrorÚ	structureÚdetailed_validation)r;   rH   r[   r<   rg   r=   r3   k   s    

þÿüÿr3   c                   s–   t | ƒs| jd tv r| fddd	„}|S | jd }z| |¡}W n ty,   |j}Y nw |jr@t| |ƒ‰ | fd‡ fd
d	„}|S | ||fddd	„}|S )z‡A hook factory for homogenous (all elements the same, indeterminate length) tuples.

    Converts any given iterable into a tuple.
    r   rT   rU   rV   r;   r8   útuple[T, ...]c                 S  rX   rI   ©rA   rZ   r<   r<   r=   Ústructure_tuple®   r\   z;homogenous_tuple_structure_factory.<locals>.structure_tuplec                   s   t ˆ | |ƒƒS rI   rv   rZ   ©Úlist_structurer<   r=   rw   À   s   c                   s   t ‡ ‡fdd„| D ƒƒS )Nc                   rj   r<   r<   rk   rl   r<   r=   rm   È   rn   zOhomogenous_tuple_structure_factory.<locals>.structure_tuple.<locals>.<listcomp>rv   ro   r<   rl   r=   rw   Å   s   N)rT   rU   rV   r;   r8   ru   )r   rp   r   rq   rr   rs   rt   r3   )r;   rH   rw   rh   ri   r<   rx   r=   r,   ¤   s    

þ

üÿr,   NrE   Úunstructure_tor   c                 C  s<   |du rt | |ƒrtS t| ||du rtn|t| j ¡ ƒd�S )z}A hook factory for unstructuring namedtuples.

    :param unstructure_to: Force unstructuring to this type, if provided.
    N)rz   Ú	type_args)rR   r!   r&   rA   rP   rQ   )rE   rH   rz   r<   r<   r=   r7   Í   s   ür7   c                   s,   t t ˆj ¡ ƒ ‰| ˆ¡‰ ‡ ‡‡fdd„S )z:A hook factory for structuring namedtuples from iterables.c                   s   ˆˆ | ˆƒŽ S rI   r<   )ÚvrV   ©Ú	base_hookrE   Úhetero_tuple_typer<   r=   Ú<lambda>ç   s    z.namedtuple_structure_factory.<locals>.<lambda>)rA   rP   rQ   rq   )rE   rH   r<   r}   r=   r6   à   s   
r6   úlist[Attribute]c                   s   ‡ fdd„t ˆ ƒ ¡ D ƒS )z,Generate pseudo attributes for a namedtuple.c                   s6   g | ]\}}t |ˆ j |t¡d ddddd||d�
‘qS )NFT)r;   Úalias)r   Ú_field_defaultsrD   r   )rK   ÚnameÚa©rE   r<   r=   rm   ì   s    ôöÿz(_namedtuple_to_attrs.<locals>.<listcomp>)r   Úitemsr†   r<   r†   r=   Ú_namedtuple_to_attrsê   s   

órˆ   Úfrom_converterFTrt   ú bool | Literal['from_converter']Úforbid_extra_keysÚuse_linecacheÚkwargsr"   c             	   K  sŽ   zt j}W n ty   tƒ }|t _Y nw | |v rtƒ ‚| | ¡ ztt| ƒ| |f|||dœ|¤ŽW | | ¡ |s<t `S S | | ¡ |sFt `w )a<  A hook factory for hooks structuring namedtuples from dictionaries.

    :param forbid_extra_keys: Whether the hook should raise a `ForbiddenExtraKeysError`
        if unknown keys are encountered.
    :param use_linecache: Whether to store the source code in the Python linecache.

    .. versionadded:: 24.1.0
    )Ú_cattrs_forbid_extra_keysÚ_cattrs_use_detailed_validationÚ_cattrs_use_linecache)	r#   Úworking_setÚAttributeErrorÚsetrr   Úaddr$   rˆ   Úremove)rE   rH   rt   r‹   rŒ   r�   r‘   r<   r<   r=   r4   ý   s8   

þ
ýúù

ÿ
ÿr4   Úomit_if_defaultc             	   K  sŒ   zt j}W n ty   tƒ }|t _Y nw | |v rtƒ ‚| | ¡ ztt| ƒ| |f||dœ|¤ŽW | | ¡ |s;t `S S | | ¡ |sEt `w )a=  A hook factory for hooks unstructuring namedtuples to dictionaries.

    :param omit_if_default: When true, attributes equal to their default values
        will be omitted in the result dictionary.
    :param use_linecache: Whether to store the source code in the Python linecache.

    .. versionadded:: 24.1.0
    )Ú_cattrs_omit_if_defaultr�   )	r#   r‘   r’   r“   rr   r”   r%   rˆ   r•   )rE   rH   r–   rŒ   r�   r‘   r<   r<   r=   r5   )  s6   

þ
ýûú
	ÿ
ÿr5   c                 C  s   t t| ƒttfƒS )z­Is this type a defaultdict?

    Bare defaultdicts (defaultdicts with no type arguments) are not supported
    since there's no way to discover their _default_factory_.
    )r   r   r   r	   r:   r<   r<   r=   r/   R  s   r/   útype[defaultdict]Údefault_factoryúCallable[[], Any] | NothingTypec                 C  s&   |t u r
t| ƒd }t| |tt|ƒƒS )ztA structure hook factory for defaultdicts.

    The value type parameter will be used as the _default factory_.
    r   )r   r   r'   r   r   )r;   rH   r™   r<   r<   r=   r+   [  s
   	ÿr+   )r8   r9   )r;   r   r8   r9   )r;   rG   rH   r*   r8   r9   )r;   r;   rH   r*   r8   r   rI   )rE   rG   rH   r*   rz   r   r8   r   )rE   rG   rH   r*   r8   r   )rE   rG   r8   r�   )r‰   FT)rE   rG   rH   r*   rt   rŠ   r‹   r9   rŒ   r9   r�   r"   r8   r   )FT)rE   rG   rH   r*   r–   r9   rŒ   r9   r�   r"   r8   r   )r;   r˜   rH   r*   r™   rš   r8   r   )FÚ__doc__Ú
__future__r   Úcollectionsr   Úcollections.abcr   r   Ú	functoolsr   Útypingr   r   r	   r
   r   r   r   Úattrsr   r   r   Ú_compatr   r   r   r   r   r   r   r   r   r   r   r1   Údispatchr   r   rb   r   r    Úfnsr!   Úgenr"   r#   r$   r%   r&   r'   r(   r)   r2   Ú
convertersr*   Ú__all__r.   r-   r0   rR   rS   r3   r,   r7   r6   rˆ   r4   r5   r/   r+   r<   r<   r<   r=   Ú<module>   sL    $
0$	






9*ÿ


û/ü
)ý