a
    [go                    @  s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dl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 ddlmZmZmZmZ ejZ dZ!d	Z"d
Z#e$i Z%e Z&e'ej(ej)Z*G dd dej+Z,e,j-Z-G dd de.Z/e-ddddddddddddddfddZ0dddZ1dddZ2dd Z3e3dg dZ4dd Z5dd Z6d d! Z7d"d# Z8d$d% Z9d&d' Z:d(d) Z;d*d+ Z<d,d- Z=G d.d/ d/Z>d0d1 Z?d2d3 Z@dd4d5ZAdd6d7ZBeBZCd8d9 ZDd:d; ZEd<d= ZFd>d? ZGd@dA ZHdBdC ZIdDdE ZJddFdGZKdHdI ZLddJdKZMdLdM ZNdNdO ZOdPdQ Z)dRdS ZPdTdU ZQdVdVdWdVdXdYdZZRdVdVdWd[dVd\d]d^ZSdVdVdWdVd_d`daZTdVdVdWd[dVd\dbdcZUdWdWdddedfdgZVdhdWdWdWdWdWdWdddWdWdWdVdidjdkdlZWdVdVdmdndoZXG dpdq dqZYdrds eYjZD Z[eGeKeMeYe[dtduds e[D dtdvds e[D dtZYG dwdx dxZ\eKeMe\Z\G dydz dzZ]d{ds e]jZD Z^eGeKeMe]e^dte^dte^dtZ]G d|d[ d[Z_d}ds d~D Z^eGeKeMe_e^dte^dte^dtZ_efdfddZ`eBdddG dd dZadd Zbdd Z'dS )    )annotationsN)
itemgetter   )_compat_configsetters)PY_3_10_PLUSPY_3_11_PLUSPY_3_13_PLUS_AnnotationExtractor_get_annotationsget_generic_base)DefaultAlreadySetErrorFrozenInstanceErrorNotAnAttrsClassErrorUnannotatedAttributeErrorz__attr_factory_%s)ztyping.ClassVarz
t.ClassVarClassVarztyping_extensions.ClassVarZ_attrs_cached_hashc                   @  s(   e Zd ZdZe Zdd Zdd ZdS )_NothingaF  
    Sentinel to indicate the lack of a value when `None` is ambiguous.

    If extending attrs, you can use ``typing.Literal[NOTHING]`` to show
    that a value may be ``NOTHING``.

    .. versionchanged:: 21.1.0 ``bool(NOTHING)`` is now False.
    .. versionchanged:: 22.2.0 ``NOTHING`` is now an ``enum.Enum`` variant.
    c                 C  s   dS )NNOTHING selfr   r   X/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/attr/_make.py__repr__I   s    z_Nothing.__repr__c                 C  s   dS )NFr   r   r   r   r   __bool__L   s    z_Nothing.__bool__N)	__name__
__module____qualname____doc__enumautor   r   r   r   r   r   r   r   <   s   
r   c                   @  s"   e Zd ZdZeddfddZdS )_CacheHashWrappera  
    An integer subclass that pickles / copies as None

    This is used for non-slots classes with ``cache_hash=True``, to avoid
    serializing a potentially (even likely) invalid hash value. Since `None`
    is the default value for uncalculated hashes, whenever this is copied,
    the copy's value for the hash should automatically reset.

    See GH #613 for more details.
    Nr   c                 C  s   ||fS Nr   )r   Z_none_constructor_argsr   r   r   
__reduce__d   s    z_CacheHashWrapper.__reduce__)r   r   r   r   typer$   r   r   r   r   r!   X   s   r!   TFc                 C  s   t |||d\}}}}|dur:|dur:|dur:d}t||	durr| turVd}t|t|	sjd}t|t|	} |du r~i }t|ttfrt	j
| }|rt|ttfrt| }|rt|ttfrt
| }t| ||d||||||
||||||dS )a  
    Create a new field / attribute on a class.

    Identical to `attrs.field`, except it's not keyword-only.

    Consider using `attrs.field` in new code (``attr.ib`` will *never* go away,
    though).

    ..  warning::

        Does **nothing** unless the class is also decorated with
        `attr.s` (or similar)!


    .. versionadded:: 15.2.0 *convert*
    .. versionadded:: 16.3.0 *metadata*
    .. versionchanged:: 17.1.0 *validator* can be a ``list`` now.
    .. versionchanged:: 17.1.0
       *hash* is `None` and therefore mirrors *eq* by default.
    .. versionadded:: 17.3.0 *type*
    .. deprecated:: 17.4.0 *convert*
    .. versionadded:: 17.4.0
       *converter* as a replacement for the deprecated *convert* to achieve
       consistency with other noun-based arguments.
    .. versionadded:: 18.1.0
       ``factory=f`` is syntactic sugar for ``default=attr.Factory(f)``.
    .. versionadded:: 18.2.0 *kw_only*
    .. versionchanged:: 19.2.0 *convert* keyword argument removed.
    .. versionchanged:: 19.2.0 *repr* also accepts a custom callable.
    .. deprecated:: 19.2.0 *cmp* Removal on or after 2021-06-01.
    .. versionadded:: 19.2.0 *eq* and *order*
    .. versionadded:: 20.1.0 *on_setattr*
    .. versionchanged:: 20.3.0 *kw_only* backported to Python 2
    .. versionchanged:: 21.1.0
       *eq*, *order*, and *cmp* also accept a custom callable
    .. versionchanged:: 21.1.0 *cmp* undeprecated
    .. versionadded:: 22.2.0 *alias*
    TNF6Invalid value for hash.  Must be True, False, or None.z=The `default` and `factory` arguments are mutually exclusive.z*The `factory` argument must be a callable.)default	validatorreprcmphashinit	convertermetadatar%   kw_onlyeqeq_keyorder	order_key
on_setattralias)_determine_attrib_eq_order	TypeErrorr   
ValueErrorcallableFactory
isinstancelisttupler   pipeand__CountingAttr)r'   r(   r)   r*   r+   r,   r.   r%   r-   factoryr/   r0   r2   r4   r5   r1   r3   msgr   r   r   attribh   sR    7
rC    c                 C  s   t | |d}t||| dS )z[
    Evaluate the script with the given global (globs) and local (locs)
    variables.
    execN)compileeval)scriptglobslocsfilenamebytecoder   r   r   _compile_and_eval   s    rM   c           
      C  s~   |du ri n|}d}|}t |d|d|f}tj||}	|	|krFqh|dd  d| d}|d7 }qt|||| ||  S )zO
    Create the method with the script given and return the method object.
    Nr   T->)len
splitlines	linecachecache
setdefaultrM   )
namerH   rK   rI   localsrJ   countbase_filenameZlinecache_tupleZold_valr   r   r   _make_method   s    
rZ   c                 C  sv   |  d}d| ddg}|rJt |D ] \}}|d| d| d q&n
|d ttd	}td
|| || S )z
    Create a tuple subclass to hold `Attribute`s for an `attrs` class.

    The subclass is a bare tuple with properties for names.

    class MyClassAttributes(tuple):
        __slots__ = ()
        x = property(itemgetter(0))
    Z
Attributeszclass z(tuple):z    __slots__ = ()    z% = _attrs_property(_attrs_itemgetter())z    pass)Z_attrs_itemgetterZ_attrs_property
)	enumerateappendr   propertyrM   join)cls_name
attr_namesZattr_class_nameZattr_class_templatei	attr_namerI   r   r   r   _make_attr_tuple_class   s    




rf   _Attributes)attrs
base_attrsZbase_attrs_mapc                 C  s2   t | } | dr(| dr(| dd } | tS )z
    Check whether *annot* is a typing.ClassVar.

    The string comparison hack is used to avoid evaluating all string
    annotations which would put attrs-based classes at a performance
    disadvantage compared to plain old classes.
    )'"r   rN   )str
startswithendswith_CLASSVAR_PREFIXES)Zannotr   r   r   _is_class_var#  s    rp   c                 C  s
   || j v S )zR
    Check whether *cls* defines *attrib_name* (and doesn't just inherit it).
    )__dict__)clsZattrib_namer   r   r   _has_own_attribute4  s    rs   c                 C  s   g }i }t | jdd D ]H}t|dg D ]6}|js*|j|v r@q*|jdd}|| |||j< q*qg }t }t |D ](}|j|v rqv|d| |	|j qv||fS )zQ
    Collect attr.ibs from base classes of *cls*, except *taken_attr_names*.
    r   rN   __attrs_attrs__T	inheritedr   )
reversed__mro__getattrrv   rV   evolver_   setinsertadd)rr   taken_attr_namesri   base_attr_mapbase_clsafilteredseenr   r   r   _collect_base_attrs;  s"    

r   c                 C  sn   g }i }| j dd D ]N}t|dg D ]<}|j|v r6q&|jdd}||j || |||j< q&q||fS )a-  
    Collect attr.ibs from base classes of *cls*, except *taken_attr_names*.

    N.B. *taken_attr_names* will be mutated.

    Adhere to the old incorrect behavior.

    Notably it collects from the front and considers inherited attributes which
    leads to the buggy behavior reported in #428.
    r   rN   rt   Tru   )rx   ry   rV   rz   r}   r_   )rr   r~   ri   r   r   r   r   r   r   _collect_base_attrs_brokenZ  s    

r   c              	     s"  | j t|  |dur$t| }n|du rdd  D }g }t }  D ]X\}	}
t|
rbqP||	 |	t}t	|t
s|tu rt nt|d}||	|f qP|| }t|dkrtddt|fd	d
d d ntdd  D dd
 d} fdd|D }|r6t| dd |D \}}nt| dd |D \}}|rpdd |D }dd |D }|| }d}dd |D D ]H}|du r|jtu rd|}t||du r|jturd}q|dur|| |}dd |D }dd |D }t| j|}t||||fS )a3  
    Transform all `_CountingAttr`s on a class into `Attribute`s.

    If *these* is passed, use that and don't look for them on the class.

    If *collect_by_mro* is True, collect them in the correct MRO order,
    otherwise use the old -- incorrect -- order.  See #428.

    Return an `_Attributes`.
    NTc                 S  s   h | ]\}}t |tr|qS r   r;   r@   .0rV   attrr   r   r   	<setcomp>  s   
z#_transform_attrs.<locals>.<setcomp>r'   r   z1The following `attr.ib`s lack a type annotation: , c                   s     | jS r"   )getcounter)n)cdr   r   <lambda>      z"_transform_attrs.<locals>.<lambda>)key.c                 s  s$   | ]\}}t |tr||fV  qd S r"   r   r   r   r   r   	<genexpr>  s   
z#_transform_attrs.<locals>.<genexpr>c                 S  s
   | d j S Nr   )r   )er   r   r   r     r   c                   s&   g | ]\}}t j|| |d qS ))rV   car%   )	Attributefrom_counting_attrr   )r   re   r   )annsr   r   
<listcomp>  s   z$_transform_attrs.<locals>.<listcomp>c                 S  s   h | ]
}|j qS r   rV   r   r   r   r   r   r     r   c                 S  s   h | ]
}|j qS r   r   r   r   r   r   r     r   c                 S  s   g | ]}|j d dqS T)r/   rz   r   r   r   r   r     r   c                 S  s   g | ]}|j d dqS r   r   r   r   r   r   r     r   Fc                 s  s&   | ]}|j d ur|jd u r|V  qdS )FN)r,   r/   r   r   r   r   r     r   zlNo mandatory attributes allowed after an attribute with a default value or factory.  Attribute in question: c                 S  s(   g | ] }|j s |jt|jd n|qS ))r5   )r5   rz   _default_init_alias_forrV   r   r   r   r   r     s   c                 S  s   g | ]
}|j qS r   r   r   r   r   r   r     r   )rq   r   r<   itemsr{   rp   r}   r   r   r;   r@   rC   r_   rQ   r   ra   sortedr   r   r'   r8   rf   r   rg   )rr   theseauto_attribsr/   collect_by_mrofield_transformerZca_listZca_namesZannot_namesre   r%   r   ZunannotatedZ	own_attrsri   r   rh   Zhad_defaultrB   rc   Z
AttrsClassr   )r   r   r   _transform_attrsv  s    

	




r   c                 C  sl   g d}|d ur| d n|g d |ddg t|d}| tj|d}tdd	|||d
|idS )N)	zdef wrapper(_cls):z    __class__ = _clsz    def __getattr__(self, item, cached_properties=cached_properties, original_getattr=original_getattr, _cached_setattr_get=_cached_setattr_get):z+         func = cached_properties.get(item)z         if func is not None:z!              result = func(self)z1              _setter = _cached_setattr_get(self)z#              _setter(item, result)z              return resultz,         return original_getattr(self, item))z         try:z2             return super().__getattribute__(item)z         except AttributeError:z4             if not hasattr(super(), '__getattr__'):z                 raisez-             return super().__getattr__(item)zY         original_error = f"'{self.__class__.__name__}' object has no attribute '{item}'"z-         raise AttributeError(original_error)z    return __getattr__z__getattr__ = wrapper(_cls)ry   )cached_properties_cached_setattr_getoriginal_getattr__getattr__r]   _cls)rW   )r_   extend_generate_unique_filename_OBJ_SETATTR__get__rZ   ra   )r   r   rr   linesunique_filenameglobr   r   r   _make_cached_property_getattr  s4    
r   c                 C  s,   t | tr$|dv r$t| || dS tdS )z4
    Attached to frozen classes as __setattr__.
    )	__cause____context____traceback____suppress_context__	__notes__N)r;   BaseException__setattr__r   r   rV   valuer   r   r   _frozen_setattrs  s    r   c                 C  s*   t | tr"|dv r"t| | dS tdS )z4
    Attached to frozen classes as __delattr__.
    )r   N)r;   r   __delattr__r   )r   rV   r   r   r   _frozen_delattrs.  s    r   c            	      O  s   z
| \}W n, t y6   dt|  d}t|dY n0 |j}t|}|D ].}|jsVqJ|j}|j}||vrJt||||< qJ|f i |S )a  
    Create a new instance, based on the first positional argument with
    *changes* applied.

    .. tip::

       On Python 3.13 and later, you can also use `copy.replace` instead.

    Args:

        inst:
            Instance of a class with *attrs* attributes. *inst* must be passed
            as a positional argument.

        changes:
            Keyword changes in the new copy.

    Returns:
        A copy of inst with *changes* incorporated.

    Raises:
        TypeError:
            If *attr_name* couldn't be found in the class ``__init__``.

        attrs.exceptions.NotAnAttrsClassError:
            If *cls* is not an *attrs* class.

    .. versionadded:: 17.1.0
    .. deprecated:: 23.1.0
       It is now deprecated to pass the instance using the keyword argument
       *inst*. It will raise a warning until at least April 2024, after which
       it will become an error. Always pass the instance as a positional
       argument.
    .. versionchanged:: 24.1.0
       *inst* can't be passed as a keyword argument anymore.
    z*evolve() takes 1 positional argument, but z were givenN)	r8   rQ   r7   	__class__fieldsr,   rV   r5   ry   )	argschangesinstrB   rr   rh   r   re   Z	init_namer   r   r   rz   9  s     %
rz   c                   @  s   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'S )(_ClassBuilderz(
    Iteratively build *one* class.
    )_attr_names_attrs_base_attr_map_base_names_cache_hashr   	_cls_dict_delete_attribs_frozen_has_custom_setattr_has_post_init_has_pre_init_is_exc_on_setattr_pre_init_has_args_slots_weakref_slot_wrote_own_setattrc                 C  s  t ||||||\}}}|| _|r,t|jni | _|| _dd |D | _|| _tdd |D | _	|| _
|| _|| _|	| _tt|dd| _d| _| jr|j}t|}t|jdk| _tt|dd| _t| | _|
| _|| _|| _d| _| j| jd	< |rt| jd
< t| jd< d| _n|tt j!t j"fv rd }}|D ]8}|j#d urPd}|j$d ur`d}|r<|r< qvq<|tkr|s|r|t j!kr|r|t j"kr|sd | _|r| % \| jd< | jd< d S )Nc                 S  s   h | ]
}|j qS r   r   r   r   r   r   r     r   z)_ClassBuilder.__init__.<locals>.<setcomp>c                 s  s   | ]}|j V  qd S r"   r   r   r   r   r   r     r   z)_ClassBuilder.__init__.<locals>.<genexpr>__attrs_pre_init__Fr   __attrs_post_init__rt   r   r   T__getstate____setstate__)&r   r   dictrq   r   r   r   r   r=   r   r   r   r   r   boolry   r   r   r   inspect	signaturerQ   
parametersr   r   r   r   r   r   r   r   _DEFAULT_ON_SETATTRr   validateconvertr(   r-   _make_getstate_setstate)r   rr   r   slotsfrozenweakref_slotgetstate_setstater   r/   
cache_hashis_excr   r4   Zhas_custom_setattrr   rh   ri   Zbase_mapZpre_init_funcZpre_init_signatureZhas_validatorZhas_converterr   r   r   r   __init__  s    
	



z_ClassBuilder.__init__c                 C  s   d| j j dS )Nz<_ClassBuilder(cls=z)>)r   r   r   r   r   r   r     s    z_ClassBuilder.__repr__c                 C  sL   | j du r|  }n|  }tr*t|}t|ddrHd|jvrH|  |S )z
        Finalize class based on the accumulated configuration.

        Builder cannot be used after calling this method.
        T__attrs_init_subclass__N)	r   _create_slots_class_patch_original_classr   abcZupdate_abstractmethodsry   rq   r   )r   rr   r   r   r   build_class  s    



z_ClassBuilder.build_classc              	   C  s   | j }| j}| jrj| jD ]P}||vrt||tturtt t	|| W d   q1 s^0    Y  q| j
 D ]\}}t||| qt| jst|ddrd|_| jst|_|S )zA
        Apply accumulated methods and return the class.
        N__attrs_own_setattr__F)r   r   r   r   ry   	_SENTINEL
contextlibsuppressAttributeErrordelattrr   r   setattrr   r   r   r   r   )r   rr   
base_namesrV   r   r   r   r   r     s&    
*z#_ClassBuilder._patch_original_classc              
     s  fddj  D }jsTd|d< jsTjjD ]  jddr4t|d<  qTq4i }d}jj	dd D ]:  jdd	d	urd
}|
 fddt dg D  qltjj}jrdtjddvrd|vr|s|d7 }dd | D }g }|rtj}| D ]F\}}	||f7 }||= ||	 t|	j}
|
tjjur|
||< q|d}|d	urx|| t||j|d< fdd|D fdd| D fddD |
 jrt t|d< jj|d< tjjjjj|}t|j  |D ]}t!|t"t#frHt|j$dd	}n(t!|t%rdt|j&dd	}nt|dd	}|szq$|D ]8}z|j'ju }W n t(y   Y n0 |r~||_'q~q$|S )zL
        Build and return a new class with a `__slots__` attribute.
        c                   s2   i | ]*\}}|g t  jd dR vr||qS )rq   __weakref__)r=   r   r   kvr   r   r   
<dictcomp>+  s   z5_ClassBuilder._create_slots_class.<locals>.<dictcomp>Fr   r   r   rN   r   NTc                   s   i | ]}|t  |qS r   ry   r   rV   )r   r   r   r   J  s   	__slots__r   )r   c                 S  s$   i | ]\}}t |tjr||jqS r   )r;   	functoolscached_propertyfunc)r   rV   r  r   r   r   r   [  s   r   c                   s   g | ]}| vr|qS r   r   r   )r   r   r   r   z  r   z5_ClassBuilder._create_slots_class.<locals>.<listcomp>c                   s   i | ]\}}| v r||qS r   r   )r   ZslotZslot_descriptor)
slot_namesr   r   r     s   c                   s   g | ]}| vr|qS r   r   r   )reused_slotsr   r   r     r   r   __closure__))r   r   r   r   r   	__bases__rq   r   r   rx   updatery   r{   r   r   r   r   r_   r   r   return_annotation	Parameteremptyr   r   _HASH_CACHE_FIELDr=   r   r%   r   	itertoolschainvaluesr;   classmethodstaticmethod__func__r`   fgetcell_contentsr8   )r   r   Zexisting_slotsZweakref_inheritednamesr   Z&additional_closure_functions_to_updateZclass_annotationsrV   r  
annotationr   rr   itemZclosure_cellscellmatchr   )r   r   r  r   r  r   r   '  s    













z!_ClassBuilder._create_slots_classc                 C  s    |  t| j|| j| jd< | S )Nr   )_add_method_dunders
_make_reprr   r   r   )r   nsr   r   r   add_repr  s    
z_ClassBuilder.add_reprc                 C  s<   | j d}|d u r d}t|dd }| || j d< | S )Nr   z3__str__ can only be generated if a __repr__ exists.c                 S  s   |   S r"   r   r   r   r   r   __str__  s    z&_ClassBuilder.add_str.<locals>.__str__r   )r   r   r8   r  )r   r)   rB   r   r   r   r   add_str  s    z_ClassBuilder.add_strc                   s<   t dd | jD fdd}| j  fdd}||fS )zF
        Create custom __setstate__ and __getstate__ methods.
        c                 s  s   | ]}|d kr|V  qdS )r   Nr   )r   Zanr   r   r   r     s   z8_ClassBuilder._make_getstate_setstate.<locals>.<genexpr>c                   s    fddD S )9
            Automatically created by attrs.
            c                   s   i | ]}|t  |qS r   r   r   r   r   r   r     r   zQ_ClassBuilder._make_getstate_setstate.<locals>.slots_getstate.<locals>.<dictcomp>r   r   )state_attr_namesr   r   slots_getstate  s    z=_ClassBuilder._make_getstate_setstate.<locals>.slots_getstatec                   sf   t | }t|tr4t|D ]\}}||| qn D ]}||v r8||||  q8 rb|td dS )r"  N)r   r   r;   r=   zipr  )r   stateZ_ClassBuilder__bound_setattrrV   r   Zhash_caching_enabledr#  r   r   slots_setstate  s    

z=_ClassBuilder._make_getstate_setstate.<locals>.slots_setstate)r=   r   r   )r   r$  r(  r   r'  r   r     s    z%_ClassBuilder._make_getstate_setstatec                 C  s   d | j d< | S )N__hash__)r   r   r   r   r   make_unhashable  s    
z_ClassBuilder.make_unhashablec                 C  s(   |  t| j| j| j| jd| jd< | S )Nr   r   r)  )r  
_make_hashr   r   r   r   r   r   r   r   r   add_hash  s    
	z_ClassBuilder.add_hashc                 C  sF   |  t| j| j| j| j| j| j| j| j	| j
| j| jdd| jd< | S )NF
attrs_initr   r  
_make_initr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   add_init  s"    
z_ClassBuilder.add_initc                 C  s   |  dd | jd< | S )Nc                 [  s   t | fi |S r"   r   )r   r   r   r   r   r     r   z+_ClassBuilder.add_replace.<locals>.<lambda>__replace__)r  r   r   r   r   r   add_replace  s    
z_ClassBuilder.add_replacec                 C  s   t dd | jD | jd< d S )Nc                 s  s    | ]}|j r|js|jV  qd S r"   )r,   r/   rV   )r   fieldr   r   r   r     s   z/_ClassBuilder.add_match_args.<locals>.<genexpr>__match_args__)r=   r   r   r   r   r   r   add_match_args  s    z_ClassBuilder.add_match_argsc                 C  sF   |  t| j| j| j| j| j| j| j| j	| j
| j| jdd| jd< | S )NTr.  __attrs_init__r0  r   r   r   r   add_attrs_init  s"    
z_ClassBuilder.add_attrs_initc                 C  s2   | j }| t| j| j|d< | t |d< | S )N__eq____ne__)r   r  _make_eqr   r   _make_ner   r   r   r   r   add_eq2  s    z_ClassBuilder.add_eqc                   s>    j } fddt j jD \|d< |d< |d< |d<  S )Nc                 3  s   | ]}  |V  qd S r"   )r  )r   methr   r   r   r   ?  s   z*_ClassBuilder.add_order.<locals>.<genexpr>__lt____le____gt____ge__)r   _make_orderr   r   r>  r   r   r   	add_order<  s
    
z_ClassBuilder.add_orderc                   s   | j r
| S i  | jD ],}|jp"| j}|r|tjur||f |j< q sJ| S | jr\d}t| fdd}d| j	d< | 
|| j	d< d| _| S )Nz7Can't combine custom __setattr__ with on_setattr hooks.c                   sD   z | \}}W n t y&   |}Y n0 || ||}t| || d S r"   )KeyErrorr   )r   rV   valr   hookZnvalZsa_attrsr   r   r   Y  s    
z._ClassBuilder.add_setattr.<locals>.__setattr__Tr   r   )r   r   r4   r   r   NO_OPrV   r   r8   r   r  r   )r   r   r4   rB   r   r   rJ  r   add_setattrF  s"    


z_ClassBuilder.add_setattrc                 C  s   t t | jj|_W d   n1 s*0    Y  t t& | jj d|j |_W d   n1 sj0    Y  t t" d| jj d|_W d   n1 s0    Y  |S )zL
        Add __module__ and __qualname__ to a *method* if possible.
        Nr   z$Method generated by attrs for class )r   r   r   r   r   r   r   r   )r   methodr   r   r   r  i  s    (4"z!_ClassBuilder._add_method_dundersN)r   r   r   r   r  r   r   r   r   r   r  r!  r   r*  r-  r2  r4  r7  r9  r?  rF  rL  r  r   r   r   r   r   s  s*   \$ )

#r   c                 C  st   | dur(t |du|dufr(d}t|| dur8| | fS |du rD|}|du rP|}|du rl|du rld}t|||fS )
    Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
    values of eq and order.  If *eq* is None, set it to *default_eq*.
    N&Don't mix `cmp` with `eq' and `order`.FT-`order` can only be True if `eq` is True too.anyr8   )r*   r0   r2   
default_eqrB   r   r   r   _determine_attrs_eq_order|  s    rT  c           	      C  s   | dur(t |du|dufr(d}t|dd }| durP|| \} }| || |fS |du rd|d }}n||\}}|du r|| }}n||\}}|du r|du rd}t|||||fS )rN  NrO  c                 S  s    t | rd|  } }nd}| |fS )z8
        Decide whether a key function is used.
        TN)r9   )r   r   r   r   r   decide_callable_or_boolean  s    z>_determine_attrib_eq_order.<locals>.decide_callable_or_booleanFTrP  rQ  )	r*   r0   r2   rS  rB   rU  Zcmp_keyr1   r3   r   r   r   r6     s"    r6   c                 C  sF   |du s|du r|S |du r(|du r(|S |D ]}t | |r, dS q,|S )ap  
    Check whether we should implement a set of methods for *cls*.

    *flag* is the argument passed into @attr.s like 'init', *auto_detect* the
    same as passed into @attr.s and *dunders* is a tuple of attribute names
    whose presence signal that the user has implemented it themselves.

    Return *default* if no reason for either for or against is found.
    TFN)rs   )rr   flagauto_detectZdundersr'   dunderr   r   r   _determine_whether_to_implement  s    
rY  c                   s   dur"ddl }|jtddd t|||d\|dur@|	tttfrXtj  	
fdd}| du r|S || S )a  
    A class decorator that adds :term:`dunder methods` according to the
    specified attributes using `attr.ib` or the *these* argument.

    Consider using `attrs.define` / `attrs.frozen` in new code (``attr.s`` will
    *never* go away, though).

    Args:
        repr_ns (str):
            When using nested classes, there was no way in Python 2 to
            automatically detect that.  This argument allows to set a custom
            name for a more meaningful ``repr`` output.  This argument is
            pointless in Python 3 and is therefore deprecated.

    .. caution::
        Refer to `attrs.define` for the rest of the parameters, but note that they
        can have different defaults.

        Notably, leaving *on_setattr* as `None` will **not** add any hooks.

    .. versionadded:: 16.0.0 *slots*
    .. versionadded:: 16.1.0 *frozen*
    .. versionadded:: 16.3.0 *str*
    .. versionadded:: 16.3.0 Support for ``__attrs_post_init__``.
    .. versionchanged:: 17.1.0
       *hash* supports `None` as value which is also the default now.
    .. versionadded:: 17.3.0 *auto_attribs*
    .. versionchanged:: 18.1.0
       If *these* is passed, no attributes are deleted from the class body.
    .. versionchanged:: 18.1.0 If *these* is ordered, the order is retained.
    .. versionadded:: 18.2.0 *weakref_slot*
    .. deprecated:: 18.2.0
       ``__lt__``, ``__le__``, ``__gt__``, and ``__ge__`` now raise a
       `DeprecationWarning` if the classes compared are subclasses of
       each other. ``__eq`` and ``__ne__`` never tried to compared subclasses
       to each other.
    .. versionchanged:: 19.2.0
       ``__lt__``, ``__le__``, ``__gt__``, and ``__ge__`` now do not consider
       subclasses comparable anymore.
    .. versionadded:: 18.2.0 *kw_only*
    .. versionadded:: 18.2.0 *cache_hash*
    .. versionadded:: 19.1.0 *auto_exc*
    .. deprecated:: 19.2.0 *cmp* Removal on or after 2021-06-01.
    .. versionadded:: 19.2.0 *eq* and *order*
    .. versionadded:: 20.1.0 *auto_detect*
    .. versionadded:: 20.1.0 *collect_by_mro*
    .. versionadded:: 20.1.0 *getstate_setstate*
    .. versionadded:: 20.1.0 *on_setattr*
    .. versionadded:: 20.3.0 *field_transformer*
    .. versionchanged:: 21.1.0
       ``init=False`` injects ``__attrs_init__``
    .. versionchanged:: 21.1.0 Support for ``__attrs_pre_init__``
    .. versionchanged:: 21.1.0 *cmp* undeprecated
    .. versionadded:: 21.3.0 *match_args*
    .. versionadded:: 22.2.0
       *unsafe_hash* as an alias for *hash* (for :pep:`681` compliance).
    .. deprecated:: 24.1.0 *repr_ns*
    .. versionchanged:: 24.1.0
       Instances are not compared as tuples of attributes anymore, but using a
       big ``and`` condition. This is faster and has more correct behavior for
       uncomparable values like `math.nan`.
    .. versionadded:: 24.1.0
       If a class has an *inherited* classmethod called
       ``__attrs_init_subclass__``, it is executed after the class is created.
    .. deprecated:: 24.1.0 *hash* is deprecated in favor of *unsafe_hash*.
    Nr   zQThe `repr_ns` argument is deprecated and will be removed in or after August 2025.   )
stacklevelc                   s  p
t | }du ot| t}o*t| d}|r@|r@d}t|t| |t| dd ||}t| dr| du r|  t| d}|s|du r|	  |st| dr|
  |  	d u rdu rt| d	rd
		dur$	d
ur$	d ur$d}t|	d
u sH	d u rB|d
u sH|r\rd}t|nL	du s	d u r|du r|du r|  nrd}t||  t| 
dr|  n|  rd}t|trt| ds|  trrt| ds|  | S )NTr   z/Can't freeze a class with a custom __setattr__.)r   r   r   r  )r:  r;  )rA  rB  rC  rD  r)  Fr&   zlInvalid value for cache_hash.  To use hash caching, hashing must be either explicitly or implicitly enabled.r   zFInvalid value for cache_hash.  To use hash caching, init must be True.r3  r6  )_has_frozen_base_class
issubclassr   rs   r8   r   rY  r  r!  r?  rF  rL  r7   r-  r*  r2  r9  r
   r4  r   r7  r   )rr   	is_frozenr   Zhas_own_setattrrB   Zbuilderr0   r   rW  auto_excr   r   Zeq_r   r   r   r+   r,   r/   
match_argsr4   Zorder_r)   repr_nsr   rl   r   r   r   r   wrapL  s    
$



zattrs.<locals>.wrap)	warningswarnDeprecationWarningrT  r;   r<   r=   r   r>   )Z	maybe_clsr   rc  r)   r*   r+   r,   r   r   r   rl   r   r/   r   ra  r0   r2   rW  r   r   r4   r   rb  unsafe_hashre  rd  r   r`  r   rh     s"    \
4krh   c                 C  s
   | j tu S )zV
    Check whether *cls* has a frozen ancestor by looking at its
    __setattr__.
    )r   r   )rr   r   r   r   r]    s    r]  c              	   C  s$   d| d| j  dt| d| j dS )zF
    Create a "filename" suitable for a function being generated.
    z<attrs generated  r   r   rP   )r   ry   r   )rr   	func_namer   r   r   r     s    r   c           	        s  t dd  D  d}t| d}t|i d}dd|sF|d7 }n |d	7 }|d
7 }d d7 |g fdd}|r|dt d  |r|dt d|d  |d d  n|dt d|d  |dt   n
|d| d}td||S )Nc                 s  s0   | ](}|j d u s$|j du r|jd u r|V  qdS )TN)r+   r0   r   r   r   r   r     s   z_make_hash.<locals>.<genexpr>        r+   zdef __hash__(selfzhash((r\   z):z, *zC, _cache_wrapper=__import__('attr._make')._make._CacheHashWrapper):z_cache_wrapper()c              	     s    ||   |d d g  D ]Z}|jrhd|j d}|j|< |d| d|j d  q&|d|j d  q&|d   d	S )
z
        Generate the code for actually computing the hash code.
        Below this will either be returned directly or used to compute
        a value which is then cached, depending on the value of cache_hash
        rk  ,__key(self.z),        self.r[   N)r   r1   rV   r_   )prefixindentr   cmp_namerh   Zclosing_bracesrI   Z	hash_funcZmethod_linesZ	type_hashr   r   append_hash_computation_lines  s    

z1_make_hash.<locals>.append_hash_computation_lineszif self.z	 is None:zobject.__setattr__(self, '', rZ  self. = zreturn self.zreturn r]   r)  )r=   r   r+   r_   r  ra   rZ   )	rr   rh   r   r   tabr   Zhash_defrv  rH   r   ru  r   r,    s@    



r,  c                 C  s   t | |ddd| _| S )z%
    Add a hash method to *cls*.
    Fr+  )r,  r)  rr   rh   r   r   r   	_add_hash  s    r|  c                  C  s   dd } | S )z
    Create __ne__ method.
    c                 S  s   |  |}|tu rtS | S )zj
        Check equality and either forward a NotImplemented or
        return the result negated.
        )r:  NotImplemented)r   otherresultr   r   r   r;  *  s    
z_make_ne.<locals>.__ne__r   )r;  r   r   r   r=  %  s    r=  c                 C  s   dd |D }t | d}g d}i }|r|d |D ]}|jrd|j d}|j||< |d| d	|j d
| d|j d	 n|d|j d|j  ||d ur6|d  d|d< q6|d n
|d d|}td|||S )z6
    Create __eq__ method for *cls* with *attrs*.
    c                 S  s   g | ]}|j r|qS r   )r0   r   r   r   r   r   <  r   z_make_eq.<locals>.<listcomp>r0   )zdef __eq__(self, other):z-    if other.__class__ is not self.__class__:z        return NotImplementedz    return  (rn  ro  rk  rp  z) == z(other.rl  rq  z
 == other.rN   z andz    )z    return Truer]   r:  )r   r_   r1   rV   ra   rZ   )rr   rh   r   r   rI   r   rt  rH   r   r   r   r<  8  s(    


 

r<  c                   sV   dd  D   fddfdd}fdd}fd	d
}fdd}||||fS )z9
    Create ordering methods for *cls* with *attrs*.
    c                 S  s   g | ]}|j r|qS r   )r2   r   r   r   r   r   b  r   z_make_order.<locals>.<listcomp>c                   s    t dd  fddD D S )z&
        Save us some typing.
        c                 s  s"   | ]\}}|r||n|V  qd S r"   r   )r   r   r   r   r   r   r   h  s   z6_make_order.<locals>.attrs_to_tuple.<locals>.<genexpr>c                 3  s    | ]}t  |j|jfV  qd S r"   )ry   rV   r3   r   objr   r   r   j  s   )r=   r  rh   r  r   attrs_to_tupled  s
    
z#_make_order.<locals>.attrs_to_tuplec                   s    |j | j u r |  |k S tS z1
        Automatically created by attrs.
        r   r}  r   r~  r  r   r   rA  o  s    z_make_order.<locals>.__lt__c                   s    |j | j u r |  |kS tS r  r  r  r  r   r   rB  x  s    z_make_order.<locals>.__le__c                   s    |j | j u r |  |kS tS r  r  r  r  r   r   rC    s    z_make_order.<locals>.__gt__c                   s    |j | j u r |  |kS tS r  r  r  r  r   r   rD    s    z_make_order.<locals>.__ge__r   )rr   rh   rA  rB  rC  rD  r   )rh   r  r   rE  ^  s    				rE  c                 C  s&   |du r| j }t| || _t | _| S )z5
    Add equality methods to *cls* with *attrs*.
    N)rt   r<  r:  r=  r;  r{  r   r   r   _add_eq  s
    r  c                 C  s   t |d}tdd | D }dd |D }t|d< t|d< t|d< g }|D ]N\}}}	|	r`d	| n
d
| d }
|tkrd||
f nd|||
f }|| qJd|}|d u rd}n|d }ddddddddddddd| d| ddd g}td!d"|||d#S )$Nr)   c                 s  s6   | ].}|j d ur|j|j du r"t n|j |jfV  qdS )FTN)r)   rV   r,   r   r   r   r   r     s   
z_make_repr.<locals>.<genexpr>c                 S  s$   i | ]\}}}|t kr|d  |qS )_repr)r)   )r   rV   rrn  r   r   r   r     s   z_make_repr.<locals>.<dictcomp>r   r   r   rx  zgetattr(self, "z", NOTHING)z	%s={%s!r}z%s={%s_repr(%s)}r   z1{self.__class__.__qualname__.rsplit(">.", 1)[-1]}z.{self.__class__.__name__}zdef __repr__(self):z  try:z:    already_repring = _compat.repr_context.already_repringz  except AttributeError:z!    already_repring = {id(self),}z:    _compat.repr_context.already_repring = already_repringz  else:z#    if id(self) in already_repring:z      return '...'z	    else:z#      already_repring.add(id(self))z    return f'(z)'z
  finally:z$    already_repring.remove(id(self))r   r]   )rI   )	r   r=   r   r   r   r)   r_   ra   rZ   )rh   r  rr   r   Zattr_names_with_reprsrI   Zattribute_fragmentsrV   r  rd   accessorfragmentZrepr_fragmentZcls_name_fragmentr   r   r   r   r    sT    

r  c                 C  s    |du r| j }t||| | _| S )z%
    Add a repr method to *cls*.
    N)rt   r  r   )rr   r  rh   r   r   r   	_add_repr  s    r  c                 C  sv   t | }|du r&t| ts&d}t|t| dd}|du rr|dur`t|dd}|dur`|| _|S | d}t||S )aG  
    Return the tuple of *attrs* attributes for a class.

    The tuple also allows accessing the fields by their names (see below for
    examples).

    Args:
        cls (type): Class to introspect.

    Raises:
        TypeError: If *cls* is not a class.

        attrs.exceptions.NotAnAttrsClassError:
            If *cls* is not an *attrs* class.

    Returns:
        tuple (with name accessors) of `attrs.Attribute`

    .. versionchanged:: 16.2.0 Returned tuple allows accessing the fields
       by name.
    .. versionchanged:: 23.1.0 Add support for generic classes.
    NPassed object must be a class.rt   ! is not an attrs-decorated class.)r   r;   r%   r7   ry   rt   r   )rr   Zgeneric_baserB   rh   r   r   r   r     s    
r   c                 C  sJ   t | tsd}t|t| dd}|du r<| d}t|dd |D S )a  
    Return an ordered dictionary of *attrs* attributes for a class, whose keys
    are the attribute names.

    Args:
        cls (type): Class to introspect.

    Raises:
        TypeError: If *cls* is not a class.

        attrs.exceptions.NotAnAttrsClassError:
            If *cls* is not an *attrs* class.

    Returns:
        dict[str, attrs.Attribute]: Dict of attribute name to definition

    .. versionadded:: 18.1.0
    r  rt   Nr  c                 S  s   i | ]}|j |qS r   r   r   r   r   r   r   /  r   zfields_dict.<locals>.<dictcomp>)r;   r%   r7   ry   r   )rr   rB   rh   r   r   r   fields_dict  s    

r  c                 C  sD   t jdu rdS t| jD ]&}|j}|dur|| |t| |j qdS )z
    Validate all attributes on *inst* that have a validator.

    Leaves all exceptions through.

    Args:
        inst: Instance of a class with *attrs* attributes.
    FN)r   Z_run_validatorsr   r   r(   ry   rV   )r   r   r   r   r   r   r   2  s    	
r   c                 C  s   | | }|od|jv S )z>
    Check if the attribute name comes from a slot class.
    r  )r   rq   )a_namer   rr   r   r   r   _is_slot_attrD  s    
r  c                 C  s6  |
d uo|
t ju}|r&|r&d}t||p,|}g }i }|D ]b}|jsP|jtu rPq:|| |||j< |jd ur|du rd}t|d}q:|r:|jt jur:d}q:t	| d}t
|||||||||	|||rdnd\}}}| jtjv r|tj| j j |t|d |rtj|d< t|r dnd|||}||_|S )Nz$Frozen classes can't use on_setattr.Tr,   r8  r   )r   	attr_dictr   )r   rK  r8   r,   r'   r   r_   rV   r4   r   _attrs_to_init_scriptr   sysmodulesr	  rq   r   r   rZ   __annotations__)rr   rh   pre_initpre_init_has_args	post_initr   r   r   r   r   Zcls_on_setattrr/  has_cls_on_setattrrB   needs_cached_setattrZfiltered_attrsr  r   r   rH   rI   r   r,   r   r   r   r1  L  s`    






r1  rl   r   re   	value_varhas_on_setattrreturnc                 C  s   d|  d| dS )zJ
    Use the cached object.setattr to set *attr_name* to *value_var*.
    
_setattr('rw  rl  r   re   r  r  r   r   r   _setattr  s    r  	Converterre   r  r  r-   r  c                 C  s   d|  d| | | dS )zk
    Use the cached object.setattr to set *attr_name* to *value_var*, but run
    its converter first.
    r  rw  rl  )_fmt_converter_callre   r  r  r-   r   r   r   _setattr_with_converter  s    r  )re   r   r  r  c                 C  s    |rt | |dS d|  d| S )zo
    Unless *attr_name* has an on_setattr hook, use normal assignment. Otherwise
    relegate to _setattr.
    Trx  ry  )r  )re   r   r  r   r   r   _assign  s    r  c                 C  s*   |rt | |d|S d|  d|| | S )z
    Unless *attr_name* has an on_setattr hook, use normal assignment after
    conversion. Otherwise relegate to _setattr_with_converter.
    Trx  ry  )r  r  r  r   r   r   _assign_with_converter  s    r  zdict[str, type])r   r   r   c                   s`   | du rV|du rdt tfS ddddd fdd}dddddd	 fd
d}d||fS dttfS )zg
    Determine the correct setter functions based on whether a class is frozen
    and/or slotted.
    Tr   rl   r   r  c                   s&   t |  rt| ||S d|  d| S N_inst_dict['z'] = )r  r  r  r   r   r   
fmt_setter  s    
z&_determine_setters.<locals>.fmt_setterr  r  c                   s4   |st |  rt| |||S d|  d|| | S r  )r  r  r  r  r  r   r   fmt_setter_with_converter  s
    z5_determine_setters.<locals>.fmt_setter_with_converter)z_inst_dict = self.__dict__)r  r  r  r  )r   r   r   r  r  r   r  r   _determine_setters  s    
r  zlist[Attribute]ztuple[str, dict, dict])rh   r_  
is_slottedcall_pre_initr  call_post_initdoes_cache_hashr   r   r  r  method_namer  c           $   
   C  s  |r
dgng }|	r| d t|||\}}}|| g }g }g }i }ddi}| D ]}|jrj| | |j}|jdup|jtjuo|
}|j}t	|j
t}|r|j
jrdnd}|jdurt	|jtst|j}n|j}|jdu r|r`t|jf }|dur4| |||d| d	 || |j|||j< n| |||d| d	 | |j
j||< nT|dur| ||d
| d|| |j|||j< n| ||d
| d| n|j
tur@|s@| d| d}|jr| | n
| | |dur*| ||||| |j|||j< n| |||| nb|r@| d}|jrd| | n
| | | d| d t|jf }|dur| d|||||  | d | d|||d | d	 ||  |j|||j< nB| d||||  | d | d|||d | d	 |  |j
j||< nb|jrT| | n
| | |dur| ||||| |j|||j< n| |||| |jdu rT|jdur|du r|j||< qT|durT|jrT|j||< qT|rRt|d< | d |D ]L}d|j }d|j }| d| d| d|j d	 |j||< |||< q|rb| d |r|r|rdt d}ndt d}ndt d}| | |rd d!d" | D } | d#|  d	 d$|}|}!|r@||rd$nd d%d$| 7 }d$d&d' d(d" |D D }"|!|!r2d$nd7 }!|!|"7 }!|r\|r\d)|! d	|d*< d+}#d,| d| d-|r~|#|nd. d/||fS )0z
    Return a script of an initializer for *attrs*, a dict of globals, and
    annotations for the initializer.

    The globals are required by the generated script.
    zself.__attrs_pre_init__()z$_setattr = _cached_setattr_get(self)r  Nr   rD   Fr  rl  zattr_dict['z
'].defaultz=attr_dict['z=NOTHINGzif z is not NOTHING:r[   zelse:Tr   z#if _config._run_validators is True:Z__attr_validator_Z__attr_z(self, z, self.zself.__attrs_post_init__()r  z', None)r  z	'] = Nonerx  z = Nonerm  c                 s  s    | ]}|j rd |j V  qdS )rx  N)r,   rV   r   r   r   r   r     r   z(_attrs_to_init_script.<locals>.<genexpr>zBaseException.__init__(self, r   z*, c                 S  s   g | ]}| d | qS )=r   )r   Zkw_arg_namer   r   r   r     s   z)_attrs_to_init_script.<locals>.<listcomp>c                 s  s   | ]}| d d V  qdS )r  r   N)split)r   Zkwar   r   r   r     r   zself.__attrs_pre_init__(r   z
    zdef z):
    passr]   )r_   r  r   r(   rV   r4   r   rK  r5   r;   r'   r:   
takes_selfr-   r  r,   _INIT_FACTORY_PAT_get_global_namerA   r   r/   r%   _first_param_typer   r  ra   )$rh   r_  r  r  r  r  r  r   r   r  r  r  r   extra_linesr  r  r   Zkw_only_argsZattrs_to_validateZnames_for_globalsr   r   re   r  Zarg_nameZhas_factoryZ
maybe_selfr-   Zinit_factory_nameargZval_nameZinit_hash_cachevalsZpre_init_argsZpre_init_kw_only_argsNLr   r   r   r    sj   





	

	














 



"r  )rV   r  c                 C  s
   |  dS )z
    The default __init__ parameter name for a field.

    This performs private-name adjustment via leading-unscore stripping,
    and is the default value of Attribute.alias if not provided.
    rn  )lstripr   r   r   r   r     s    r   c                
   @  sT   e Zd ZdZdZdddZdd Zedd	d
Zdd Z	dd Z
dd Zdd ZdS )r   a  
    *Read-only* representation of an attribute.

    .. warning::

       You should never instantiate this class yourself.

    The class has *all* arguments of `attr.ib` (except for ``factory`` which is
    only syntactic sugar for ``default=Factory(...)`` plus the following:

    - ``name`` (`str`): The name of the attribute.
    - ``alias`` (`str`): The __init__ parameter name of the attribute, after
      any explicit overrides and default private-attribute-name handling.
    - ``inherited`` (`bool`): Whether or not that attribute has been inherited
      from a base class.
    - ``eq_key`` and ``order_key`` (`typing.Callable` or `None`): The
      callables that are used for comparing and ordering objects by this
      attribute, respectively. These are set by passing a callable to
      `attr.ib`'s ``eq``, ``order``, or ``cmp`` arguments. See also
      :ref:`comparison customization <custom-comparison>`.

    Instances of this class are frequently used for introspection purposes
    like:

    - `fields` returns a tuple of them.
    - Validators get them passed as the first argument.
    - The :ref:`field transformer <transform-fields>` hook receives a list of
      them.
    - The ``alias`` property exposes the __init__ parameter name of the field,
      with any overrides and default private-attribute handling applied.


    .. versionadded:: 20.1.0 *inherited*
    .. versionadded:: 20.1.0 *on_setattr*
    .. versionchanged:: 20.2.0 *inherited* is not taken into account for
        equality checks and hashing anymore.
    .. versionadded:: 21.1.0 *eq_key* and *order_key*
    .. versionadded:: 22.2.0 *alias*

    For the full version history of the fields, see `attr.ib`.
    )rV   r'   r(   r)   r0   r1   r2   r3   r+   r,   r.   r%   r-   r/   rv   r4   r5   NFc                 C  s   t ||p
||p|d\}}}}t| }|d| |d| |d| |d| |d| |d| |d| |d	| |d
| |d| |d| |d|	rtt|	nt |d|
 |d| |d| |d| |d| d S )NTrV   r'   r(   r)   r0   r1   r2   r3   r+   r,   r-   r.   r%   r/   rv   r4   r5   )r6   r   r   typesMappingProxyTyper   _EMPTY_METADATA_SINGLETON)r   rV   r'   r(   r)   r*   r+   r,   rv   r.   r%   r-   r/   r0   r1   r2   r3   r4   r5   bound_setattrr   r   r   r   C	  s4    















zAttribute.__init__c                 C  s   t d S r"   )r   r   r   r   r   r   z	  s    zAttribute.__setattr__c              	     sZ   |d u r j }n j d ur&d}t| fddtjD }| f | j j|d dd|S )Nz8Type annotation and type argument cannot both be presentc                   s    i | ]}|d vr|t  |qS ))rV   r(   r'   r%   rv   r   )r   r   r   r   r   r   	  s
   z0Attribute.from_counting_attr.<locals>.<dictcomp>F)rV   r(   r'   r%   r*   rv   )r%   r8   r   r  
_validator_default)rr   rV   r   r%   rB   	inst_dictr   r  r   r   }	  s$    

zAttribute.from_counting_attrc                 K  s   t  | }||  |S )a
  
        Copy *self* and apply *changes*.

        This works similarly to `attrs.evolve` but that function does not work
        with :class:`attrs.Attribute`.

        It is mainly meant to be used for `transform-fields`.

        .. versionadded:: 20.3.0
        )copy	_setattrsr   )r   r   newr   r   r   rz   	  s    
zAttribute.evolvec                   s   t  fdd jD S )(
        Play nice with pickle.
        c                 3  s*   | ]"}|d krt  |nt jV  qdS )r.   N)ry   r   r.   r   r   r   r   r   	  s   z)Attribute.__getstate__.<locals>.<genexpr>r=   r  r   r   r   r   r   	  s    zAttribute.__getstate__c                 C  s   |  t| j| dS r  N)r  r%  r  r   r&  r   r   r   r   	  s    zAttribute.__setstate__c                 C  sL   t | }|D ]8\}}|dkr*||| q|||r@tt|nt qd S )Nr.   )r   r   r  r  r   r  )r   Zname_values_pairsr  rV   r   r   r   r   r  	  s    
zAttribute._setattrs)
NNNFNNNNNN)N)r   r   r   r   r  r   r   r  r   rz   r   r   r  r   r   r   r   r   	  s(   ,          
7	r   c                 C  s2   g | ]*}t |td dd dd|dkddt|dqS )NTFr.   )rV   r'   r(   r)   r*   r0   r2   r+   r,   rv   r5   )r   r   r   r   r   r   r   r   	  s   r   r  c                 C  s   g | ]}|j d kr|qS ru   r   r   r   r   r   r   	  r   c                 C  s    g | ]}|j r|jd kr|qS ru   )r+   rV   r   r   r   r   r   	  r   c                   @  sn   e Zd ZdZdZg edd dD eddddddd	dd	ddd	dd	dd
R ZdZdd Z	dd Z
dd ZdS )r@   a  
    Intermediate representation of attributes that uses a counter to preserve
    the order in which the attributes have been defined.

    *Internal* data structure of the attrs library.  Running into is most
    likely the result of a bug like a forgotten `@attr.s` decorator.
    )r  r  r5   r-   r   r0   r1   r+   r,   r/   r.   r4   r2   r3   r)   r%   c                 c  s8   | ]0}t |t|td dd ddddd dd dd dV  qd S )NTFrV   r5   r'   r(   r)   r*   r+   r,   r/   r0   r1   r2   r3   rv   r4   )r   r   r   r   r   r   r   r   
  s$   z_CountingAttr.<genexpr>)	r   r  r)   r0   r2   r+   r,   r4   r5   r.   NTFr  r   c                 C  st   t  jd7  _t j| _|| _|| _|| _|| _|| _|| _|| _	|| _
|| _|| _|| _|	| _|
| _|| _|| _d S r   )r@   cls_counterr   r  r  r-   r)   r0   r1   r2   r3   r+   r,   r.   r%   r/   r4   r5   )r   r'   r(   r)   r*   r+   r,   r-   r.   r%   r/   r0   r1   r2   r3   r4   r5   r   r   r   r   5
  s"    z_CountingAttr.__init__c                 C  s$   | j du r|| _ nt| j || _ |S )z
        Decorator that adds *meth* to the list of validators.

        Returns *meth* unchanged.

        .. versionadded:: 17.1.0
        N)r  r?   r   r@  r   r   r   r(   Z
  s    
z_CountingAttr.validatorc                 C  s    | j turtt|dd| _ |S )z
        Decorator that allows to set the default for an attribute.

        Returns *meth* unchanged.

        Raises:
            DefaultAlreadySetError: If default has been set before.

        .. versionadded:: 17.1.0
        T)r  )r  r   r   r:   r  r   r   r   r'   h
  s    
z_CountingAttr.default)r   r   r   r   r  r=   r   rt   r  r   r(   r'   r   r   r   r   r@   	  s:   1%r@   c                   @  s.   e Zd ZdZdZdddZdd Zdd	 Zd
S )r:   a  
    Stores a factory callable.

    If passed as the default value to `attrs.field`, the factory is used to
    generate a new value.

    Args:
        factory (typing.Callable):
            A callable that takes either none or exactly one mandatory
            positional argument depending on *takes_self*.

        takes_self (bool):
            Pass the partially initialized instance that is being initialized
            as a positional argument.

    .. versionadded:: 17.1.0  *takes_self*
    rA   r  Fc                 C  s   || _ || _d S r"   r  )r   rA   r  r   r   r   r   
  s    zFactory.__init__c                   s   t  fdd jD S )r  c                 3  s   | ]}t  |V  qd S r"   r   r   r   r   r   r   
  r   z'Factory.__getstate__.<locals>.<genexpr>r  r   r   r   r   r   
  s    zFactory.__getstate__c                 C  s&   t | j|D ]\}}t| || qdS r  )r%  r  r   )r   r&  rV   r   r   r   r   r   
  s    zFactory.__setstate__N)F)r   r   r   r   r  r   r   r   r   r   r   r   r:   ~
  s
   
r:   c                 C  s(   g | ] }t |td dd dddddd
qS NTF)
rV   r'   r(   r)   r*   r0   r2   r+   r,   rv   r   r   r   r   r   r   r   
  s   c                   @  sZ   e Zd ZdZdZdddddZedddd	d
ZddddddZdd Z	dd Z
dS )r  ae  
    Stores a converter callable.

    Allows for the wrapped converter to take additional arguments. The
    arguments are passed in the order they are documented.

    Args:
        converter (Callable): A callable that converts the passed value.

        takes_self (bool):
            Pass the partially initialized instance that is being initialized
            as a positional argument. (default: `False`)

        takes_field (bool):
            Pass the field definition (an :class:`Attribute`) into the
            converter as a positional argument. (default: `False`)

    .. versionadded:: 24.1.0
    )__call__r  Z_global_namer-   takes_fieldr  Fr  r  c                  s   | _ | _| _t|}|  _ js@ js@ fdd _nF jr\ js\ fdd _n* jsx jrx fdd _n fdd _| }|d ur| jjd< d S )Nc                   s
     | S r"   r-   )r   rn  __r   r   r   r   
  r   z$Converter.__init__.<locals>.<lambda>c                   s     | |S r"   r  )r   instancer  r   r   r   r   
  s   c                   s     | |S r"   r  )r   r  r5  r   r   r   r   
  s   c                   s     | ||S r"   r  )r   r  r5  r   r   r   r   
  s   r  )	r-   r  r  r   get_first_param_typer  r  get_return_typer  )r   r-   r  r  exrtr   r   r   r   
  s    
zConverter.__init__rl   )re   r  c                 C  s
   d|  S )zh
        Return the name that a converter for an attribute name *attr_name*
        would have.
        Z__attr_converter_r   )re   r   r   r   r  
  s    zConverter._get_global_name)re   r  r  c                 C  s   | j s"| js"| | d| dS | j rJ| jrJ| | d| d| dS | j rf| | d| dS | | d| d| dS )z
        Return a string that calls the converter for an attribute name
        *attr_name* and the value in variable named *value_var* according to
        `self.takes_self` and `self.takes_field`.
        r  rl  z, self, attr_dict['z'])z, self)z, attr_dict[')r  r  r  )r   re   r  r   r   r   r  
  s    zConverter._fmt_converter_callc                 C  s   | j | j| jdS )zx
        Return a dict containing only converter and takes_self -- the rest gets
        computed when loading.
        r-   r  r  r  r   r   r   r   r   
  s    zConverter.__getstate__c                 C  s   | j f i | dS )z+
        Load instance from state.
        Nr\  r  r   r   r   r     s    zConverter.__setstate__N)r   r   r   r   r  r   r  r  r  r   r   r   r   r   r   r  
  s   	c                 C  s(   g | ] }t |td dd dddddd
qS r  r  r   r   r   r   r     s   r  c                   s^  t |tr|}n*t |ttfr.dd |D }nd}t||dd}|dd}|dd}	i  |durt | |dur| d< |dur| d< |	dur|	 d< t| |i  fdd	}
t	
tt& td
jdd|
_W d   n1 s0    Y  |dd}t||d|dd\|d< |d< tf d|i||
}dd | D |_|S )a  
    A quick way to create a new class called *name* with *attrs*.

    .. note::

        ``make_class()`` is a thin wrapper around `attr.s`, not `attrs.define`
        which means that it doesn't come with some of the improved defaults.

        For example, if you want the same ``on_setattr`` behavior as in
        `attrs.define`, you have to pass the hooks yourself: ``make_class(...,
        on_setattr=setters.pipe(setters.convert, setters.validate)``

    Args:
        name (str): The name for the new class.

        attrs (list | dict):
            A list of names or a dictionary of mappings of names to `attr.ib`\
            s / `attrs.field`\ s.

            The order is deduced from the order of the names or attributes
            inside *attrs*.  Otherwise the order of the definition of the
            attributes is used.

        bases (tuple[type, ...]): Classes that the new class will subclass.

        class_body (dict):
            An optional dictionary of class attributes for the new class.

        attributes_arguments: Passed unmodified to `attr.s`.

    Returns:
        type: A new class with *attrs*.

    .. versionadded:: 17.1.0 *bases*
    .. versionchanged:: 18.1.0 If *attrs* is ordered, the order is retained.
    .. versionchanged:: 23.2.0 *class_body*
    c                 S  s   i | ]}|t  qS r   )rC   r   r   r   r   r   \  r   zmake_class.<locals>.<dictcomp>z(attrs argument must be a dict or a list.r   Nr   r   c                   s
   |   S r"   )r	  )r  bodyr   r   r   o  r   zmake_class.<locals>.<lambda>r   r   __main__r*   r0   r2   Tr   c                 S  s"   i | ]\}}|j d ur||j qS r"   )r%   r   r   r   r   r     s   )r;   r   r<   r=   r7   popr	  r  	new_classr   r   r   r8   r  	_getframe	f_globalsr   r   rT  r   r   r  )rV   rh   basesZ
class_bodyZattributes_argumentsZcls_dictrB   r  r  Z	user_inittype_r*   rr   r   r  r   
make_class1  sL    (

$r  )r   rh  c                   @  s   e Zd ZdZe Zdd ZdS )_AndValidatorz2
    Compose many validators to a single one.
    c                 C  s   | j D ]}|||| qd S r"   )_validators)r   r   r   r   r   r   r   r   r    s    
z_AndValidator.__call__N)r   r   r   r   rC   r  r  r   r   r   r   r    s   r  c                  G  s6   g }| D ] }| t|tr |jn|g qtt|S )a  
    A validator that composes multiple validators into one.

    When called on a value, it runs all wrapped validators.

    Args:
        validators (~collections.abc.Iterable[typing.Callable]):
            Arbitrary number of validators.

    .. versionadded:: 17.1.0
    )r   r;   r  r  r=   )Z
validatorsr  r(   r   r   r   r?     s    r?   c                    s   t dd  D }|r$ fdd}n fdd} sRtd}|j||d nTt d  }|rp||jd	<  d
 }tst|t	r|j
}t| }|r||jd< |rt	|dddS |S )a  
    A converter that composes multiple converters into one.

    When called on a value, it runs all wrapped converters, returning the
    *last* value.

    Type annotations will be inferred from the wrapped converters', if they
    have any.

        converters (~collections.abc.Iterable[typing.Callable]):
            Arbitrary number of converters.

    .. versionadded:: 20.1.0
    c                 s  s   | ]}t |tV  qd S r"   r;   r  )r   cr   r   r   r     r   zpipe.<locals>.<genexpr>c                   s,    D ]"}t |tr|| ||n|| } q| S r"   r  )rH  r   r5  r  
convertersr   r   pipe_converter  s    zpipe.<locals>.pipe_converterc                   s    D ]}|| } q| S r"   r   )rH  r  r  r   r   r    s    
A)rH  r  r   rH  rN   r  Tr  )rR  typingTypeVarr  r	  r   r  r	   r;   r  r  r  )r  Zreturn_instancer  r  tlastr  r   r  r   r>     s&    



r>   )NrD   )N)T)NNNNNNNFFTFFFFFNNFFNNNTN)N)NN)c
__future__r   r   r   r  r   r  r   r  rS   r  r  r  operatorr   rD   r   r   r   r   r	   r
   r   r   r   
exceptionsr   r   r   r   objectr   r   r  ro   r  r  r  r   r>   r   r   r   Enumr   r   intr!   rC   rM   rZ   rf   rg   rp   rs   r   r   r   r   r   r   rz   r   rT  r6   rY  rh   r   r]  r   r,  r|  r=  r<  rE  r  r  r  r   r  r  r1  r  r  r  r  r  r  r   r   r  Z_ar@   r:   Z_fr  r  r  r?   r   r   r   r   <module>   s,   		

k
	
m::    , 
                        
 a
G&8
9
.O
/&   L
	 'd
a
