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rd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 )zA 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 )zIs 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*


/
)