Your IP : 3.144.1.100


Current Path : /opt/alt/python37/lib/python3.7/site-packages/attr/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/attr/__pycache__/_make.cpython-37.pyc

B

�Q�`�}�@s�ddlmZmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZddlmZmZmZmZmZmZmZmZddlmZmZmZmZmZes�ddlZe j!Z"dZ#d	Z$d
Z%dZ&dZ'ei�Z(e �Z)Gd
d�de �Z*e*�Z+Gdd�de,�Z-e+dddddddddddddfdd�Z.d�dd�Z/d�dd�Z0dd�Z1e1ddddg�Z2d d!�Z3d"d#�Z4d$d%�Z5d&d'�Z6d(d)�Z7d*d+�Z8d,d-�Z9e�r�d.d/�Z:nd0d/�Z:d1d2�Z;Gd3d4�d4e �Z<d5Z=d6d7�Z>d8d9�Z?d�d:d;�Z@d�d<d�ZAeAZBe�r�d=d>�ZCnd?d>�ZCd@dA�ZDdBdC�ZEdDdE�ZFdFdG�ZGdHdI�ZHdJdK�ZId�dLdM�ZJe�K�ZLdNdO�ZMd�dPdQ�ZNdRdS�ZOdTdU�ZPdVdW�ZQdXdY�ZRdZd[�ZSd\d]�ZTd^d_�ZUd`da�ZVdbdc�ZWddde�ZXe�r�d�dfdg�ZYdhdi�ZZdjdk�Z[Gdldm�dme �Z\dndo�e\j]D�Z^eFeJeNe\e^dp�dqdo�e^D�dp�drdo�e^D�dp�Z\Gdsdt�dte �Z_eJeNe_��Z_Gdudv�dve �Z`dwdo�e`j]D�ZaeFeJeNe`eadp�eadp�eadp�Z`e ffdxdy�ZbeAdddz�Gd{d|�d|e ��Zcd}d~�Zddd��ZedS)��)�absolute_import�division�print_functionN)�
itemgetter�)�_config�setters)�PY2�PYPY�isclass�	iteritems�metadata_proxy�	new_class�ordered_dict�set_closure_cell)�DefaultAlreadySetError�FrozenInstanceError�NotAnAttrsClassError�PythonTooOldError�UnannotatedAttributeErrorz__attr_converter_%sz__attr_factory_{}z=    {attr_name} = _attrs_property(_attrs_itemgetter({index})))ztyping.ClassVarz
t.ClassVar�ClassVarztyping_extensions.ClassVarZ_attrs_cached_hashcs<eZdZdZdZ�fdd�Zdd�Zdd�Zd	d
�Z�Z	S)�_Nothingz�
    Sentinel class to indicate the lack of a value when ``None`` is ambiguous.

    ``_Nothing`` is a singleton. There is only ever one of it.

    .. versionchanged:: 21.1.0 ``bool(NOTHING)`` is now False.
    Ncs"tjdkrtt|��|�t_tjS)N)r�
_singleton�super�__new__)�cls)�	__class__��;/opt/alt/python37/lib/python3.7/site-packages/attr/_make.pyrHs
z_Nothing.__new__cCsdS)N�NOTHINGr)�selfrrr�__repr__Msz_Nothing.__repr__cCsdS)NFr)r rrr�__bool__Psz_Nothing.__bool__cCsdS)Nrr)r rrr�__len__Ssz_Nothing.__len__)
�__name__�
__module__�__qualname__�__doc__rrr!r"r#�
__classcell__rr)rrr=src@s6eZdZdZer edfdd�Zned�dfdd�ZdS)�_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.
    )r�NcCs||fS)Nr)r �_none_constructor�_argsrrr�
__reduce__msz_CacheHashWrapper.__reduce__NrcCs||fS)Nr)r r+r,rrrr-rs)r$r%r&r'r	�getattrr-�typerrrrr)]s
r)TFcCs�t|||d�\}}}}|dk	r6|dk	r6|dk	r6td��|	dk	rf|tk	rNtd��t|	�s^td��t|	�}|dkrri}t|
ttf�r�t	j
|
�}
|r�t|ttf�r�t|�}|r�t|ttf�r�t
|�}t|||d||||||
|||||
d�S)a|
    Create a new attribute on a class.

    ..  warning::

        Does *not* do anything unless the class is also decorated with
        `attr.s`!

    :param default: A value that is used if an ``attrs``-generated ``__init__``
        is used and no value is passed while instantiating or the attribute is
        excluded using ``init=False``.

        If the value is an instance of `Factory`, its callable will be
        used to construct a new value (useful for mutable data types like lists
        or dicts).

        If a default is not set (or set manually to `attr.NOTHING`), a value
        *must* be supplied when instantiating; otherwise a `TypeError`
        will be raised.

        The default can also be set using decorator notation as shown below.

    :type default: Any value

    :param callable factory: Syntactic sugar for
        ``default=attr.Factory(factory)``.

    :param validator: `callable` that is called by ``attrs``-generated
        ``__init__`` methods after the instance has been initialized.  They
        receive the initialized instance, the `Attribute`, and the
        passed value.

        The return value is *not* inspected so the validator has to throw an
        exception itself.

        If a `list` is passed, its items are treated as validators and must
        all pass.

        Validators can be globally disabled and re-enabled using
        `get_run_validators`.

        The validator can also be set using decorator notation as shown below.

    :type validator: `callable` or a `list` of `callable`\ s.

    :param repr: Include this attribute in the generated ``__repr__``
        method. If ``True``, include the attribute; if ``False``, omit it. By
        default, the built-in ``repr()`` function is used. To override how the
        attribute value is formatted, pass a ``callable`` that takes a single
        value and returns a string. Note that the resulting string is used
        as-is, i.e. it will be used directly *instead* of calling ``repr()``
        (the default).
    :type repr: a `bool` or a `callable` to use a custom function.

    :param eq: If ``True`` (default), include this attribute in the
        generated ``__eq__`` and ``__ne__`` methods that check two instances
        for equality. To override how the attribute value is compared,
        pass a ``callable`` that takes a single value and returns the value
        to be compared.
    :type eq: a `bool` or a `callable`.

    :param order: If ``True`` (default), include this attributes in the
        generated ``__lt__``, ``__le__``, ``__gt__`` and ``__ge__`` methods.
        To override how the attribute value is ordered,
        pass a ``callable`` that takes a single value and returns the value
        to be ordered.
    :type order: a `bool` or a `callable`.

    :param cmp: Setting *cmp* is equivalent to setting *eq* and *order* to the
        same value. Must not be mixed with *eq* or *order*.
    :type cmp: a `bool` or a `callable`.

    :param Optional[bool] hash: Include this attribute in the generated
        ``__hash__`` method.  If ``None`` (default), mirror *eq*'s value.  This
        is the correct behavior according the Python spec.  Setting this value
        to anything else than ``None`` is *discouraged*.
    :param bool init: Include this attribute in the generated ``__init__``
        method.  It is possible to set this to ``False`` and set a default
        value.  In that case this attributed is unconditionally initialized
        with the specified default value or factory.
    :param callable converter: `callable` that is called by
        ``attrs``-generated ``__init__`` methods to convert attribute's value
        to the desired format.  It is given the passed-in value, and the
        returned value will be used as the new value of the attribute.  The
        value is converted before being passed to the validator, if any.
    :param metadata: An arbitrary mapping, to be used by third-party
        components.  See `extending_metadata`.
    :param type: The type of the attribute.  In Python 3.6 or greater, the
        preferred method to specify the type is using a variable annotation
        (see `PEP 526 <https://www.python.org/dev/peps/pep-0526/>`_).
        This argument is provided for backward compatibility.
        Regardless of the approach used, the type will be stored on
        ``Attribute.type``.

        Please note that ``attrs`` doesn't do anything with this metadata by
        itself. You can use it as part of your own code or for
        `static type checking <types>`.
    :param kw_only: Make this attribute keyword-only (Python 3+)
        in the generated ``__init__`` (if ``init`` is ``False``, this
        parameter is ignored).
    :param on_setattr: Allows to overwrite the *on_setattr* setting from
        `attr.s`. If left `None`, the *on_setattr* value from `attr.s` is used.
        Set to `attr.setters.NO_OP` to run **no** `setattr` hooks for this
        attribute -- regardless of the setting in `attr.s`.
    :type on_setattr: `callable`, or a list of callables, or `None`, or
        `attr.setters.NO_OP`

    .. 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
    TNFz6Invalid 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)
�_determine_attrib_eq_order�	TypeErrorr�
ValueError�callable�Factory�
isinstance�list�tupler�pipe�and_�
_CountingAttr)r0r1r2r3r4r5r7r/r6�factoryr8r9r;r=r:r<rrr�attribvsJ
rJr*cCst||d�}t|||�dS)zU
    "Exec" the script with the given global (globs) and local (locs) variables.
    �execN)�compile�eval)�script�globs�locs�filename�bytecoderrr�_compile_and_eval:srScCsBi}|dkri}t||||�t|�d|�d�|ftj|<||S)zO
    Create the method with the script given and return the method object.
    NT)rS�len�
splitlines�	linecache�cache)�namerNrQrOrPrrr�_make_methodBsrYcCstd�|�}d�|�dg}|rHx4t|�D]\}}|�tj||d��q&Wn
|�d�ttd�}td�|�|�||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{}Attributeszclass {}(tuple):z    __slots__ = ())�index�	attr_namez    pass)Z_attrs_itemgetterZ_attrs_property�
)�format�	enumerate�append�_tuple_property_patr�propertyrS�join)Zcls_name�
attr_namesZattr_class_nameZattr_class_template�ir[rOrrr�_make_attr_tuple_classXs



re�_Attributes�attrs�
base_attrsZbase_attrs_mapcCs2t|�}|�d�r(|�d�r(|dd�}|�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���)�str�
startswith�endswith�_classvar_prefixes)Zannotrrr�
_is_class_var�srpcCsLt||t�}|tkrdSx.|jdd�D]}t||d�}||kr(dSq(WdS)zj
    Check whether *cls* defines *attrib_name* (and doesn't just inherit it).

    Requires Python 3.
    FrNT)r.�	_sentinel�__mro__)rZattrib_name�attr�base_cls�arrr�_has_own_attribute�srvcCst|d�r|jSiS)z$
    Get annotations for *cls*.
    �__annotations__)rvrw)rrrr�_get_annotations�s
rxcCs
|djS)zQ
    Key function for sorting to avoid re-creating a lambda for every class.
    r)�counter)�errr�_counter_getter�sr{cCs�g}i}xbt|jdd��D]L}xFt|dg�D]6}|js.|j|krDq.|jdd�}|�|�|||j<q.WqWg}t�}x4t|�D](}|j|kr�q�|�d|�|�	|j�q�W||fS)zQ
    Collect attr.ibs from base classes of *cls*, except *taken_attr_names*.
    rrk�__attrs_attrs__T)�	inheritedr)
�reversedrrr.r}rX�evolver_�set�insert�add)r�taken_attr_namesrh�
base_attr_maprtru�filtered�seenrrr�_collect_base_attrs�s"

r�cCsvg}i}xd|jdd�D]R}xLt|dg�D]<}|j|kr:q*|jdd�}|�|j�|�|�|||j<q*WqW||fS)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.
    rrkr|T)r})rrr.rXrr�r_)rr�rhr�rtrurrr�_collect_base_attrs_broken�s

r�c	s>|j�t|��|dk	r@dd�t|�D�}t|t�s>|jtd�n�|dk�rdd����D�}g}t�}xf���D]Z\}	}
t	|
�r�qp|�
|	���|	t�}t|t
�s�|tkr�t�}n
t|d�}|�|	|f�qpW||}t|�d	k�r*td
d�t|�fdd
�d��d��ntdd����D�dd
�d�}�fdd�|D�}
|�r\t|dd�|
D��\}}nt|dd�|
D��\}}dd�||
D�}t|j|�}|�r�dd�|
D�}
dd�|D�}|||
�}d}xVdd�|D�D]D}|dk�r�|jtk�r�td|f��|dk�r�|jtk	�r�d}�q�W|dk	�r0|||�}t|||f�S)a0
    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.

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

    Return an `_Attributes`.
    NcSsg|]\}}||f�qSrr)�.0rX�carrr�
<listcomp>sz$_transform_attrs.<locals>.<listcomp>)�keyTcSsh|]\}}t|t�r|�qSr)rCrH)r�rXrsrrr�	<setcomp>sz#_transform_attrs.<locals>.<setcomp>)r0rz1The following `attr.ib`s lack a type annotation: z, cs��|�jS)N)�getry)�n)�cdrr�<lambda> �z"_transform_attrs.<locals>.<lambda>�.css$|]\}}t|t�r||fVqdS)N)rCrH)r�rXrsrrr�	<genexpr>'sz#_transform_attrs.<locals>.<genexpr>cSs
|djS)Nr)ry)rzrrrr�+r�cs&g|]\}}tj||��|�d��qS))rXr�r/)�	Attribute�from_counting_attrr�)r�r[r�)�annsrrr�/scSsh|]
}|j�qSr)rX)r�rurrrr�7scSsh|]
}|j�qSr)rX)r�rurrrr�;scSsg|]
}|j�qSr)rX)r�rurrrr�>scSsg|]}|jdd��qS)T)r8)r)r�rurrrr�CscSsg|]}|jdd��qS)T)r8)r)r�rurrrr�DsFcss&|]}|jdk	r|jdkr|VqdS)FN)r5r8)r�rurrrr�MsznNo mandatory attributes allowed after an attribute with a default value or factory.  Attribute in question: %r)�__dict__rxrrCr�sortr{�itemsr�rpr�r�rrHrJr_rTrrb�sortedr�r�rer$r0r@rf)r�these�auto_attribsr8�collect_by_mro�field_transformerZca_listZca_namesZannot_namesr[r/ruZunannotatedZ	own_attrsrhr�rcZ
AttrsClassrgZhad_defaultr)r�r�r�_transform_attrs�sj





&





r�cCs.t|t�r$|dkr$t�|||�dSt��dS)z<
        Attached to frozen classes as __setattr__.
        )�	__cause__�__context__N)rC�
BaseException�__setattr__r)r rX�valuerrr�_frozen_setattrs^s
r�cCs
t��dS)z<
        Attached to frozen classes as __setattr__.
        N)r)r rXr�rrrr�nscCs
t��dS)z4
    Attached to frozen classes as __delattr__.
    N)r)r rXrrr�_frozen_delattrsusr�c@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�
_ClassBuilderz(
    Iteratively build *one* class.
    )�_attr_names�_attrs�_base_attr_map�_base_names�_cache_hash�_cls�	_cls_dict�_delete_attribs�_frozen�
_has_pre_init�_has_post_init�_is_exc�_on_setattr�_slots�
_weakref_slot�_has_own_setattr�_has_custom_setattrcCst||||||�\}}}||_|r,t|j�ni|_||_tdd�|D��|_||_t	dd�|D��|_
||_||_||_
|	|_tt|dd��|_tt|dd��|_t|�|_|
|_||_|
|_d|_|j|jd<|r�t|jd<t|jd	<d
|_|�r|��\|jd<|jd<dS)
Ncss|]}|jVqdS)N)rX)r�rurrrr��sz)_ClassBuilder.__init__.<locals>.<genexpr>css|]}|jVqdS)N)rX)r�rurrrr��s�__attrs_pre_init__F�__attrs_post_init__r|r��__delattr__T�__getstate__�__setstate__)r�r��dictr�r�r�r�r�r�rEr�r�r�r�r��boolr.r�r�r�r�r�r�r�r�r��_make_getstate_setstate)r rr��slots�frozen�weakref_slot�getstate_setstater�r8�
cache_hash�is_excr�r=Zhas_custom_setattrr�rgrhZbase_maprrr�__init__�s>

z_ClassBuilder.__init__cCsdj|jjd�S)Nz<_ClassBuilder(cls={cls})>)r)r]r�r$)r rrrr!�sz_ClassBuilder.__repr__cCs|jdkr|��S|��SdS)z�
        Finalize class based on the accumulated configuration.

        Builder cannot be used after calling this method.
        TN)r��_create_slots_class�_patch_original_class)r rrr�build_class�s
z_ClassBuilder.build_classc	Cs�|j}|j}|jr^xJ|jD]@}||krt||t�tk	ryt||�Wqtk
rXYqXqWx"|j�	�D]\}}t
|||�qjW|js�t|dd�r�d|_|j
s�tj|_|S)zA
        Apply accumulated methods and return the class.
        �__attrs_own_setattr__F)r�r�r�r�r.rq�delattr�AttributeErrorr�r��setattrr�r�r��objectr�)r r�
base_namesrXr�rrrr��s$

z#_ClassBuilder._patch_original_classc
s>�fdd�t�j�D�}�jsXd|d<�jsXx*�jjD]��j�dd�r6tj	|d<Pq6Wt
�}d}xN�jjdd�D]:��j�dd	�d	k	r�d
}|��fdd�t
�dg�D��qtWt�j���j}�jr�dt
�jdd
�kr�d|kr�|s�|d7}�fdd�|D���fdd�t|�D���fdd��D��|����j�rD��t�t��|d<t
�jdd	�}|d	k	�rp||d<t�j��jj�jj|�}x�|j��D]�}t|ttf��r�t
|jdd	�}n(t|t��r�t
|jdd	�}nt
|dd	�}|�s�q�xF|D]>}	y|	j�jk}
Wnt k
�rYnX|
�r�t!|	|��q�W�q�W|S)zL
        Build and return a new class with a `__slots__` attribute.
        cs(i|] \}}|t�j�dkr||�qS))r��__weakref__)rEr�)r��k�v)r rr�
<dictcomp>sz5_ClassBuilder._create_slots_class.<locals>.<dictcomp>Fr�r�rrkr�NTcsi|]}t�|�|�qSr)r.)r�rX)rtrrr�'s�	__slots__r)r�csg|]}|�kr|�qSrr)r�rX)r�rrr�:sz5_ClassBuilder._create_slots_class.<locals>.<listcomp>csi|]\}}|�kr||�qSrr)r�ZslotZslot_descriptor)�
slot_namesrrr�?scsg|]}|�kr|�qSrr)r�rX)�reused_slotsrrr�Dsr&�__closure__)"rr�r�r�r��	__bases__r�r�r�r�r�rr�updater.r�r�r�r�r�r_�_hash_cache_fieldrEr/r$�valuesrC�classmethod�staticmethod�__func__ra�fget�
cell_contentsr@r)r r�Zexisting_slotsZweakref_inherited�names�qualnamer�itemZ
closure_cells�cell�matchr)rtr�r�r r�rr�sh








z!_ClassBuilder._create_slots_classcCs|�t|j|d��|jd<|S)N)�nsr!)�_add_method_dunders�
_make_reprr�r�)r r�rrr�add_reprpsz_ClassBuilder.add_reprcCs8|j�d�}|dkrtd��dd�}|�|�|jd<|S)Nr!z3__str__ can only be generated if a __repr__ exists.cSs|��S)N)r!)r rrr�__str__}sz&_ClassBuilder.add_str.<locals>.__str__r�)r�r�r@r�)r r2r�rrr�add_strvsz_ClassBuilder.add_strcs<tdd�|jD����fdd�}|j���fdd�}||fS)zF
        Create custom __setstate__ and __getstate__ methods.
        css|]}|dkr|VqdS)r�Nr)r�Zanrrrr��sz8_ClassBuilder._make_getstate_setstate.<locals>.<genexpr>cst�fdd��D��S)z9
            Automatically created by attrs.
            c3s|]}t�|�VqdS)N)r.)r�rX)r rrr��szP_ClassBuilder._make_getstate_setstate.<locals>.slots_getstate.<locals>.<genexpr>)rE)r )�state_attr_names)r r�slots_getstate�sz=_ClassBuilder._make_getstate_setstate.<locals>.slots_getstatecs@t�|t�}x t�|�D]\}}|||�qW�r<|td�dS)z9
            Automatically created by attrs.
            N)�_obj_setattr�__get__r��zipr�)r �stateZ_ClassBuilder__bound_setattrrXr�)�hash_caching_enabledr�rr�slots_setstate�s
z=_ClassBuilder._make_getstate_setstate.<locals>.slots_setstate)rEr�r�)r r�r�r)r�r�rr��sz%_ClassBuilder._make_getstate_setstatecCsd|jd<|S)N�__hash__)r�)r rrr�make_unhashable�s
z_ClassBuilder.make_unhashablecCs(|�t|j|j|j|jd��|jd<|S)N)r�r�r�)r��
_make_hashr�r�r�r�r�)r rrr�add_hash�sz_ClassBuilder.add_hashcCsR|�t|j|j|j|j|j|j|j|j	|j
|jdk	o>|jtj
k	dd��|jd<|S)NF)�
attrs_initr�)r��
_make_initr�r�r�r�r�r�r�r�r�r�r�NO_OPr�)r rrr�add_init�s

z_ClassBuilder.add_initcCsR|�t|j|j|j|j|j|j|j|j	|j
|jdk	o>|jtj
k	dd��|jd<|S)NT)r��__attrs_init__)r�r�r�r�r�r�r�r�r�r�r�r�rr�r�)r rrr�add_attrs_init�s

z_ClassBuilder.add_attrs_initcCs2|j}|�t|j|j��|d<|�t��|d<|S)N�__eq__�__ne__)r�r��_make_eqr�r��_make_ne)r r�rrr�add_eq�s
z_ClassBuilder.add_eqcs>�j}�fdd�t�j�j�D�\|d<|d<|d<|d<�S)Nc3s|]}��|�VqdS)N)r�)r��meth)r rrr��sz*_ClassBuilder.add_order.<locals>.<genexpr>�__lt__�__le__�__gt__�__ge__)r��_make_orderr�r�)r r�r)r r�	add_order�s
*z_ClassBuilder.add_ordercs�|jr
|Si�x6|jD],}|jp$|j}|r|tjk	r||f�|j<qW�sN|S|jr\td���fdd�}d|j	d<|�
|�|j	d<d|_|S)Nz7Can't combine custom __setattr__ with on_setattr hooks.csFy�|\}}Wntk
r(|}YnX||||�}t|||�dS)N)�KeyErrorr�)r rX�valru�hookZnval)�sa_attrsrrr�s
z._ClassBuilder.add_setattr.<locals>.__setattr__Tr�r�)r�r�r=r�rr�rXr�r@r�r�r�)r rur=r�r)rr�add_setattr�s"

z_ClassBuilder.add_setattrcCs�y|jj|_Wntk
r"YnXyd�|jj|jf�|_Wntk
rRYnXyd|jjf|_Wntk
r|YnX|S)zL
        Add __module__ and __qualname__ to a *method* if possible.
        r�z'Method generated by attrs for class %s.)r�r%r�rbr&r$r')r �methodrrrr�sz!_ClassBuilder._add_method_dundersN)r$r%r&r'r�r�r!r�r�r�r�r�r�r�r�r�r�rrrr�rrrrr�|s$;&l
"

$r�zrThe usage of `cmp` is deprecated and will be removed on or after 2021-06-01.  Please use `eq` and `order` instead.cCsl|dk	r$t|dk	|dk	f�r$td��|dk	r4||fS|dkr@|}|dkrL|}|dkrd|dkrdtd��||fS)z�
    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*.
    Nz&Don't mix `cmp` with `eq' and `order`.FTz-`order` can only be True if `eq` is True too.)�anyr@)r3r9r;�
default_eqrrr�_determine_attrs_eq_order5srcCs�|dk	r$t|dk	|dk	f�r$td��dd�}|dk	rL||�\}}||||fS|dkr`|d}}n||�\}}|dkr�||}}n||�\}}|dkr�|dkr�td��||||fS)z�
    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*.
    Nz&Don't mix `cmp` with `eq' and `order`.cSs t|�rd|}}nd}||fS)z8
        Decide whether a key function is used.
        TN)rA)r�r�rrr�decide_callable_or_booleanWsz>_determine_attrib_eq_order.<locals>.decide_callable_or_booleanFTz-`order` can only be True if `eq` is True too.)rr@)r3r9r;rrZcmp_keyr:r<rrrr>Osr>cCsH|dks|dkr|S|dkr(|dkr(|Sx|D]}t||�r.dSq.W|S)a�
    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.

    auto_detect must be False on Python 2.
    TFN)rv)r�flag�auto_detectZdundersr0Zdunderrrr�_determine_whether_to_implementxs

rcs��rtrtd��t|||d�\��
|�	t�ttf�r>tj�������������	�
���
������fdd�}|dkr||S||�SdS)a�2
    A class decorator that adds `dunder
    <https://wiki.python.org/moin/DunderAlias>`_\ -methods according to the
    specified attributes using `attr.ib` or the *these* argument.

    :param these: A dictionary of name to `attr.ib` mappings.  This is
        useful to avoid the definition of your attributes within the class body
        because you can't (e.g. if you want to add ``__repr__`` methods to
        Django models) or don't want to.

        If *these* is not ``None``, ``attrs`` will *not* search the class body
        for attributes and will *not* remove any attributes from it.

        If *these* is an ordered dict (`dict` on Python 3.6+,
        `collections.OrderedDict` otherwise), the order is deduced from
        the order of the attributes inside *these*.  Otherwise the order
        of the definition of the attributes is used.

    :type these: `dict` of `str` to `attr.ib`

    :param str repr_ns: When using nested classes, there's no way in Python 2
        to automatically detect that.  Therefore it's possible to set the
        namespace explicitly for a more meaningful ``repr`` output.
    :param bool auto_detect: Instead of setting the *init*, *repr*, *eq*,
        *order*, and *hash* arguments explicitly, assume they are set to
        ``True`` **unless any** of the involved methods for one of the
        arguments is implemented in the *current* class (i.e. it is *not*
        inherited from some base class).

        So for example by implementing ``__eq__`` on a class yourself,
        ``attrs`` will deduce ``eq=False`` and will create *neither*
        ``__eq__`` *nor* ``__ne__`` (but Python classes come with a sensible
        ``__ne__`` by default, so it *should* be enough to only implement
        ``__eq__`` in most cases).

        .. warning::

           If you prevent ``attrs`` from creating the ordering methods for you
           (``order=False``, e.g. by implementing ``__le__``), it becomes
           *your* responsibility to make sure its ordering is sound. The best
           way is to use the `functools.total_ordering` decorator.


        Passing ``True`` or ``False`` to *init*, *repr*, *eq*, *order*,
        *cmp*, or *hash* overrides whatever *auto_detect* would determine.

        *auto_detect* requires Python 3. Setting it ``True`` on Python 2 raises
        a `PythonTooOldError`.

    :param bool repr: Create a ``__repr__`` method with a human readable
        representation of ``attrs`` attributes..
    :param bool str: Create a ``__str__`` method that is identical to
        ``__repr__``.  This is usually not necessary except for
        `Exception`\ s.
    :param Optional[bool] eq: If ``True`` or ``None`` (default), add ``__eq__``
        and ``__ne__`` methods that check two instances for equality.

        They compare the instances as if they were tuples of their ``attrs``
        attributes if and only if the types of both classes are *identical*!
    :param Optional[bool] order: If ``True``, add ``__lt__``, ``__le__``,
        ``__gt__``, and ``__ge__`` methods that behave like *eq* above and
        allow instances to be ordered. If ``None`` (default) mirror value of
        *eq*.
    :param Optional[bool] cmp: Setting *cmp* is equivalent to setting *eq*
        and *order* to the same value. Must not be mixed with *eq* or *order*.
    :param Optional[bool] hash: If ``None`` (default), the ``__hash__`` method
        is generated according how *eq* and *frozen* are set.

        1. If *both* are True, ``attrs`` will generate a ``__hash__`` for you.
        2. If *eq* is True and *frozen* is False, ``__hash__`` will be set to
           None, marking it unhashable (which it is).
        3. If *eq* is False, ``__hash__`` will be left untouched meaning the
           ``__hash__`` method of the base class will be used (if base class is
           ``object``, this means it will fall back to id-based hashing.).

        Although not recommended, you can decide for yourself and force
        ``attrs`` to create one (e.g. if the class is immutable even though you
        didn't freeze it programmatically) by passing ``True`` or not.  Both of
        these cases are rather special and should be used carefully.

        See our documentation on `hashing`, Python's documentation on
        `object.__hash__`, and the `GitHub issue that led to the default \
        behavior <https://github.com/python-attrs/attrs/issues/136>`_ for more
        details.
    :param bool init: Create a ``__init__`` method that initializes the
        ``attrs`` attributes. Leading underscores are stripped for the argument
        name. If a ``__attrs_pre_init__`` method exists on the class, it will
        be called before the class is initialized. If a ``__attrs_post_init__``
        method exists on the class, it will be called after the class is fully
        initialized.

        If ``init`` is ``False``, an ``__attrs_init__`` method will be
        injected instead. This allows you to define a custom ``__init__``
        method that can do pre-init work such as ``super().__init__()``,
        and then call ``__attrs_init__()`` and ``__attrs_post_init__()``.
    :param bool slots: Create a `slotted class <slotted classes>` that's more
        memory-efficient. Slotted classes are generally superior to the default
        dict classes, but have some gotchas you should know about, so we
        encourage you to read the `glossary entry <slotted classes>`.
    :param bool frozen: Make instances immutable after initialization.  If
        someone attempts to modify a frozen instance,
        `attr.exceptions.FrozenInstanceError` is raised.

        .. note::

            1. This is achieved by installing a custom ``__setattr__`` method
               on your class, so you can't implement your own.

            2. True immutability is impossible in Python.

            3. This *does* have a minor a runtime performance `impact
               <how-frozen>` when initializing new instances.  In other words:
               ``__init__`` is slightly slower with ``frozen=True``.

            4. If a class is frozen, you cannot modify ``self`` in
               ``__attrs_post_init__`` or a self-written ``__init__``. You can
               circumvent that limitation by using
               ``object.__setattr__(self, "attribute_name", value)``.

            5. Subclasses of a frozen class are frozen too.

    :param bool weakref_slot: Make instances weak-referenceable.  This has no
        effect unless ``slots`` is also enabled.
    :param bool auto_attribs: If ``True``, collect `PEP 526`_-annotated
        attributes (Python 3.6 and later only) from the class body.

        In this case, you **must** annotate every field.  If ``attrs``
        encounters a field that is set to an `attr.ib` but lacks a type
        annotation, an `attr.exceptions.UnannotatedAttributeError` is
        raised.  Use ``field_name: typing.Any = attr.ib(...)`` if you don't
        want to set a type.

        If you assign a value to those attributes (e.g. ``x: int = 42``), that
        value becomes the default value like if it were passed using
        ``attr.ib(default=42)``.  Passing an instance of `Factory` also
        works as expected in most cases (see warning below).

        Attributes annotated as `typing.ClassVar`, and attributes that are
        neither annotated nor set to an `attr.ib` are **ignored**.

        .. warning::
           For features that use the attribute name to create decorators (e.g.
           `validators <validators>`), you still *must* assign `attr.ib` to
           them. Otherwise Python will either not find the name or try to use
           the default value to call e.g. ``validator`` on it.

           These errors can be quite confusing and probably the most common bug
           report on our bug tracker.

        .. _`PEP 526`: https://www.python.org/dev/peps/pep-0526/
    :param bool kw_only: Make all attributes keyword-only (Python 3+)
        in the generated ``__init__`` (if ``init`` is ``False``, this
        parameter is ignored).
    :param bool cache_hash: Ensure that the object's hash code is computed
        only once and stored on the object.  If this is set to ``True``,
        hashing must be either explicitly or implicitly enabled for this
        class.  If the hash code is cached, avoid any reassignments of
        fields involved in hash code computation or mutations of the objects
        those fields point to after object creation.  If such changes occur,
        the behavior of the object's hash code is undefined.
    :param bool auto_exc: If the class subclasses `BaseException`
        (which implicitly includes any subclass of any exception), the
        following happens to behave like a well-behaved Python exceptions
        class:

        - the values for *eq*, *order*, and *hash* are ignored and the
          instances compare and hash by the instance's ids (N.B. ``attrs`` will
          *not* remove existing implementations of ``__hash__`` or the equality
          methods. It just won't add own ones.),
        - all attributes that are either passed into ``__init__`` or have a
          default value are additionally available as a tuple in the ``args``
          attribute,
        - the value of *str* is ignored leaving ``__str__`` to base classes.
    :param bool collect_by_mro: Setting this to `True` fixes the way ``attrs``
       collects attributes from base classes.  The default behavior is
       incorrect in certain cases of multiple inheritance.  It should be on by
       default but is kept off for backward-compatability.

       See issue `#428 <https://github.com/python-attrs/attrs/issues/428>`_ for
       more details.

    :param Optional[bool] getstate_setstate:
       .. note::
          This is usually only interesting for slotted classes and you should
          probably just set *auto_detect* to `True`.

       If `True`, ``__getstate__`` and
       ``__setstate__`` are generated and attached to the class. This is
       necessary for slotted classes to be pickleable. If left `None`, it's
       `True` by default for slotted classes and ``False`` for dict classes.

       If *auto_detect* is `True`, and *getstate_setstate* is left `None`,
       and **either** ``__getstate__`` or ``__setstate__`` is detected directly
       on the class (i.e. not inherited), it is set to `False` (this is usually
       what you want).

    :param on_setattr: A callable that is run whenever the user attempts to set
        an attribute (either by assignment like ``i.x = 42`` or by using
        `setattr` like ``setattr(i, "x", 42)``). It receives the same arguments
        as validators: the instance, the attribute that is being modified, and
        the new value.

        If no exception is raised, the attribute is set to the return value of
        the callable.

        If a list of callables is passed, they're automatically wrapped in an
        `attr.setters.pipe`.

    :param Optional[callable] field_transformer:
        A function that is called with the original class object and all
        fields right before ``attrs`` finalizes the class.  You can use
        this, e.g., to automatically add converters or validators to
        fields based on their types.  See `transform-fields` for more details.

    .. 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
    z-auto_detect only works on Python 3 and later.Ncs�t|dd�dkrtd���p"t|�}�dko4t|t�}�oBt|d�}|rT|rTtd��t|��|�t|��d�d����|��|��}t|��d�r�|�	���dkr�|�
�t|��d	�}|s�|dkr�|��|s�t|�
�d
�r�|��|�
��	dk�r�dk�rt|d��rd}n�	}|dk	�rB|dk	�rB|dk	�rBtd
��n||dk�sf|dk�r`|dk�sf|�rv��r�td��nH|dk�s�|dk�r�|dk�r�|dk�r�|��n��r�td��|��t|�
�d��r�|��n|����r�td��|��S)Nrz(attrs only works with new-style classes.Tr�z/Can't freeze a class with a custom __setattr__.)r�r�)r0)r!)rr)rrrr	r�Fz6Invalid value for hash.  Must be True, False, or None.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�rvr@r�rr�r�rrrr�r�r�r�r�)r�	is_frozenr�Zhas_own_setattrZbuilderr9r4)r�r�auto_excr�r��eq_r�r�r��hash_r5r8r=�order_r2�repr_nsr�rlr�r�rr�wrap�s�


$


zattrs.<locals>.wrap)r	rrrCrDrErrF)Z	maybe_clsr�r r2r3r4r5r�r�r�rlr�r8r�rr9r;rr�r�r=r�r!r)r�rrr�r�rr�r�r�rr5r8r=rr2r r�rlr�r�rrg�s
2lcCs"t|jdd�tjko |jjtjkS)zb
        Check whether *cls* has a frozen ancestor by looking at its
        __setattr__.
        r%N)r.r�r�r%r$)rrrrr*srcCs
|jtkS)zb
        Check whether *cls* has a frozen ancestor by looking at its
        __setattr__.
        )r�r�)rrrrr8scCspt��}d}d}xZd�||jt|d|j�|�}ddt|�f|f}tj�	||�|krV|S|d7}d�|�}qWdS)zF
    Create a "filename" suitable for a function being generated.
    r*rz <attrs generated {0} {1}.{2}{3}>r&Nz-{0})
�uuidZuuid4r]r%r.r$rlrVrW�
setdefault)r�	func_nameZ	unique_id�extra�count�unique_filenameZ
cache_linerrr�_generate_unique_filename@sr(c	stdd��D���d}t|d�}t|��d}d�d�|sB|d7}n$tsN|d	7}|d
7}d���d7�|g������fd
d�}|r��|dt�|r�|dt|d���|dd�n|dt|d���|dt�n
|d|�d���}td||�S)Ncss0|](}|jdks$|jdkr|jdkr|VqdS)TN)r4r9)r�rurrrr�`sz_make_hash.<locals>.<genexpr>z        r4zdef __hash__(selfzhash((z))z):z, *zC, _cache_wrapper=__import__('attr._make')._make._CacheHashWrapper):z_cache_wrapper(�)csX��||�|d�fg�x �D]}��|d|j�q&W��|d��dS)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
        z        %d,z        self.%s,z    N)�extendr_rX)�prefix�indentru)rg�closing_braces�	hash_func�method_lines�	type_hashrr�append_hash_computation_lineszs

z1_make_hash.<locals>.append_hash_computation_lineszif self.%s is None:zobject.__setattr__(self, '%s', �z
self.%s = zreturn self.%szreturn r\r�)rEr(r4r	r_r�rbrY)	rrgr�r��tabr'Zhash_defr1rNr)rgr-r.r/r0rr�^s<



r�cCst||ddd�|_|S)z%
    Add a hash method to *cls*.
    F)r�r�)r�r�)rrgrrr�	_add_hash�sr4cCsdd�}|S)z
    Create __ne__ method.
    cSs|�|�}|tkrtS|S)zj
        Check equality and either forward a NotImplemented or
        return the result negated.
        )r�NotImplemented)r �other�resultrrrr�s
z_make_ne.<locals>.__ne__r)rrrrr�src	Cs�dd�|D�}t|d�}dddg}i}|r�|�d�dg}xv|D]n}|jr�d	|jf}|j||<|�d
||jf�|�d||jf�q@|�d|jf�|�d
|jf�q@W||dg7}n
|�d�d�|�}td|||�S)z6
    Create __eq__ method for *cls* with *attrs*.
    cSsg|]}|jr|�qSr)r9)r�rurrrr��sz_make_eq.<locals>.<listcomp>r9zdef __eq__(self, other):z-    if other.__class__ is not self.__class__:z        return NotImplementedz
    return  (z
    ) == (z_%s_keyz        %s(self.%s),z        %s(other.%s),z        self.%s,z        other.%s,z    )z    return Truer\r)r(r_r:rXrbrY)	rrgr'�linesrOZothersruZcmp_namerNrrrr�s6





rcsVdd��D���fdd���fdd�}�fdd�}�fd	d
�}�fdd�}||||fS)
z9
    Create ordering methods for *cls* with *attrs*.
    cSsg|]}|jr|�qSr)r;)r�rurrrr��sz_make_order.<locals>.<listcomp>cs tdd��fdd��D�D��S)z&
        Save us some typing.
        css"|]\}}|r||�n|VqdS)Nr)r�r�r�rrrr��sz6_make_order.<locals>.attrs_to_tuple.<locals>.<genexpr>c3s |]}t�|j�|jfVqdS)N)r.rXr<)r�ru)�objrrr��s)rE)r9)rg)r9r�attrs_to_tuple�sz#_make_order.<locals>.attrs_to_tuplecs |j|jkr�|��|�kStS)z1
        Automatically created by attrs.
        )rr5)r r6)r:rrrsz_make_order.<locals>.__lt__cs |j|jkr�|��|�kStS)z1
        Automatically created by attrs.
        )rr5)r r6)r:rrr	sz_make_order.<locals>.__le__cs |j|jkr�|��|�kStS)z1
        Automatically created by attrs.
        )rr5)r r6)r:rrrsz_make_order.<locals>.__gt__cs |j|jkr�|��|�kStS)z1
        Automatically created by attrs.
        )rr5)r r6)r:rrr	sz_make_order.<locals>.__ge__r)rrgrrrr	r)rgr:rr
�s				r
cCs&|dkr|j}t||�|_t�|_|S)z5
    Add equality methods to *cls* with *attrs*.
    N)r|rrrr)rrgrrr�_add_eq's
r;cs$tdd�|D�����fdd�}|S)z^
    Make a repr method that includes relevant *attrs*, adding *ns* to the full
    name.
    css2|]*}|jdk	r|j|jdkr"tn|jfVqdS)FTN)r2rX)r�rurrrr�@sz_make_repr.<locals>.<genexpr>c	
sy
tj}Wn tk
r*t�}|t_YnXt|�|kr<dS|j}�dkrxt|dd�}|dk	rp|�dd�d}q�|j}n�d|j}|�	t|��z\|dg}d	}x@�D]8\}}|r�d
}n
|�
d�|�|d|t||t��f�q�Wd
�
|�dS|�t|��XdS)z1
        Automatically created by attrs.
        z...Nr&z>.rrkr��(TFz, �=r*r))�_already_repring�working_setr�r��idrr.�rsplitr$r�r_r*rrb�remove)	r r?Zreal_clsr��
class_namer7�firstrXZ	attr_repr)�attr_names_with_reprsr�rrr!Es4

z_make_repr.<locals>.__repr__)rE)rgr�r!r)rEr�rr�7s

*r�cCs|dkr|j}t||�|_|S)z%
    Add a repr method to *cls*.
    N)r|r�r!)rr�rgrrr�	_add_reprrsrFcCs8t|�std��t|dd�}|dkr4tdj|d���|S)a�
    Return the tuple of ``attrs`` attributes for a class.

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

    :param type cls: Class to introspect.

    :raise TypeError: If *cls* is not a class.
    :raise attr.exceptions.NotAnAttrsClassError: If *cls* is not an ``attrs``
        class.

    :rtype: tuple (with name accessors) of `attr.Attribute`

    ..  versionchanged:: 16.2.0 Returned tuple allows accessing the fields
        by name.
    zPassed object must be a class.r|Nz({cls!r} is not an attrs-decorated class.)r)rr?r.rr])rrgrrr�fields}srGcCsFt|�std��t|dd�}|dkr4tdj|d���tdd�|D��S)a8
    Return an ordered dictionary of ``attrs`` attributes for a class, whose
    keys are the attribute names.

    :param type cls: Class to introspect.

    :raise TypeError: If *cls* is not a class.
    :raise attr.exceptions.NotAnAttrsClassError: If *cls* is not an ``attrs``
        class.

    :rtype: an ordered dict where keys are attribute names and values are
        `attr.Attribute`\ s. This will be a `dict` if it's
        naturally ordered like on Python 3.6+ or an
        :class:`~collections.OrderedDict` otherwise.

    .. versionadded:: 18.1.0
    zPassed object must be a class.r|Nz({cls!r} is not an attrs-decorated class.)rcss|]}|j|fVqdS)N)rX)r�rurrrr��szfields_dict.<locals>.<genexpr>)rr?r.rr]r)rrgrrr�fields_dict�srHcCsHtjdkrdSx4t|j�D]&}|j}|dk	r|||t||j��qWdS)z�
    Validate all attributes on *inst* that have a validator.

    Leaves all exceptions through.

    :param inst: Instance of a class with ``attrs`` attributes.
    FN)rZ_run_validatorsrGrr1r.rX)�instrur�rrr�validate�s
rJcCs
d|jkS)Nr�)r�)rrrr�_is_slot_cls�srKcCs||kot||�S)z>
    Check if the attribute name comes from a slot class.
    )rK)Za_namer�rrr�
_is_slot_attr�srLcCs|r|	rtd��|p|}g}i}
xr|D]j}|js<|jtkr<q&|�|�||
|j<|jdk	rp|dkrjtd��d}q&|	r�|jtjk	s�t	|j|�r&d}q&Wt
|d�}t||||||||||	|
�\}}}|jt
jkr�|�t
j|jj�|�t|
d��|r�t|d<t|
�rdnd|||�}||_|S)Nz$Frozen classes can't use on_setattr.Tr5)r�	attr_dictZ_cached_setattrr�r�)r@r5r0rr_rXr=rr�rLr(�_attrs_to_init_scriptr%�sys�modulesr�r�r�rYrw)rrg�pre_init�	post_initr�r�r�r�r��has_global_on_setattrr��needs_cached_setattrZfiltered_attrsrMrur'rNrO�annotationsr5rrrr��sT





r�cCsd||fS)zJ
    Use the cached object.setattr to set *attr_name* to *value_var*.
    z_setattr('%s', %s)r)r[�	value_var�has_on_setattrrrr�_setattrsrXcCsd|t|f|fS)zk
    Use the cached object.setattr to set *attr_name* to *value_var*, but run
    its converter first.
    z_setattr('%s', %s(%s)))�_init_converter_pat)r[rVrWrrr�_setattr_with_converter!srZcCs|rt||d�Sd||fS)zo
    Unless *attr_name* has an on_setattr hook, use normal assignment. Otherwise
    relegate to _setattr.
    Tzself.%s = %s)rX)r[r�rWrrr�_assign-sr[cCs$|rt||d�Sd|t|f|fS)z�
    Unless *attr_name* has an on_setattr hook, use normal assignment after
    conversion. Otherwise relegate to _setattr_with_converter.
    Tzself.%s = %s(%s))rZrY)r[rVrWrrr�_assign_with_converter8sr\cCs$|dk	rd|}nd}d|||fS)z8
        Unpack *attr_name* from _kw_only dict.
        Nz, %sr*z%s = _kw_only.pop('%s'%s)r)r[r0Zarg_defaultrrr�_unpack_kw_only_py2Is
r]cCs,dg}|�dd�|D��|d�d�7}|S)a�
        Unpack all *kw_only_args* from _kw_only dict and handle errors.

        Given a list of strings "{attr_name}" and "{attr_name}={default}"
        generates list of lines of code that pop attrs from _kw_only dict and
        raise TypeError similar to builtin if required attr is missing or
        extra key is passed.

        >>> print("
".join(_unpack_kw_only_lines_py2(["a", "b=42"])))
        try:
            a = _kw_only.pop('a')
            b = _kw_only.pop('b', 42)
        except KeyError as _key_error:
            raise TypeError(
                ...
        if _kw_only:
            raise TypeError(
                ...
        ztry:css |]}dt|�d��VqdS)z    r=N)r]�split)r��argrrrr�msz,_unpack_kw_only_lines_py2.<locals>.<genexpr>a	except KeyError as _key_error:
    raise TypeError(
        '__init__() missing required keyword-only argument: %s' % _key_error
    )
if _kw_only:
    raise TypeError(
        '__init__() got an unexpected keyword argument %r'
        % next(iter(_kw_only))
    )
r\)r*r^)�kw_only_argsr8rrr�_unpack_kw_only_lines_py2Ws

rac!
s�g}|r|�d�|r |�d�|dkr^|dkr:t}t}
qf|�d��fdd�}�fdd�}
nt}t}
g}g}g}i}d	d
i}�x�|D�]�}|jr�|�|�|j}|jd
k	p�|jtj	k	o�|	}|j�
d�}t|jt
�}|r�|jjr�d}nd
}|jdk�r�|�rrt�|j�}|jd
k	�rH|�|
||d|f|��t|jf}|j||<n|�|||d|f|��|jj||<nT|jd
k	�r�|�|
|d|f|��t|jf}|j||<n|�||d|f|���n�|jtk	�rN|�sNd||f}|j�r�|�|�n
|�|�|jd
k	�r8|�|
|||��|j|t|jf<n|�||||���n^|�rJd|f}|j�rr|�|�n
|�|�|�d|f�t�|j�}|jd
k	�r�|�d|
|||��|�d�|�d|
||d|d|��|j|t|jf<nB|�d||||��|�d�|�d|||d|d|��|jj||<nb|j�r^|�|�n
|�|�|jd
k	�r�|�|
|||��|j|t|jf<n|�||||��|jdkr�|jd
k	�r�|jd
k�r�|j||<q�|jd
k	r�ts�d
}yt�|j�}Wnttfk
�rYnX|r�t|j���}|r�|dj tj!j"k	r�|dj ||<q�W|�r�t#|d<|�d�xJ|D]B}d|j}d|j}|�d|||jf�|j||<|||<�qpW|�r�|�d�|�r�|�r�|�r�d}nd }nd!}|�|t$d"f�|�r$d#�%d$d%�|D��} |�d&| f�d'�%|�}|�r�t�r`t&|�|}|d(|�rTd'nd
f7}n |d)|�rnd'nd
d'�%|�f7}d*j|
�r�d+nd,||�r�d-�%|�nd.d/�||fS)0z�
    Return a script of an initializer for *attrs* and a dict of globals.

    The globals are expected by the generated script.

    If *frozen* is True, we cannot set the attributes directly so we use
    a cached ``object.__setattr__``.
    zself.__attrs_pre_init__()z8_setattr = _cached_setattr.__get__(self, self.__class__)Tz_inst_dict = self.__dict__cs"t|��rt|||�Sd||fS)Nz_inst_dict['%s'] = %s)rLrX)r[rVrW)r�rr�
fmt_setter�s
z)_attrs_to_init_script.<locals>.fmt_settercs.|st|��rt|||�Sd|t|f|fS)Nz_inst_dict['%s'] = %s(%s))rLrZrY)r[rVrW)r�rr�fmt_setter_with_converter�s
z8_attrs_to_init_script.<locals>.fmt_setter_with_converter�returnN�_r r*Fz(%s)zattr_dict['%s'].defaultz%s=attr_dict['%s'].defaultz
%s=NOTHINGzif %s is not NOTHING:z    zelse:r<r)rrz#if _config._run_validators is True:Z__attr_validator_Z__attr_z    %s(self, %s, self.%s)zself.__attrs_post_init__()z_setattr('%s', %s)z_inst_dict['%s'] = %szself.%s = %s�None�,css|]}|jrd|jVqdS)zself.N)r5rX)r�rurrrr��	sz(_attrs_to_init_script.<locals>.<genexpr>z BaseException.__init__(self, %s)z, z%s**_kw_onlyz%s*, %sz+def {init_name}(self, {args}):
    {lines}
r�r�z
    �pass)Z	init_name�argsr8)'r_rXrZr[r\r1rXr=rr��lstriprCr0rB�
takes_selfr5�_init_factory_patr]r6rYrIrr8r/r	�inspect�	signaturer@r?rD�
parametersr��
annotation�	Parameter�emptyrr�rbra)!rgr�r�rQrRr�r�r�rTrSr�r8rbrcrir`Zattrs_to_validateZnames_for_globalsrUrur[rWZarg_nameZhas_factoryZ
maybe_selfZinit_factory_nameZ	conv_namer_�sig�
sig_paramsZval_nameZinit_hash_cache�valsr)r�rrN�sD




















rNc	@s`eZdZdZdZddd�Zdd�Zedd	d
��Ze	dd��Z
d
d�Zdd�Zdd�Z
dd�ZdS)r�a~
    *Read-only* representation of an attribute.

    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 *field transformer* hook receives a list of them.

    :attribute name: The name of the attribute.
    :attribute inherited: Whether or not that attribute has been inherited from
        a base class.

    Plus *all* arguments of `attr.ib` (except for ``factory``
    which is only syntactic sugar for ``default=Factory(...)``.

    .. 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*

    For the full version history of the fields, see `attr.ib`.
    )rXr0r1r2r9r:r;r<r4r5r7r/r6r8r}r=NFcCs�t||p
|
|p|d�\}
}}}t�|t�}|d|�|d|�|d|�|d|�|d|
�|d|�|d|�|d	|�|d
|�|d|�|d|�|d
|	r�t|	�nt�|d|
�|d|�|d|�|d|�dS)NTrXr0r1r2r9r:r;r<r4r5r6r7r/r8r}r=)r>r�r�r�r
�_empty_metadata_singleton)r rXr0r1r2r3r4r5r}r7r/r6r8r9r:r;r<r=�
bound_setattrrrrr��	s,













zAttribute.__init__cCs
t��dS)N)r)r rXr�rrrr�
szAttribute.__setattr__c	sV|dkr�j}n�jdk	r"td���fdd�tjD�}|f|�j�j|ddd�|��S)Nz8Type annotation and type argument cannot both be presentcs i|]}|dkrt�|�|�qS))rXr1r0r/r})r.)r�r�)r�rrr�
sz0Attribute.from_counting_attr.<locals>.<dictcomp>F)rXr1r0r/r3r})r/r@r�r��
_validator�_default)rrXr�r/Z	inst_dictr)r�rr�
s



zAttribute.from_counting_attrcCstjttdd�|jo|jS)zD
        Simulate the presence of a cmp attribute and warn.
        r2)�
stacklevel)�warnings�warn�_CMP_DEPRECATION�DeprecationWarningr9r;)r rrrr3.
sz
Attribute.cmpcKst�|�}|�|���|S)z�
        Copy *self* and apply *changes*.

        This works similarly to `attr.evolve` but that function does not work
        with ``Attribute``.

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

        .. versionadded:: 20.3.0
        )�copy�	_setattrsr�)r Zchanges�newrrrr8
s
zAttribute.evolvecst�fdd��jD��S)z(
        Play nice with pickle.
        c3s*|]"}|dkrt�|�nt�j�VqdS)r7N)r.r�r7)r�rX)r rrr�O
sz)Attribute.__getstate__.<locals>.<genexpr>)rEr�)r r)r rr�J
s
zAttribute.__getstate__cCs|�t|j|��dS)z(
        Play nice with pickle.
        N)r�r�r�)r r�rrrr�S
szAttribute.__setstate__cCsLt�|t�}x:|D]2\}}|dkr.|||�q|||r>t|�nt�qWdS)Nr7)r�r�r�r
rv)r Zname_values_pairsrwrXr�rrrr�Y
szAttribute._setattrs)	NNNFNNNNN)N)r$r%r&r'r�r�r�r�r�rar3rr�r�r�rrrrr��	s&
#
	r�cCs,g|]$}t|tddddd|dkddd�
�qS)NTFr7)
rXr0r1r2r3r9r;r4r5r})r�r)r�rXrrrr�h
sr�)rgcCsg|]}|jdkr|�qS)r})rX)r�rurrrr�z
scCs g|]}|jr|jdkr|�qS)r})r4rX)r�rurrrr�|
sc@sheZdZdZdZedd�dD��edddddd	dd	ddd	dd	dd
�fZdZdd
�Z	dd�Z
dd�ZdS)rHa
    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.
    )ryryr2r9r:r;r<r4r5r7rxr6r/r8r=ccs2|]*}t|tddddddddddddd�VqdS)NTF)rXr0r1r2r3r4r5r8r9r:r;r<r}r=)r�r)r�rXrrrr��
sz_CountingAttr.<genexpr>)ryryr2r9r;r4r5r=r7NTF)rXr0r1r2r3r4r5r8r9r:r;r<r}r=rcCsntjd7_tj|_||_||_||_||_||_||_|
|_	||_
||_||_||_
|	|_|
|_||_dS)Nr)rH�cls_counterryryrxr6r2r9r:r;r<r4r5r7r/r8r=)r r0r1r2r3r4r5r6r7r/r8r9r:r;r<r=rrrr��
s z_CountingAttr.__init__cCs$|jdkr||_nt|j|�|_|S)z�
        Decorator that adds *meth* to the list of validators.

        Returns *meth* unchanged.

        .. versionadded:: 17.1.0
        N)rxrG)r rrrrr1�
s
z_CountingAttr.validatorcCs"|jtk	rt��t|dd�|_|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)rk)ryrrrB)r rrrrr0�
s

z_CountingAttr.default)r$r%r&r'r�rEr�r|r�r�r1r0rrrrrH�
s0
#rHc@s.eZdZdZdZddd�Zdd�Zdd	�Zd
S)rBa�
    Stores a factory callable.

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

    :param callable factory: A callable that takes either none or exactly one
        mandatory positional argument depending on *takes_self*.
    :param bool takes_self: Pass the partially initialized instance that is
        being initialized as a positional argument.

    .. versionadded:: 17.1.0  *takes_self*
    )rIrkFcCs||_||_dS)z�
        `Factory` is part of the default machinery so if we want a default
        value here, we have to implement it ourselves.
        N)rIrk)r rIrkrrrr� szFactory.__init__cst�fdd��jD��S)z(
        Play nice with pickle.
        c3s|]}t�|�VqdS)N)r.)r�rX)r rrr�,sz'Factory.__getstate__.<locals>.<genexpr>)rEr�)r r)r rr�(szFactory.__getstate__cCs*x$t|j|�D]\}}t|||�qWdS)z(
        Play nice with pickle.
        N)r�r�r�)r r�rXr�rrrr�.szFactory.__setstate__N)F)r$r%r&r'r�r�r�r�rrrrrBs


rBcCs(g|] }t|tddddddddd�
�qS)NTF)
rXr0r1r2r3r9r;r4r5r})r�r)r�rXrrrr�7sc
	s$t|t�r|}n*t|ttf�r2tdd�|D��}ntd��|�dd�}|�dd�}|�dd�}i�|dk	rr|�d<|dk	r�|�d<|dk	r�|�d<t||i�fdd	��}yt�d
�j	�
dd�|_Wntt
fk
r�YnX|�d
d�}	t|	|�
d�|�
d�d�\|d<|d<tfd|i|��|�S)aB
    A quick way to create a new class called *name* with *attrs*.

    :param str name: The name for the new class.

    :param attrs: A list of names or a dictionary of mappings of names to
        attributes.

        If *attrs* is a list or an ordered dict (`dict` on Python 3.6+,
        `collections.OrderedDict` otherwise), 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.
    :type attrs: `list` or `dict`

    :param tuple bases: Classes that the new class will subclass.

    :param attributes_arguments: Passed unmodified to `attr.s`.

    :return: A new class with *attrs*.
    :rtype: type

    .. versionadded:: 17.1.0 *bases*
    .. versionchanged:: 18.1.0 If *attrs* is ordered, the order is retained.
    css|]}|t�fVqdS)N)rJ)r�rurrrr�eszmake_class.<locals>.<genexpr>z(attrs argument must be a dict or a list.r�Nr�r�cs
|���S)N)r�)r�)�bodyrrr�ur�zmake_class.<locals>.<lambda>rr$�__main__r3r9r;Tr�)rCr�rDrEr?�poprrO�	_getframe�	f_globalsr�r%r�r@rr�)
rXrg�basesZattributes_argumentsZcls_dictrQrRZ	user_init�type_r3r)r�r�
make_classIs8
r�)r�r4c@seZdZdZe�Zdd�ZdS)�
_AndValidatorz2
    Compose many validators to a single one.
    cCs x|jD]}||||�qWdS)N)�_validators)r rIrsr�r�rrr�__call__�sz_AndValidator.__call__N)r$r%r&r'rJr�r�rrrrr��sr�cGs:g}x(|D] }|�t|t�r"|jn|g�q
Wtt|��S)z�
    A validator that composes multiple validators into one.

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

    :param callables validators: Arbitrary number of validators.

    .. versionadded:: 17.1.0
    )r*rCr�r�rE)Z
validatorsrur1rrrrG�s

rGc	s��fdd�}ts�s,t�d�}||d�|_n�d}yt��d�}Wnttfk
rZYnX|r�t|j	�
��}|r�|djtjj
k	r�|dj|jd<d}yt��d�}Wnttfk
r�YnX|r�|jt��j
k	r�|j|jd	<|S)
aY
    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.

    :param callables converters: Arbitrary number of converters.

    .. versionadded:: 20.1.0
    csx�D]}||�}qW|S)Nr)r
r6)�
convertersrr�pipe_converter�s
zpipe.<locals>.pipe_converter�A)r
rdNrr
rkrd)r	�typing�TypeVarrwrmrnr@r?rDror�rprqrr�return_annotation�	Signature)r�r�r�rs�paramsr)r�rrF�s0
rF)Nr*)N)T)NNNNNNNFFTFFFFFNNFFNNN)N)NN)N)f�
__future__rrrrrmrVrO�	threadingr"r{�operatorrr*rr�_compatr	r
rrr
rrr�
exceptionsrrrrrr�r�r�r�rYrlr`ror�rvrqrr�intr)rJrSrYrerfrprvrxr{r�r�r�r�r�r�r}rr>rrgr�rr(r�r4rrr
r;�localr>r�rFrGrHrJrKrLr�rXrZr[r\r]rarNr�r�Z_arHrBZ_fr�r�rGrFrrrr�<module>s(
	7


k
7*

y
B48

;
I
)+@


(
L

?>