o
    gy                    @  s0  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mZmZ d dlmZ d dl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 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/Z0G dd dej1Z2e2j3Z3	 G dd de4Z5e3ddddddddddddddfddZ6		dddd Z7	ddd#d$Z8dd)d*Z9G d+d, d,eZ:d-d. Z;d/d0 Z<dd2d3Z=d4d5 Z>dd6d7Z?d8d9 Z@d:d; ZAd<d= ZBd>d? ZCG d@dA dAZDdBdC ZEdDdE ZF	ddFdGZG																								ddHdIZHeHZI	 dJdK ZJddNdOZKddUdVZLddWdXZMdYdZ ZNdd\d]ZOd^d_ ZPdd`daZQddbdcZRddddeZSdfdg ZTdhdi ZUdjdk Z/dldm ZVddodpZWddtduZXddxdyZYdd{d|ZZdd}d~Z[dddZ\dddZ]dddZ^G dd dZ_dd e_j`D ZaeMeQeSe_eaddd eaD ddd eaD dZ_G dd dZbeQeSebZbG dd dZcdd ecj`D ZdeMeQeSeceddeddeddZcG ddw dwZedd dD ZdeMeQeSeeeddeddeddZee$fdfddZfeHdddG dd dZgdd Zhdd Z-dS )    )annotationsN)CallableMapping)cached_property)Any
NamedTupleTypeVar   )_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.ClassVar_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     dS )NNOTHING selfr   r   C/home/ubuntu/webapp/venv/lib/python3.10/site-packages/attr/_make.py__repr__J      z_Nothing.__repr__c                 C  r   )NFr   r   r   r   r   __bool__M   r!   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   _none_constructor_argsr   r   r   
__reduce__e      z_CacheHashWrapper.__reduce__)r#   r$   r%   r&   typer-   r   r   r   r   r)   Y   s    r)   TFc                 C  s4  t |||d\}}}}|dur|dur|durd}t||	dur9| tur+d}t|t|	s5d}t|t|	} |du r?i }t|ttfrKt	j
| }|rXt|ttfrXt| }|ret|ttfret
| }tdi d| d|d	|d
dd|d|d|d|d|d|
d|d|d|d|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aliasr   )_determine_attrib_eq_order	TypeErrorr   
ValueErrorcallableFactory
isinstancelisttupler   pipeand__CountingAttr)r1   r2   r3   r4   r5   r6   r8   r/   r7   factoryr9   r:   r<   r>   r?   r;   r=   msgr   r   r   attribi   sp   7
	
rM    scriptstrglobsdict[str, Any] | NonelocsMapping[str, object] | NonefilenamereturnNonec                 C  s   t | |d}t||| dS )z[
    Evaluate the script with the given global (globs) and local (locs)
    variables.
    execN)compileeval)rO   rQ   rS   rU   bytecoder   r   r   _compile_and_eval   s   
r\   localsdict[str, Any]c           	      C  s|   |du ri n|}d}|}	 t | d| d|f}tj||}||kr$n|dd  d| d}|d7 }qt| ||| |S )zP
    Cache the script with _linecache_, compile it and return the _locals_.
    Nr	   T->)len
splitlines	linecachecache
setdefaultr\   )	rO   rU   rQ   r]   rS   countbase_filenamelinecache_tupleold_valr   r   r   _linecache_and_compile   s"   
rk   cls_name
attr_names	list[str]r/   c                 C  sF   |  d}i }t |D ]\}}|fdd}t|||< qt|tf|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))
    
Attributesc                 S  s   | | S r*   r   )r   ir   r   r   getter  r.   z&_make_attr_tuple_class.<locals>.getter)	enumeratepropertyr/   rG   )rl   rm   attr_class_namebodyrp   	attr_namerq   r   r   r   _make_attr_tuple_class  s   

rw   c                   @  s&   e Zd ZU ded< ded< ded< dS )_Attributesr/   attrslist[Attribute]
base_attrsdict[str, type]base_attrs_mapN)r#   r$   r%   __annotations__r   r   r   r   rx     s   
 rx   c                 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	   r_   )rP   
startswithendswith_CLASSVAR_PREFIXES)annotr   r   r   _is_class_var"  s   
r   c                 C  s
   || j v S )zR
    Check whether *cls* defines *attrib_name* (and doesn't just inherit it).
    )__dict__)clsattrib_namer   r   r   _has_own_attribute3  s   
r   'tuple[list[Attribute], dict[str, type]]c                 C  s   g }i }t | jdd D ]$}t|dg D ]}|js|j|v r q|jdd}|| |||j< qqg }t }t |D ]}|j|v rCq;|d| |	|j q;||fS )zQ
    Collect attr.ibs from base classes of *cls*, except *taken_attr_names*.
    r	   r_   __attrs_attrs__T	inheritedr   )
reversed__mro__getattrr   nameevolveappendsetinsertadd)r   taken_attr_namesr{   base_attr_mapbase_clsafilteredseenr   r   r   _collect_base_attrs:  s$   

r   c                 C  sn   g }i }| j dd D ]'}t|dg D ]}|j|v rq|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	   r_   r   Tr   )r   r   r   r   r   r   )r   r   r{   r   r   r   r   r   r   _collect_base_attrs_broken[  s   

	r   c              	     s  | j t|  |durt| }nd|du rgdd  D }g }t }  D ]$\}	}
t|
r1q(||	 |	t}|j	t
urEt|}||	|f q(|| }|rftddt|fddd	 d
 ntdd  D dd d	}tj fdd|D }|rt| dd |D \}}nt| dd |D \}}|rdd |D }dd |D }|| }|durt|| |}d}dd |D D ]}|du r|jtu rd|}t||du r|jturd}q|D ]}|jst|dt|j qdd |D }t| j|}t||||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 | ]\}}|j tu r|qS r   	__class__rJ   .0r   attrr   r   r   	<setcomp>  s
    
z#_transform_attrs.<locals>.<setcomp>z1The following `attr.ib`s lack a type annotation: , c                   s     | jS r*   )getcounter)n)cdr   r   <lambda>  s    z"_transform_attrs.<locals>.<lambda>)key.c                 s  s&    | ]\}}|j tu 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        
 c                   s"   g | ]\}}||  |qS r   )r   )r   rv   ca)annsfcar   r   
<listcomp>  s    z$_transform_attrs.<locals>.<listcomp>c                 S     h | ]}|j qS r   r   r   r   r   r   r   r         c                 S  r   r   r   r   r   r   r   r     r   c                 S     g | ]}|j d dqS T)r9   r   r   r   r   r   r         c                 S  r   r   r   r   r   r   r   r     r   Fc                 s  s(    | ]}|j d ur|jd u r|V  qdS )FN)r6   r9   r   r   r   r   r     s   & zlNo mandatory attributes allowed after an attribute with a default value or factory.  Attribute in question: r?   c                 S  s   g | ]}|j qS r   r   r   r   r   r   r     r   )r   r   rF   itemsr   r   r   r   r   r   rJ   rM   r   r   joinsorted	Attributefrom_counting_attrr   r   rG   r1   rB   r?   _OBJ_SETATTR__get___default_init_alias_forr   rw   r#   rx   )r   theseauto_attribsr9   collect_by_mrofield_transformerca_listca_namesannot_namesrv   r/   r   unannotated	own_attrsr{   r   ry   had_defaultrL   rm   
AttrsClassr   )r   r   r   r   _transform_attrsw  s   

		

r   c                 C  sn   g d}|d ur| d n|g d |ddg t|d}| tj|d}td|||d	|id
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)r   )cached_properties_cached_setattr_getoriginal_getattr
_cls)r]   __getattr__)r   extend_generate_unique_filenamer   r   rk   r   )r   r   r   linesunique_filenameglobr   r   r   _make_cached_property_getattr  s.   
r   c                 C  s(   t | tr|dv rt| || dS t)z4
    Attached to frozen classes as __setattr__.
    )	__cause____context____traceback____suppress_context__	__notes__N)rE   BaseException__setattr__r   r   r   valuer   r   r   _frozen_setattrs  s   r   c                 C  s&   t | tr|dv rt| | dS t)z4
    Attached to frozen classes as __delattr__.
    )r   N)rE   r   __delattr__r   )r   r   r   r   r   _frozen_delattrs(  s   r   c            	      O  s   z| \}W n t y   dt|  d}t|dw |j}t|}|D ]}|js)q#|j}|j}||vr:t||||< q#|d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 givenNr   )	rB   rb   rA   r   fieldsr6   r   r?   r   )	argschangesinstrL   r   ry   r   rv   	init_namer   r   r   r   3  s$   %

r   c                   @  s   e Zd ZdZdZd2ddZdd Zd3d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d4d-d.Zd4d/d0Zd1S )5_ClassBuilderz(
    Iteratively build *one* class.
    )_add_method_dunders_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_repr_added_script_snippets_slots_weakref_slot_wrote_own_setattrr   r/   c                 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	< |rt| jd
< t| jd< d| _n?|tt j!t j"fv rd }}|D ]}|j#d urd}|j$d urd}|r|r nq|tkr|s|r|t j!kr|r|t j"kr|sd | _|r| % \| jd< | jd< g | _&d| _'t(| jdrt(| jds| j)| _*d S | j+| _*d S )Nc                 S  r   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     s    z)_ClassBuilder.__init__.<locals>.<genexpr>__attrs_pre_init__Fr	   __attrs_post_init__r   r   r   T__getstate____setstate__r$   r%   ),r   r   dictr   r   r   r   r   rG   r   r   r   r  r   boolr   r   r   r  inspect	signaturerb   
parametersr   r   r   r   r   r  r   r   _DEFAULT_ON_SETATTRr   validateconvertr2   r7   _make_getstate_setstater   r   hasattr_add_method_dunders_safer   _add_method_dunders_unsafe)r   r   r   slotsfrozenweakref_slotgetstate_setstater   r9   
cache_hashis_excr   r>   has_custom_setattrr   ry   r{   base_mappre_init_funcpre_init_signaturehas_validator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__rV   rW   c                 C  sl   d dd | jD }i }| jD ]
\}}}|| qt|t| jd|}| jD ]\}}}|| j| q(dS )z=
        Evaluate any registered snippets in one go.
        r   c                 S  s   g | ]}|d  qS )r   r   )r   snippetr   r   r   r         z0_ClassBuilder._eval_snippets.<locals>.<listcomp>methodsN)r   r   updaterk   r   r   r   )r   rO   rQ   _snippet_globsrS   hookr   r   r   _eval_snippets  s   
z_ClassBuilder._eval_snippetsc                 C  sT   |    | jdu r|  }n|  }trt|}t|ddr(d|jvr(|	  |S )z
        Finalize class based on the accumulated configuration.

        Builder cannot be used after calling this method.
        T__attrs_init_subclass__N)
r'  r   _create_slots_class_patch_original_classr   abcupdate_abstractmethodsr   r   r(  )r   r   r   r   r   build_class
  s   




z_ClassBuilder.build_classc              	   C  s   | j }| j}| jr5| jD ](}||vr4t||ttur4tt t	|| W d   n1 s/w   Y  q| j
 D ]
\}}t||| q:| jsWt|ddrWd|_| jsWt|_|S )zA
        Apply accumulated methods and return the class.
        N__attrs_own_setattr__F)r   r   r   r   r   	_SENTINEL
contextlibsuppressAttributeErrordelattrr   r   setattrr  r.  r   r   r   )r   r   
base_namesr   r   r   r   r   r*  "  s&   
z#_ClassBuilder._patch_original_classc              
     s  fddj  D }js*d|d< js*jjD ]  jddr)t|d<  nqi }d}jj	dd D ]  jdd	d	urCd
}|
 fddt dg D  q6tjj}jrrdtjddvrrd|vrr|sr|d7 }dd | D }g }|rtj}| D ]!\}}	||f7 }||= ||	 t|	j}
|
tjjur|
||< q|d}|d	ur|| 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 ]L}t!|t"t#frt|j$dd	}nt!|t%r-t|j&dd	}nt|dd	}|s8q|D ]}z|j'ju }W n t(yO   Y q:w |rV||_'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 )r   __weakref__)rG   r   r   kvr   r   r   
<dictcomp>J  s
    z5_ClassBuilder._create_slots_class.<locals>.<dictcomp>Fr.  r   r	   r_   r6  NTc                      i | ]}|t  |qS r   r   r   r   )r   r   r   r:  i  s    
	__slots__r   )r6  c                 S  s"   i | ]\}}t |tr||jqS r   )rE   r   func)r   r   cached_propr   r   r   r:  z  s    r   c                      g | ]}| vr|qS r   r   r=  )r5  r   r   r     r   z5_ClassBuilder._create_slots_class.<locals>.<listcomp>c                   s   i | ]\}}| v r||qS r   r   )r   slotslot_descriptor)
slot_namesr   r   r:    s
    c                   rA  r   r   r=  )reused_slotsr   r   r     r   r%   __closure__))r   r   r  r   r   	__bases__r   r   r   r   r#  r   r   r   r   r  r   r   r	  r
  return_annotation	Parameteremptyr   r   _HASH_CACHE_FIELDrG   r%   r/   r#   	itertoolschainvaluesrE   classmethodstaticmethod__func__rs   fgetcell_contentsrB   )r   r   existing_slotsweakref_inheritednamesr   &additional_closure_functions_to_updateclass_annotationsr   r?  
annotationr   r   itemclosure_cellscellmatchr   )r   r5  rE  r   rD  r   r)  F  s   












	z!_ClassBuilder._create_slots_classc                   s8   t  j|\}} fdd} j|||f d _ S )Nc                        |d | d< d S )Nr    r   cls_dictrQ   r   r   r   _attach_repr     z,_ClassBuilder.add_repr.<locals>._attach_reprT)_make_repr_scriptr   r   r   r   )r   nsrO   rQ   rb  r   r   r   add_repr  s
   z_ClassBuilder.add_reprc                 C  s.   | j s	d}t|dd }| || jd< | S )Nz3__str__ can only be generated if a __repr__ exists.c                 S  s   |   S r*   r    r   r   r   r   __str__  r.   z&_ClassBuilder.add_str.<locals>.__str__rh  )r   rB   r   r   )r   rL   rh  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 )r6  Nr   )r   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                   r;  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     z=_ClassBuilder._make_getstate_setstate.<locals>.slots_getstatec                   sj   t | }t|trt|D ]	\}}||| qnD ]}||v r)||||  q r3|td dS dS )rk  N)r   r   rE   rG   ziprK  )r   state_ClassBuilder__bound_setattrr   r   hash_caching_enabledrl  r   r   slots_setstate  s   

z=_ClassBuilder._make_getstate_setstate.<locals>.slots_setstate)rG   r   r   )r   rm  rt  r   rr  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                   s@   t  j j j jd\}}d	 fdd} j|||f  S )
Nr  r  ra  r  rS   rV   rW   c                   r^  ru  r_  )ra  rS   r   r   r   attach_hash  rc  z+_ClassBuilder.add_hash.<locals>.attach_hash)ra  r  rS   r  rV   rW   )_make_hash_scriptr   r   r   r   r   r   )r   rO   rQ   ry  r   r   r   add_hash  s   
z_ClassBuilder.add_hashc                   `   t jjjjjjjjj	j
jdd\}}  fdd}j|||f S )NF
attrs_initc                       |d } |_ || d< d S )Nr  r~   r   ra  rQ   r6   r   r   r   r   _attach_init2     z,_ClassBuilder.add_init.<locals>._attach_init_make_init_scriptr   r   r   r   r   r   r   r   r   r   r   r   r   )r   rO   rQ   r  r   r  r   add_init"  "   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   =  s    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*   )r6   r9   r   )r   fieldr   r   r   r   B  s    
z/_ClassBuilder.add_match_args.<locals>.<genexpr>__match_args__)rG   r   r   r   r   r   r   add_match_argsA  s   z_ClassBuilder.add_match_argsc                   r|  )NTr}  c                   r  )N__attrs_init__r  r  r  r   r   _attach_attrs_initX  r  z8_ClassBuilder.add_attrs_init.<locals>._attach_attrs_initr  )r   rO   rQ   r  r   r  r   add_attrs_initH  r  z_ClassBuilder.add_attrs_initc                   s>    j }t j\}} fdd} j|||f t|d<  S )Nc                   r^  )N__eq__r_  r`  r   r   r   
_attach_eqf  rc  z(_ClassBuilder.add_eq.<locals>._attach_eq__ne__)r   _make_eq_scriptr   r   r   r  )r   r   rO   rQ   r  r   r   r   add_eqa  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   r  s
    
z*_ClassBuilder.add_order.<locals>.<genexpr>__lt____le____gt____ge__)r   _make_orderr   r   )r   r   r   r   r   	add_ordero  s
   
z_ClassBuilder.add_orderc                   s   i  | j D ]}|jp| j}|r|tjur||f |j< q s | 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w || ||}t| || d S r*   )KeyErrorr   )r   r   valr   r&  nvalsa_attrsr   r   r     s   z._ClassBuilder.add_setattr.<locals>.__setattr__Tr.  r   )r   r>   r   r   NO_OPr   r   rB   r   r   r  )r   r   r>   rL   r   r   r  r   add_setattry  s    


z_ClassBuilder.add_setattrmethodr   c                 C  s6   | j j|_| j j d|j |_d| j j d|_|S )z@
        Add __module__ and __qualname__ to a *method*.
        r   $Method generated by attrs for class )r   r$   r%   r#   r&   r   r  r   r   r   r    s
   
z(_ClassBuilder._add_method_dunders_unsafec                 C  s   t t | jj|_W d   n1 sw   Y  t t | jj d|j |_W d   n1 s5w   Y  t t d| jj d|_W d   |S 1 sTw   Y  |S )zL
        Add __module__ and __qualname__ to a *method* if possible.
        Nr   r  )r0  r1  r2  r   r$   r%   r#   r&   r  r   r   r   r    s   
z&_ClassBuilder._add_method_dunders_safeN)r   r/   )rV   rW   )r  r   rV   r   )r#   r$   r%   r&   r>  r  r    r'  r-  r*  r)  rf  ri  r  rw  r{  r  r  r  r  r  r  r  r  r  r   r   r   r   r   m  s0    
k
$ 
)

 r   c                 C  st   | durt |du|dufrd}t|| dur| | fS |du r"|}|du r(|}|du r6|du r6d}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.anyrB   )r4   r:   r<   
default_eqrL   r   r   r   _determine_attrs_eq_order  s   r  c           	      C  s   | durt |du|dufrd}t|dd }| dur(|| \} }| || |fS |du r2|d}}n||\}}|du rB||}}n||\}}|du rV|du rVd}t|||||fS )r  Nr  c                 S  s&   t | rd| } }| |fS d}| |fS )z8
        Decide whether a key function is used.
        TN)rC   )r   r   r   r   r   decide_callable_or_boolean  s
   
z>_determine_attrib_eq_order.<locals>.decide_callable_or_booleanFTr  r  )	r4   r:   r<   r  rL   r  cmp_keyr;   r=   r   r   r   r@     s"   r@   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)r   )r   flagauto_detectdundersr1   dunderr   r   r   _determine_whether_to_implement  s   
r  c                   s   durddl }|jtddd t|||d\|dur |	tttfr,tj  	
fdd}| du rL|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rD| du rL|  t| d}|s]|du r]|	  |sjt| drj|
  sp|  	d u rdu rt| d	rd
		dur	d
ur	d urd}t|	d
u s	d u r|d
u s|rrd}t|n!	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rt| ds|  | S )NTr   z/Can't freeze a class with a custom __setattr__.)r  r  )r1   rg  )r  r  )r  r  r  r  rv  Fr0   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.r  r  )_has_frozen_base_class
issubclassr   r   rB   r   r  rf  ri  r  r  r  rA   r{  rw  r  r  r   r  r   r  r-  )r   	is_frozenr  has_own_setattrrL   builderr:   r   r  auto_excr  r   eq_r   r  r  r5   r6   r9   
match_argsr>   order_r3   repr_nsr  rP   r   r  r   r   wrap  s   


zattrs.<locals>.wrap)	warningswarnDeprecationWarningr  rE   rF   rG   r   rH   )	maybe_clsr   r  r3   r4   r5   r6   r  r  r  rP   r   r9   r  r  r:   r<   r  r   r  r>   r   r  unsafe_hashr  r  r   r  r   ry     s"   \
4nry   c                 C  s
   | j tu S )zV
    Check whether *cls* has a frozen ancestor by looking at its
    __setattr__.
    )r   r   )r   r   r   r   r    s   
r  r   	func_namec              	   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%   ra   )r$   r   r#   )r   r  r   r   r   r   
  s   r   rz   r  r  r  tuple[str, dict]c                   s  t dd  D  d}tt| di d}dd|s!|d7 }n|d	7 }|d
7 }d d7 |g fdd}|ry|dt d  |rc|dt d|d  |d d  n|dt d|d  |dt   n|d| d}|fS )Nc                 s  s2    | ]}|j d u s|j du r|jd u r|V  qdS )TN)r5   r:   r   r   r   r   r     s    (z$_make_hash_script.<locals>.<genexpr>        r5   zdef __hash__(selfzhash((z))z):z, *zC, _cache_wrapper=__import__('attr._make')._make._CacheHashWrapper):z_cache_wrapper()c              	     s    ||   |d d g  D ]-}|jr4d|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
        r  ,r$  _key(self.z),        self.    N)r   r;   r   r   )prefixindentr   cmp_namery   closing_bracesrQ   	hash_funcmethod_lines	type_hashr   r   append_hash_computation_lines/  s   

z8_make_hash_script.<locals>.append_hash_computation_lineszif self.z	 is None:zobject.__setattr__(self, '', r  self. = zreturn self.zreturn r   )rG   r5   r   r   rK  r   )r   ry   r  r  tabhash_defr  rO   r   r  r   rz    s>   


rz  c                 C  s6   t | |ddd\}}t||t| dd |d | _| S )z%
    Add a hash method to *cls*.
    Frx  rv  rU   )rz  r\   r   rv  r   ry   rO   rQ   r   r   r   	_add_hash\  s   

r  c                 C  s   |  |}|tu rtS | S )z^
    Check equality and either forward a NotImplemented or
    return the result negated.
    )r  NotImplemented)r   otherresultr   r   r   r  j  s   
r  rF   c                 C  s   dd | D } g d}i }| r_| d | D ]B}|jr<d|j d}|j||< | d| d|j d	| d
|j d	 n| d|j d|j  || d urX|d  d|d< q| d n| d d|}||fS )z6
    Create __eq__ method for *cls* with *attrs*.
    c                 S     g | ]}|j r|qS r   )r:   r   r   r   r   r   z      z#_make_eq_script.<locals>.<listcomp>)zdef __eq__(self, other):z-    if other.__class__ is not self.__class__:z        return NotImplementedz    return  (r$  r  r  r  z) == z(other.r  r  z
 == other.r_   z andz    )z    return Truer   )r   r;   r   r   )ry   r   rQ   r   r  rO   r   r   r   r  v  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  r  r   )r<   r   r   r   r   r     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     s
    
z6_make_order.<locals>.attrs_to_tuple.<locals>.<genexpr>c                 3  s"    | ]}t  |j|jfV  qd S r*   )r   r   r=   r   objr   r   r     s    
)rG   r  ry   r  r   attrs_to_tuple  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   r       z_make_order.<locals>.__lt__c                   s    |j | j u r |  |kS tS r  r  r  r  r   r   r    r  z_make_order.<locals>.__le__c                   s    |j | j u r |  |kS tS r  r  r  r  r   r   r    r  z_make_order.<locals>.__gt__c                   s    |j | j u r |  |kS tS r  r  r  r  r   r   r    r  z_make_order.<locals>.__ge__r   )r   ry   r  r  r  r  r   )ry   r  r   r    s   				r  c                 C  sB   |du r| j }t|\}}t||t| dd |d | _t| _| S )z5
    Add equality methods to *cls* with *attrs*.
    Nr  r  )r   r  r\   r   r  r  r  r   r   r   _add_eq  s   
r  c                 C  s   t dd | D }dd |D }t|d< t|d< t|d< g }|D ]'\}}}|r+d| nd	| d
 }|tkr;d||f nd|||f }	||	 q d|}
|du rTd}n|d }ddddddddddddd| d|
 ddd g}d!||fS )"zC
    Create the source and globs for a __repr__ and return it.
    c                 s  s8    | ]}|j d ur|j|j du rt n|j |jfV  qdS )FTN)r3   r   r6   r   r   r   r   r     s    
z$_make_repr_script.<locals>.<genexpr>c                 S  s$   i | ]\}}}|t kr|d  |qS )_repr)r3   )r   r   rr$  r   r   r   r:    s    z%_make_repr_script.<locals>.<dictcomp>r
   r2  r   r  zgetattr(self, "z", NOTHING)z	%s={%s!r}z%s={%s_repr(%s)}r   Nz1{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   )rG   r
   r2  r   r3   r   r   )ry   re  attr_names_with_reprsrQ   attribute_fragmentsr   r  rp   accessorfragmentrepr_fragmentcls_name_fragmentr   r   r   r   rd    sN   
rd  c                 C  s>   |du r| j }t||\}}t||t| dd |d | _| S )z%
    Add a repr method to *cls*.
    Nr    r  )r   rd  r\   r   r    )r   re  ry   rO   rQ   r   r   r   	_add_repr  s   
r  c                 C  sv   t | }|du rt| tsd}t|t| dd}|du r9|dur0t|dd}|dur0|| _|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.r   ! is not an attrs-decorated class.)r   rE   r/   rA   r   r   r   )r   generic_baserL   ry   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  r   Nr  c                 S  s   i | ]}|j |qS r   r   r   r   r   r   r:  t  r!  zfields_dict.<locals>.<dictcomp>)rE   r/   rA   r   r   )r   rL   ry   r   r   r   fields_dictZ  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   _run_validatorsr   r   r2   r   r   )r   r   r9  r   r   r   r  w  s   
	r  c                 C  s   | | }|od|jv S )z>
    Check if the attribute name comes from a slot class.
    r>  )r   r   )a_namer   r   r   r   r   _is_slot_attr  s   
r  tuple[str, dict, dict]c                 C  s  |
d uo|
t ju}|r|rd}t||p|}g }i }|D ]1}|js(|jtu r(q|| |||j< |jd urD|du rAd}t|d}q|rN|jt jurNd}qt	|||||||||	|||r_dnd\}}}| j
tjv ru|tj| j
 j |t|d |rtj|d< |||fS )Nz$Frozen classes can't use on_setattr.Tr  r  )r   	attr_dictr   )r   r  rB   r6   r1   r   r   r   r>   _attrs_to_init_scriptr$   sysmodulesr#  r   r   r   )r   ry   pre_initpre_init_has_args	post_initr  r  r  r   r  cls_on_setattrr~  has_cls_on_setattrrL   needs_cached_setattrfiltered_attrsr  r   rO   rQ   r   r   r   r   r    sR   






r  rv   	value_varhas_on_setattrc                 C  s   d|  d| dS )zJ
    Use the cached object.setattr to set *attr_name* to *value_var*.
    
_setattr('r  r  r   rv   r  r  r   r   r   _setattr  rn  r  r7   	Converterc                 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  r  r  )_fmt_converter_callrv   r  r  r7   r   r   r   _setattr_with_converter  s   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.
    Tr  r  )r  )rv   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.
    Tr  r  )r  r  r  r   r   r   _assign_with_converter  s   r  r  r   r|   c                   sJ   | du r |du rdt tfS d f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   rv   rP   r  r  r  rV   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_setterr7   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__Nrv   rP   r  rP   r  r  rV   rP   
rv   rP   r  rP   r  r  r7   r  rV   rP   )r  r  r  r  )r  r  r   r  r  r   r  r   _determine_setters  s   

r"  r  
is_slottedcall_pre_initr
  call_post_initdoes_cache_hashr  r  r  method_namec           $   
   C  s  |rdgng }|	r| d t|||\}}}|| g }g }g }i }ddi}| D ]}|jr5| | |j}|jdupD|jtjuoD|
}|j}t	|j
t}|rV|j
jrVdnd}|jdurit	|jtsit|j}n|j}|jdu r|rt|jf }|dur| |||d| d	 || |j|||j< n| |||d| d	 | |j
j||< n|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| |||| n|r| d}|jr-| | n| | | d| d t|jf }|durs| d|||||  | d | d|||d | d	 ||  |j|||j< n!| d||||  | d | d|||d | d	 |  |j
j||< n1|jr| | n| | |dur| ||||| |j|||j< n	| |||| |jdu r|jdur|du r|j||< q*|dur|jr|j||< q*|r't|d< | d |D ]&}d|j }d|j }| d| d| d|j d	 |j||< |||< q |r/| d |rQ|rF|r?dt d}ndt d}ndt d}| | |rgd d!d" | D } | d#|  d	 d$|}|}!|r||rwd$nd d%d$| 7 }d$d&d' d(d" |D D }"|!|!rd$nd7 }!|!|"7 }!|r|rd)|! 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)rV   Nr   rN   Fr  r  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:__attr_validator___attr_z(self, z, self.zself.__attrs_post_init__()r  z', None)r  z	'] = Noner  z = Noner  c                 s  s"    | ]}|j rd |j V  qdS )r  N)r6   r   r   r   r   r   r   	  s     z(_attrs_to_init_script.<locals>.<genexpr>zBaseException.__init__(self, r   z*, c                 S  s   g | ]	}| d | qS )=r   )r   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   kwar   r   r   r   	  s    zself.__attrs_pre_init__(r   z
    zdef z):
    passr   )r   r"  r   r2   r   r>   r   r  r?   rE   r1   rD   
takes_selfr7   r  r6   _INIT_FACTORY_PAT_get_global_namerK   r   r9   r/   _first_param_typer   rK  r   )$ry   r  r#  r$  r
  r%  r&  r   r  r  r  r'  r   extra_linesr  r  r   kw_only_argsattrs_to_validatenames_for_globalsr   r   rv   r  arg_namehas_factory
maybe_selfr7   init_factory_nameargval_nameinit_hash_cachevalspre_init_argspre_init_kw_only_argsNLr   r   r   r  .  sl  





	
	














 



"r  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.
    r$  )lstripr   r   r   r   r   2	  s   
r   c                   @  sj   e Zd ZdZdZ										dddZdd Zed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`.
    )r   r1   r2   r3   r:   r;   r<   r=   r5   r6   r8   r/   r7   r9   r   r>   r?   NFc                 C  s   t ||p||p|d\}}}}t| }|d| |d| |d| |d| |d| |d| |d| |d	| |d
| |d| |d| |d|	rVtt|	nt |d|
 |d| |d| |d| |d| d S )NTr   r1   r2   r3   r:   r;   r<   r=   r5   r6   r7   r8   r/   r9   r   r>   r?   )r@   r   r   typesMappingProxyTyper  _EMPTY_METADATA_SINGLETON)r   r   r1   r2   r3   r4   r5   r6   r   r8   r/   r7   r9   r:   r;   r<   r=   r>   r?   bound_setattrr   r   r   r  ~	  s4   















zAttribute.__init__c                 C  s   t r*   )r   r   r   r   r   r   	  r!   zAttribute.__setattr__r   rP   r   rJ   c                 C  st   |d u r|j }n|j d urd| d}t|| ||j|j|jd |j|jd|j||j|j	|j
|j|j|j|j|jS )Nz>Type annotation and type argument cannot both be present for 'z'.F)r/   rB   _default
_validatorr3   r5   r6   r8   r7   r9   r:   r;   r<   r=   r>   r?   )r   r   r   r/   rL   r   r   r   r   	  s2   
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   r   	  s   
zAttribute.evolvec                      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 )r8   N)r   r  r8   r=  r   r   r   r   	  s
    
z)Attribute.__getstate__.<locals>.<genexpr>rG   r>  r   r   r   r   r  	  s   zAttribute.__getstate__c                 C  s   |  t| j| dS rM  N)rJ  ro  r>  r   rp  r   r   r   r  	  s   zAttribute.__setstate__c                 C  sL   t | }|D ]\}}|dkr||| q|||r tt|nt qd S )Nr8   )r   r   rC  rD  r  rE  )r   name_values_pairsrF  r   r   r   r   r   rJ  	  s   
zAttribute._setattrs)
NNNFNNNNNNr*   )r   rP   r   rJ   )r#   r$   r%   r&   r>  r  r   rO  r   r   r  r  rJ  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 )NTFr8   )r   r1   r2   r3   r4   r:   r<   r5   r6   r   r?   )r   r   r   r=  r   r   r   r   
  s     r   r  c                 C  s   g | ]	}|j d kr|qS r   r   r   r   r   r   r   
  s    c                 C  s    g | ]}|j r|jd kr|qS r   )r5   r   r   r   r   r   r   
  s     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 )rJ   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.
    )rG  rH  r?   r7   r   r:   r;   r5   r6   r9   r8   r>   r<   r=   r3   r/   c                 c  s:    | ]}t |t|td dd ddddd dd dd dV  qd S )NTFr   r?   r1   r2   r3   r4   r5   r6   r9   r:   r;   r<   r=   r   r>   )r   r   r   r=  r   r   r   r   =
  s*    
z_CountingAttr.<genexpr>)	r   rG  r3   r:   r<   r5   r6   r>   r?   r8   NTFrR  r   c                 C  st   t  jd7  _t j| _|| _|| _|| _|| _|| _|| _|| _	|| _
|| _|| _|| _|	| _|
| _|| _|| _d S r   )rJ   cls_counterr   rG  rH  r7   r3   r:   r;   r<   r=   r5   r6   r8   r/   r9   r>   r?   )r   r1   r2   r3   r4   r5   r6   r7   r8   r/   r9   r:   r;   r<   r=   r>   r?   r   r   r   r  o
  s"   
z_CountingAttr.__init__c                 C  s&   | j du r
|| _ |S t| j || _ |S )z
        Decorator that adds *meth* to the list of validators.

        Returns *meth* unchanged.

        .. versionadded:: 17.1.0
        N)rH  rI   r   r  r   r   r   r2   
  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/  )rG  r   r   rD   rT  r   r   r   r1   
  s   
z_CountingAttr.default)r#   r$   r%   r&   r>  rG   r   r   rS  r  r2   r1   r   r   r   r   rJ   !
  s<    1%rJ   c                   @  s.   e Zd ZdZdZdddZdd Zdd	 Zd
S )rD   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*
    rK   r/  Fc                 C  s   || _ || _d S r*   rU  )r   rK   r/  r   r   r   r  
  s   
zFactory.__init__c                   rL  )rM  c                 3  s    | ]}t  |V  qd S r*   r<  r=  r   r   r   r   
      z'Factory.__getstate__.<locals>.<genexpr>rN  r   r   r   r   r  
  s   zFactory.__getstate__c                 C  s&   t | j|D ]
\}}t| || qdS rO  )ro  r>  r4  )r   rp  r   r   r   r   r   r  
  s   zFactory.__setstate__N)F)r#   r$   r%   r&   r>  r  r  r  r   r   r   r   rD   
  s    
rD   c                 C  (   g | ]}t |td dd dddddd
qS NTF)
r   r1   r2   r3   r4   r:   r<   r5   r6   r   r   r   r=  r   r   r   r   
      c                   @  sL   e Zd ZdZdZdddddZedd
dZ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__r2  _global_namer7   takes_fieldr/  Fr/  r]  c                  s   | _ | _| _t|}|  _ js  js  fdd _n# jr. js. fdd _n js< jr< fdd _n fdd _| }|d urS| jjd< d S d S )Nc                   s
     | S r*   r7   )r   r$  __r   r   r   r     r   z$Converter.__init__.<locals>.<lambda>c                   s     | |S r*   r_  )r   instancer`  r   r   r   r         c                   s     | |S r*   r_  )r   r`  r  r   r   r   r     rb  c                   s     | ||S r*   r_  )r   ra  r  r   r   r   r   #  s    rV   )	r7   r/  r]  r   get_first_param_typer2  r[  get_return_typer~   )r   r7   r/  r]  exrtr   r   r   r    s    
zConverter.__init__rv   rP   rV   c                 C  s
   d|  S )zh
        Return the name that a converter for an attribute name *attr_name*
        would have.
        __attr_converter_r   )rv   r   r   r   r1  +  s   
zConverter._get_global_namer  c                 C  s   | j s| js| | d| dS | j r%| jr%| | d| d| dS | j r3| | 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  r  z, self, attr_dict['z'])z, self)z, attr_dict[')r/  r]  r1  )r   rv   r  r   r   r   r  3  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.
        r7   r/  r]  rh  r   r   r   r   r  D  s   zConverter.__getstate__c                 C  s   | j di | dS )z+
        Load instance from state.
        Nr   r  rP  r   r   r   r  O  s   zConverter.__setstate__N)rv   rP   rV   rP   )rv   rP   r  rP   rV   rP   )r#   r$   r%   r&   r>  r  rP  r1  r  r  r  r   r   r   r   r  
  s    	
c                 C  rW  rX  rY  r=  r   r   r   r   V  rZ  rh  c                   sj  t d| } t|tr|}nt|ttfrdd |D }nd}t||dd}|dd}|dd}	i  |dur@ | |durH| d< |durP| d< |	durX|	 d< t	
| |i  fd	d
}
ttt tdjdd|
_W d   n1 sw   Y  |dd}t||d|dd\|d< |d< td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)``

    .. warning::

        It is *your* duty to ensure that the class name and the attribute names
        are valid identifiers. ``make_class()`` will *not* validate them for
        you.

    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*
    .. versionchanged:: 25.2.0 Class names can now be unicode.
    NFKCc                 S  s   i | ]}|t  qS r   )rM   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#  )re  ru   r   r   r     r   zmake_class.<locals>.<lambda>r	   r#   __main__r4   r:   r<   Tr   c                 S  s"   i | ]\}}|j d ur||j qS r*   )r/   r7  r   r   r   r:    s    r   )unicodedata	normalizerE   r  rF   rG   rA   popr#  rC  	new_classr0  r1  r2  rB   r  	_getframe	f_globalsr   r$   r  r   r   r~   )r   ry   bases
class_bodyattributes_argumentsra  rL   r	  r  	user_inittype_r4   r   r   rj  r   
make_classk  sP   0

rw  )r  r  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   r9  r   r   r   r[    s   
z_AndValidator.__call__N)r#   r$   r%   r&   rM   ry  r[  r   r   r   r   rx    s    rx  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   rE   rx  ry  rG   )
validatorsr>  r2   r   r   r   rI     s   rI   c                    s   t dd  D }|r fdd}n fdd} s(td}|j||d n*t d  }|r7||jd	<  d
 }tsEt|trE|j	}t|
 }|rR||jd< |r[t|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*   rE   r  )r   cr   r   r   r   
  rV  zpipe.<locals>.<genexpr>c                   s,    D ]}t |tr|| ||n|| } q| S r*   r{  )r  r   r  r|  
convertersr   r   pipe_converter  s   zpipe.<locals>.pipe_converterc                   s    D ]}|| } q| S r*   r   )r  r|  r}  r   r   r    s   
A)r  rV   r   r  r_   rV   Tr^  )r  r   r~   r#  r   rc  r   rE   r  r[  rd  )r~  return_instancer  r  tlastrf  r   r}  r   rH     s&   


rH   )NrN   )
rO   rP   rQ   rR   rS   rT   rU   rP   rV   rW   r*   )
rO   rP   rU   rP   rQ   rR   r]   rT   rV   r^   )rl   rP   rm   rn   rV   r/   )rV   r   )rV   rx   )T)NNNNNNNFFTFFFFFNNFFNNNTN)r   r/   r  rP   rV   rP   )
r   r/   ry   rz   r  r  r  r  rV   r  )r   r/   ry   rz   )ry   rF   rV   r  )rV   r  )NN)rV   r  r   r!  )rv   rP   r   rP   r  r  rV   rP   )r  r  r  r  r   r|   )ry   rz   r  r  r#  r  r$  r  r
  r  r%  r  r&  r  r   r|   r  r  r  r  r  r  r'  rP   rV   r  )r   rP   rV   rP   )i
__future__r   r+  r0  rI  r'   r	  rL  rd   r  rC  rl  collections.abcr   r   	functoolsr   typingr   r   r   rN   r
   r   r   r   r   r   r   r   r   
exceptionsr   r   r   r   objectr   r   r0  r   rK  rD  rE  r/  rH   r  r  r  Enumr   r   intr)   rM   r\   rk   rw   rx   r   r   r   r   r   r   r   r   r   r   r  r@   r  ry   r   r  r   rz  r  r  r  r  r  rd  r  r   r   r  r  r  r  r  r  r"  r  r   r   r>  _arJ   rD   _fr  rw  rx  rI   r   r   r   r   <module>   s4   		

n
#
!
l4:    N,

 d



H
%
8

9.

E





/  
 K
	 'd

k