U
    ]]                    @   s  d dl mZmZ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
mZ ddl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mZ ejZdZd	Zd
Z dZ!dZ"ei Z#e Z$G dd deZ%e% Z&e&ddddddddddddfddZ'dd Z(e(ddddgZ)dd Z*dd Z+dd Z,dd  Z-d!d" Z.d#d$ Z/G d%d& d&eZ0d'Z1d(d) Z2dbd*dZ3e3Z4er|d+d, Z5nd-d, Z5d.d/ Z6d0d1 Z7d2d3 Z8d4d5 Z9d6d7 Z:d8d9 Z;d:d; Z<dcd<d=Z=e> Z?d>d? Z@ddd@dAZAdBdC ZBdDdE ZCdFdG ZDdHdI ZEdJdK ZFdLdM ZGdNdO ZHG dPdQ dQeZIdRdS eIjJD ZKe9e=eAeIeKdTeKdTdUdS eKD dTZIG dVdW dWeZLe=eAeLZLe3ddddXG dYdZ dZeZMeffd[d\ZNe3ddd]G d^d_ d_eZOd`da ZPdS )e    )absolute_importdivisionprint_functionN)
itemgetter   )_config)PY2isclass	iteritemsmetadata_proxyordered_dictset_closure_cell)DefaultAlreadySetErrorFrozenInstanceErrorNotAnAttrsClassErrorPythonTooOldErrorUnannotatedAttributeErrorz__attr_converter_{}z__attr_factory_{}z=    {attr_name} = _attrs_property(_attrs_itemgetter({index})))ztyping.ClassVarz
t.ClassVarZClassVarZ_attrs_cached_hashc                       s,   e Zd ZdZdZ fddZd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.
    Nc                    s"   t jd krtt | | t _t jS N)r   
_singletonsuper__new__cls	__class__ ,/usr/lib/python3/dist-packages/attr/_make.pyr   :   s    
z_Nothing.__new__c                 C   s   dS )NNOTHINGr   selfr   r   r   __repr__?   s    z_Nothing.__repr__)__name__
__module____qualname____doc__r   r   r!   __classcell__r   r   r   r   r   1   s   r   TFc                 C   s   t |||\}}|dk	r0|dk	r0|dk	r0td|	dk	r`| tk	rHtdt|	sXtdt|	} |dkrli }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(callable)``.

    :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 bool eq: If ``True`` (default), include this attribute in the
        generated ``__eq__`` and ``__ne__`` methods that check two instances
        for equality.
    :param bool order: If ``True`` (default), include this attributes in the
        generated ``__lt__``, ``__le__``, ``__gt__`` and ``__ge__`` methods.
    :param bool cmp: Setting to ``True`` is equivalent to setting ``eq=True,
        order=True``. Deprecated in favor of *eq* and *order*.
    :param 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*.
    :type hash: ``bool`` or ``None``
    :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 converter 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).

    .. 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*
    NTF6Invalid 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metadatatypekw_onlyeqorder)_determine_eq_order	TypeErrorr   
ValueErrorcallableFactory_CountingAttr)r(   r)   r*   r+   r,   r-   r/   r0   r.   factoryr1   r2   r3   r   r   r   attribI   s:    zr;   c                 C   sx   d | }d |dg}|rDt|D ]\}}|tj ||d q$n
|d ttd}ttd|dd	| || S )
z
    Create a tuple subclass to hold `Attribute`s for an `attrs` class.

    The subclass is a bare tuple with properties for names.

    class MyClassAttributes(tuple):
        __slots__ = ()
        x = property(itemgetter(0))
    z{}Attributeszclass {}(tuple):z    __slots__ = ())index	attr_namez    pass)Z_attrs_itemgetterZ_attrs_property
 exec)	format	enumerateappend_tuple_property_patr   propertyevalcompilejoin)Zcls_name
attr_namesZattr_class_nameZattr_class_templateir=   globsr   r   r   _make_attr_tuple_class   s    



rL   _Attributesattrs
base_attrsZbase_attrs_mapc                 C   s   t | 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.
    )str
startswith_classvar_prefixes)Zannotr   r   r   _is_class_var  s    rS   c                 C   sH   t | dd}|dkri S | jdd D ]}|t |ddkr&i   S q&|S )z$
    Get annotations for *cls*.
    __annotations__Nr   )getattr__mro__)r   annsbase_clsr   r   r   _get_annotations  s    
rY   c                 C   s
   | d j S )zQ
    Key function for sorting to avoid re-creating a lambda for every class.
    r   counterer   r   r   _counter_getter-  s    r^   c              	      sl  | j t|  |dk	r@dd t|D }t|ts>|jtd n|dkrdd  D }g }t }  D ]Z\}}t	|rqn|
| |t}	t|	ts|	tkrt }	n
t|	d}	|||	f qn|| }
t|
d	kr&td
dt|
fddd d ntdd  D dd d} fdd|D }g }i }dd |D }| jdd D ]\}t|dd}|dk	r\|D ]:}	||	j}|dkrz||	 |	||	j< |||	j< qzq\dd || D }t| j|}|rdd |D }dd |D }||| }d}dd |D D ]D}	|dkr@|	jtkr@td|	f |dkr|	jtk	rd}qt|||fS )z
    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.

    Return an `_Attributes`.
    Nc                 S   s   g | ]\}}||fqS r   r   ).0namecar   r   r   
<listcomp>@  s     z$_transform_attrs.<locals>.<listcomp>)keyTc                 S   s   h | ]\}}t |tr|qS r   
isinstancer9   r_   r`   attrr   r   r   	<setcomp>E  s   
z#_transform_attrs.<locals>.<setcomp>)r(   r   z1The following `attr.ib`s lack a type annotation: , c                    s     | jS r   )getr[   )n)cdr   r   <lambda>]      z"_transform_attrs.<locals>.<lambda>.c                 s   s$   | ]\}}t |tr||fV  qd S r   rd   rf   r   r   r   	<genexpr>c  s   
z#_transform_attrs.<locals>.<genexpr>c                 S   s
   | d j S Nr   rZ   r\   r   r   r   rm   h  rn   c                    s&   g | ]\}}t j|| |d qS ))r`   ra   r0   )	Attributefrom_counting_attrrj   )r_   r=   ra   )rW   r   r   rb   k  s     c                 S   s   i | ]}|j |qS r   r`   r_   ar   r   r   
<dictcomp>t  s      z$_transform_attrs.<locals>.<dictcomp>r   __attrs_attrs__c                 S   s   g | ]
}|j qS r   rt   ru   r   r   r   rb     s     c                 S   s   g | ]}|j d dqS T)r1   _assocru   r   r   r   rb     s     c                 S   s   g | ]}|j d dqS rz   r{   ru   r   r   r   rb     s     Fc                 s   s&   | ]}|j d k	r|jd kr|V  qdS )FN)r-   r1   ru   r   r   r   rp     s     
 
 znNo mandatory attributes allowed after an attribute with a default value or factory.  Attribute in question: %r)__dict__rY   r
   re   r   sortr^   itemssetrS   addrj   r   r9   r;   rC   lenr   rH   sortedrV   rU   r`   rL   r"   r(   r6   rM   )r   theseauto_attribsr1   Zca_listZca_namesZannot_namesr=   r0   rv   ZunannotatedZ	own_attrsrO   base_attr_mapZtaken_attr_namesrX   Z	sub_attrsZprev_arI   Z
AttrsClassrN   Zhad_defaultr   )rW   rl   r   _transform_attrs4  s    




	




r   c                 C   s
   t  dS )z4
    Attached to frozen classes as __setattr__.
    Nr   r    r`   valuer   r   r   _frozen_setattrs  s    r   c                 C   s
   t  dS )z4
    Attached to frozen classes as __delattr__.
    Nr   )r    r`   r   r   r   _frozen_delattrs  s    r   c                   @   s|   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )_ClassBuilderz(
    Iteratively build *one* class.
    )_cls	_cls_dict_attrs_base_names_attr_names_slots_frozen_weakref_slot_cache_hash_has_post_init_delete_attribs_base_attr_map_is_excc
                 C   s   t ||||\}
}}|| _|r(t|jni | _|
| _tdd |D | _|| _t	dd |
D | _
|| _|prt|| _|| _|| _tt|dd| _t| | _|	| _| j| jd< |rt| jd< t| jd< d S )	Nc                 s   s   | ]}|j V  qd S r   rt   ru   r   r   r   rp     s     z)_ClassBuilder.__init__.<locals>.<genexpr>c                 s   s   | ]}|j V  qd S r   rt   ru   r   r   r   rp     s     __attrs_post_init__Fry   __setattr____delattr__)r   r   dictr}   r   r   r   r   r   tupler   r   _has_frozen_base_classr   r   r   boolrU   r   r   r   r   r   )r    r   r   slotsfrozenweakref_slotr   r1   
cache_hashis_excrN   rO   Zbase_mapr   r   r   __init__  s.       

z_ClassBuilder.__init__c                 C   s   dj | jjdS )Nz<_ClassBuilder(cls={cls})>r   )rA   r   r"   r   r   r   r   r!     s    z_ClassBuilder.__repr__c                 C   s   | j dkr|  S |  S dS )z
        Finalize class based on the accumulated configuration.

        Builder cannot be used after calling this method.
        TN)r   _create_slots_class_patch_original_classr   r   r   r   build_class  s    
z_ClassBuilder.build_classc              	   C   s   | j }| j}| jrZ| jD ]@}||krt||ttk	rzt|| W q tk
rV   Y qX q| j	 D ]\}}t
||| qd| jrt|dd}|rtddd }t
|d| |S )zA
        Apply accumulated methods and return the class.
        __setstate__NzCurrently you cannot use hash caching if you specify your own __setstate__ method.See https://github.com/python-attrs/attrs/issues/494 .c                 S   s   t | td  d S r   )setattr_hash_cache_field)Z	chss_self_r   r   r   cache_hash_set_state  s    zA_ClassBuilder._patch_original_class.<locals>.cache_hash_set_state)r   r   r   r   rU   	_sentineldelattrAttributeErrorr   r   r   r   NotImplementedError)r    r   
base_namesr`   r   Zexisting_set_state_methodr   r   r   r   r     s.    
z#_ClassBuilder._patch_original_classc                    s  j  fddtjD }d}jjdd D ]}dt|ddkr2d	} qPq2j}jrdtjd
dkrd|kr|s|d7 } fdd|D }jr|	t
 t||d
< tjdd}|dk	r||d< tdd jD fdd}jfdd}||d< ||d< tjjjjj|}	|	j D ]`}
t|
ttfrZt|
jdd}nt|
dd}|spq6|D ]}|jjkrtt||	 qtq6|	S )zL
        Build and return a new class with a `__slots__` attribute.
        c                    s(   i | ] \}}|t  jd  kr||qS ))r}   __weakref__)r   r   )r_   kvr   r   r   rw   )  s    z5_ClassBuilder._create_slots_class.<locals>.<dictcomp>Fr   rx   r   r}   r   T	__slots__)r   c                    s   g | ]}| kr|qS r   r   r_   r`   )r   r   r   rb   B  s      z5_ClassBuilder._create_slots_class.<locals>.<listcomp>r$   Nc                 s   s   | ]}|d kr|V  qdS )r   Nr   )r_   Zanr   r   r   rp   L  s     z4_ClassBuilder._create_slots_class.<locals>.<genexpr>c                    s   t  fddD S )9
            Automatically created by attrs.
            c                 3   s   | ]}t  |V  qd S r   rU   r   r   r   r   rp   T  s     zL_ClassBuilder._create_slots_class.<locals>.slots_getstate.<locals>.<genexpr>r   r   )state_attr_namesr   r   slots_getstateP  s    z9_ClassBuilder._create_slots_class.<locals>.slots_getstatec                    s<   t | t}t|D ]\}}||| q r8|td dS )r   N)_obj_setattr__get__rr   zipr   )r    stateZ_ClassBuilder__bound_setattrr`   r   )hash_caching_enabledr   r   r   slots_setstateX  s
    z9_ClassBuilder._create_slots_class.<locals>.slots_setstate__getstate__r   __closure__)r   r
   r   r   rV   rU   r   r   r   rC   r   r   r0   r"   	__bases__r}   valuesre   classmethodstaticmethod__func__cell_contentsr   )r    rl   Zweakref_inheritedrX   namesZ
slot_namesqualnamer   r   r   itemZclosure_cellsZcellr   )r   r   r    r   r   r   $  sZ    

z!_ClassBuilder._create_slots_classc                 C   s   |  t| j|d| jd< | S )N)nsr!   )_add_method_dunders
_make_reprr   r   )r    r   r   r   r   add_repr  s    
z_ClassBuilder.add_reprc                 C   s8   | j d}|d krtddd }| || j d< | S )Nr!   z3__str__ can only be generated if a __repr__ exists.c                 S   s   |   S r   )r!   r   r   r   r   __str__  s    z&_ClassBuilder.add_str.<locals>.__str__r   )r   rj   r6   r   )r    r*   r   r   r   r   add_str  s    z_ClassBuilder.add_strc                 C   s   d | j d< | S )N__hash__)r   r   r   r   r   make_unhashable  s    
z_ClassBuilder.make_unhashablec                 C   s(   |  t| j| j| j| jd| jd< | S )Nr   r   r   )r   
_make_hashr   r   r   r   r   r   r   r   r   add_hash  s    
	z_ClassBuilder.add_hashc                 C   s6   |  t| j| j| j| j| j| j| j| j	| j
d< | S )Nr   )r   
_make_initr   r   r   r   r   r   r   r   r   r   r   r   r   add_init  s    
z_ClassBuilder.add_initc                    s2    j } fddt j jD \|d< |d<  S )Nc                 3   s   | ]}  |V  qd S r   r   r_   methr   r   r   rp     s   z'_ClassBuilder.add_eq.<locals>.<genexpr>__eq____ne__)r   _make_eqr   r   r    rl   r   r   r   add_eq  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   r   r   r   rp     s   z*_ClassBuilder.add_order.<locals>.<genexpr>__lt____le____gt____ge__)r   _make_orderr   r   r   r   r   r   	add_order  s
    
z_ClassBuilder.add_orderc                 C   sX   z| j j|_W n tk
r"   Y nX zd| j j|jf|_W n tk
rR   Y nX |S )zL
        Add __module__ and __qualname__ to a *method* if possible.
        ro   )r   r#   r   rH   r$   r"   )r    methodr   r   r   r     s    
z!_ClassBuilder._add_method_dundersN)r"   r#   r$   r%   r   r   r!   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s   $0`

r   zrThe usage of `cmp` is deprecated and will be removed on or after 2021-06-01.  Please use `eq` and `order` instead.c                 C   s|   | dk	r$t |dk	|dk	fr$td| dk	rDtjttdd | | fS |dkrPd}|dkr\|}|dkrt|dkrttd||fS )zp
    Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
    values of eq and order.
    Nz&Don't mix `cmp` with `eq' and `order`.   
stacklevelTFz-`order` can only be True if `eq` is True too.)anyr6   warningswarn_CMP_DEPRECATIONDeprecationWarning)r+   r2   r3   r   r   r   r4     s    r4   c                    sP   t |\ 	
fdd}| dkrD|S || S dS )a   
    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 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 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, but only iff the types of both classes are *identical*!
    :type eq: `bool` or `None`
    :param 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*.
    :type order: `bool` or `None`
    :param cmp: Setting to ``True`` is equivalent to setting ``eq=True,
        order=True``. Deprecated in favor of *eq* and *order*, has precedence
        over them for backward-compatibility though. Must not be mixed with
        *eq* or *order*.
    :type cmp: `bool` or `None`
    :param 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.
    :type hash: ``bool`` or ``None``
    :param bool init: Create a ``__init__`` method that initializes the
        ``attrs`` attributes.  Leading underscores are stripped for the
        argument name.  If a ``__attrs_post_init__`` method exists on the
        class, it will be called after the class is fully initialized.
    :param bool slots: Create a `slotted class <slotted classes>` that's more
        memory-efficient.
    :param bool frozen: Make instances immutable after initialization.  If
        someone attempts to modify a frozen instance,
        `attr.exceptions.FrozenInstanceError` is raised.

        Please 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)``.

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

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

        .. _`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.

    .. 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*
    c              
      sH  t | dd d krtddko(t| t}t|  |	}	dkrT|
 dkrd|  dkrx|sx|  dkr|s|  dk	rdk	rd k	rtdnpdksʈd krƈdks|r؈rtdnFdksd krdkrdkr|	  nrtd|
  dkr2|  nr@td| S )Nr   z(attrs only works with new-style classes.TFr'   zlInvalid value for cache_hash.  To use hash caching, hashing must be either explicitly or implicitly enabled.zFInvalid value for cache_hash.  To use hash caching, init must be True.)rU   r5   
issubclassBaseExceptionr   r   r   r   r   r   r   r   r   )r   r   Zbuilderr   auto_excr   r2   r   r,   r-   r1   r3   r*   repr_nsr   rP   r   r   r   r   wrap  sZ    
&


zattrs.<locals>.wrapN)r4   )Z	maybe_clsr   r   r*   r+   r,   r-   r   r   r   rP   r   r1   r   r   r2   r3   r   r   r   r   rN     s     2(Dc                 C   s"   t | jddtjko | jjtjkS )b
        Check whether *cls* has a frozen ancestor by looking at its
        __setattr__.
        r#   N)rU   r   r   r#   r"   r   r   r   r   r     s
    r   c                 C   s
   | j tkS )r   )r   r   r   r   r   r   r     s    c                    s   t  fdd|D S )z:
    Create a tuple of all values of *obj*'s *attrs*.
    c                 3   s   | ]}t  |jV  qd S r   )rU   r`   ru   objr   r   rp     s     z"_attrs_to_tuple.<locals>.<genexpr>r   )r   rN   r   r   r   _attrs_to_tuple  s    r   c                 C   sl   t  }d}d}d|| jt| d| j|}ddt|f|f}tj	|||krT|S |d7 }d|}qdS )zF
    Create a "filename" suitable for a function being generated.
    r?   r   z <attrs generated {0} {1}.{2}{3}>r$   Nz-{0})
uuidZuuid4rA   r#   rU   r"   rP   	linecachecache
setdefault)r   Z	func_nameZ	unique_idZextracountunique_filenameZ
cache_liner   r   r   _generate_unique_filename"  s"    	r  c                    s   t dd  D  d}t| d}t|dg fdd}|r|dt   |r~|d	t |d
  |d
 d  n|dt |d
  |dt   n
|d| d}i }i }	t||d}
t|
||	 t|d |	d|ft
j|< |	d S )Nc                 s   s0   | ](}|j d ks$|j dkr|jd kr|V  qdS )TN)r,   r2   ru   r   r   r   rp   A  s
    
 
 
 z_make_hash.<locals>.<genexpr>z        r,   zdef __hash__(self):c                    sP    ||  d |df  g  D ]}|d|j   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
        zhash((z        %d,        self.%s,z    ))N)extendrC   r`   )prefixindentrv   rN   Zmethod_linesZ	type_hashr   r   append_hash_computation_linesL  s    z1_make_hash.<locals>.append_hash_computation_lineszif self.%s is None:zobject.__setattr__(self, '%s',    )z
self.%s = zreturn self.%szreturn r>   r@   Tr   )r   r  r,   rC   r   rH   rG   rF   r   
splitlinesr   r   )r   rN   r   r   Ztabr  r
  scriptrK   locsbytecoder   r	  r   r   @  sB    
  


r   c                 C   s   t | |ddd| _| S )z%
    Add a hash method to *cls*.
    Fr   )r   r   r   rN   r   r   r   	_add_hash|  s    r  c                 C   s   |  |}|tk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     s    
r   c           
      C   s   dd |D }t | d}dddg}|rt|d dg}|D ](}|d	|jf  |d
|jf  q:||dg 7 }n
|d d|}i }i }t||d}	t|	|| t|d |d|ftj	|< |d t
fS )Nc                 S   s   g | ]}|j r|qS r   )r2   ru   r   r   r   rb     s      z_make_eq.<locals>.<listcomp>r2   zdef __eq__(self, other):z-    if other.__class__ is not self.__class__:z        return NotImplementedz    return  (z
    ) == (r  z        other.%s,z    )z    return Truer>   r@   Tr   )r  rC   r`   rH   rG   rF   r   r  r   r   r   )
r   rN   r  linesZothersrv   r  rK   r  r  r   r   r   r     s2    




r   c                    sV   dd  D   fddfdd}fdd}fd	d
}fdd}||||fS )Nc                 S   s   g | ]}|j r|qS r   )r3   ru   r   r   r   rb     s      z_make_order.<locals>.<listcomp>c                    s
   t |  S )z&
        Save us some typing.
        )r   r   rN   r   r   attrs_to_tuple  s    z#_make_order.<locals>.attrs_to_tuplec                    s    |j | j kr |  |k S tS 1
        Automatically created by attrs.
        r   r  r    r  r  r   r   r     s    z_make_order.<locals>.__lt__c                    s    |j | j kr |  |kS tS r  r  r  r  r   r   r     s    z_make_order.<locals>.__le__c                    s    |j | j kr |  |kS tS r  r  r  r  r   r   r     s    z_make_order.<locals>.__gt__c                    s    |j | j kr |  |kS tS r  r  r  r  r   r   r     s    z_make_order.<locals>.__ge__r   )r   rN   r   r   r   r   r   )rN   r  r   r     s    				r   c                 C   s$   |dkr| j }t| |\| _| _| S )z5
    Add equality methods to *cls* with *attrs*.
    N)ry   r   r   r   r  r   r   r   _add_eq  s    r  c                    s$   t dd | D   fdd}|S )z^
    Make a repr method that includes relevant *attrs*, adding *ns* to the full
    name.
    c                 s   s2   | ]*}|j d k	r|j|j dkr"t n|j fV  qdS )FTN)r*   r`   ru   r   r   r   rp     s   
z_make_repr.<locals>.<genexpr>c           	   
      s  z
t j}W n  tk
r*   t }|t _Y nX t| |kr<dS | j}dkrxt|dd}|dk	rp|ddd }q|j}nd |j }|	t|  z\|dg}d	} D ]8\}}|rd
}n
|d ||d|t| |tf qd|d W S |
t|  X dS )r  z...Nr$   z>.r   rx   ro   (TFri   =r?   r  )_already_repringworking_setr   r   idr   rU   rsplitr"   r   removerC   r  r   rH   )	r    r"  Zreal_clsr   
class_namer  firstr`   Z	attr_reprZattr_names_with_reprsr   r   r   r!     s6    

z_make_repr.<locals>.__repr__r   )rN   r   r!   r   r(  r   r     s
    *r   c                 C   s   |dkr| j }t||| _| S )z%
    Add a repr method to *cls*.
    N)ry   r   r!   )r   r   rN   r   r   r   	_add_repr1  s    r)  c                 C   s   dd |D }t | d}t|||||||\}	}
}i }t|	|d}tdd |D }|
t|d |dkrtt|
d	< t||
| t|	d |		d|ft
j|< |d
 }||_|S )Nc                 S   s    g | ]}|j s|jtk	r|qS r   )r-   r(   r   ru   r   r   r   rb   ?  s      
 z_make_init.<locals>.<listcomp>r-   r@   c                 s   s   | ]}|j |fV  qd S r   rt   ru   r   r   r   rp   H  s     z_make_init.<locals>.<genexpr>)r   	attr_dictTZ_cached_setattrr   )r  _attrs_to_init_scriptrG   r   updater   r   rF   r   r  r   r   rT   )r   rN   	post_initr   r   r   r   r   r  r  rK   annotationsr  r  r*  r   r   r   r   r   <  s4    
      

r   c                 C   s8   t | stdt| dd}|dkr4tdj| 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.
    Passed object must be a class.ry   N({cls!r} is not an attrs-decorated class.r   )r	   r5   rU   r   rA   r  r   r   r   fieldsa  s    
r1  c                 C   sF   t | stdt| dd}|dkr4tdj| dtdd |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
    r/  ry   Nr0  r   c                 s   s   | ]}|j |fV  qd S r   rt   ru   r   r   r   rp     s     zfields_dict.<locals>.<genexpr>)r	   r5   rU   r   rA   r   r  r   r   r   fields_dict}  s    
r2  c                 C   sD   t jdkrdS t| jD ]&}|j}|dk	r|| |t| |j qdS )z
    Validate all attributes on *inst* that have a validator.

    Leaves all exceptions through.

    :param inst: Instance of a class with ``attrs`` attributes.
    FN)r   Z_run_validatorsr1  r   r)   rU   r`   )instrv   r   r   r   r   validate  s    
r4  c                 C   s
   d| j kS )Nr   )r}   r   r   r   r   _is_slot_cls  s    r5  c                 C   s   | |kot ||  S )z>
    Check if the attribute name comes from a slot class.
    )r5  )Za_namer   r   r   r   _is_slot_attr  s    r6  c              
      s  g }t  fdd| D }|dkrx|dkrF|d dd }	dd }
q|d	 |r^|d  fd
d}	 fdd}
ndd }	dd }
g }g }g }i }ddi}| D ] }|jr|| |j}|jd}t|jt}|r|jjrd}nd}|j	dkr|rrt
|j}|jdk	rJ||
||d|  t|j}|j||< n||	||d|  |jj||< nT|jdk	r||
|dj|d t|j}|j||< n||	|dj|d n|jtk	rL|sLdj||d}|jr|| n
|| |jdk	r8||
|| |j|t|j< n||	|| nR|r@dj|d}|jrr|| n
|| |dj|d t
|j}|jdk	r|d|
||  |d |d|
||d|   |j|t|j< n<|d|	||  |d |d|	||d|   |jj||< n^|jrT|| n
|| |jdk	r||
|| |j|t|j< n||	|| |j	dkr|jdkr|jdk	r|j||< q|r,t|d< |d |D ]F}d |j}d!|j}|d"|||j |j||< |||< q|r<|d# |rp|rZ|rTd$}nd%}nd&}||td'f  |rd(d)d | D }|d*|f  d+|}|rtrtd,|d-j|rd+ndd+|d.7 }d/j||rd0|nd1d2||fS )3z
    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__``.
    c                 3   s   | ]}t |j V  qd S r   )r6  r`   ru   r   r   r   rp     s    z(_attrs_to_init_script.<locals>.<genexpr>Tz8_setattr = _cached_setattr.__get__(self, self.__class__)c                 S   s   d| |d S )N(_setattr('%(attr_name)s', %(value_var)s)r=   	value_varr   r9  r   r   r   
fmt_setter  s    z)_attrs_to_init_script.<locals>.fmt_setterc                 S   s   t | }d| ||d S )Nz2_setattr('%(attr_name)s', %(conv)s(%(value_var)s))r=   r:  Zconv_init_converter_patrA   r=   r:  	conv_namer   r   r   fmt_setter_with_converter  s    
z8_attrs_to_init_script.<locals>.fmt_setter_with_converterz_inst_dict = self.__dict__c                    s,   t |  rd| |d }nd| |d }|S )Nr8  r9  z+_inst_dict['%(attr_name)s'] = %(value_var)s)r6  )r=   r:  resr7  r   r   r;    s    

c                    s.   t | }t|  rd}nd}|| ||d S )Nz/_setattr('%(attr_name)s', %(c)s(%(value_var)s))z2_inst_dict['%(attr_name)s'] = %(c)s(%(value_var)s))r=   r:  c)r>  rA   r6  )r=   r:  r@  Ztmplr7  r   r   rA    s    

c                 S   s   d| |d S )Nzself.%(attr_name)s = %(value)sr=   r   r   rD  r   r   r   r;    s    c                 S   s   t | }d| ||d S )Nz,self.%(attr_name)s = %(conv)s(%(value_var)s)r<  r=  r?  r   r   r   rA  	  s    
returnNr   r    r?   Fz({0})z attr_dict['{attr_name}'].default)r=   z+{arg_name}=attr_dict['{attr_name}'].default)arg_namer=   z{arg_name}=NOTHING)rF  zif {arg_name} is not NOTHING:z    zelse:r   z#if _config._run_validators is True:z__attr_validator_{}z	__attr_{}z    {}(self, {}, self.{})zself.__attrs_post_init__()z_setattr('%s', %s)z_inst_dict['%s'] = %szself.%s = %sNone,c                 s   s   | ]}|j rd |j V  qdS )zself.N)r-   r`   ru   r   r   r   rp     s      z BaseException.__init__(self, %s)ri   z7Keyword-only arguments only work on Python 3 and later.z {leading_comma}*, {kw_only_args})Zleading_commakw_only_argsz(def __init__(self, {args}):
    {lines}
z
    pass)argsr  )r   rC   r)   r`   lstripre   r(   r8   
takes_selfr-   _init_factory_patrA   r.   r>  r:   r   r1   r0   r   r   rH   r   r   )rN   r   r   r-  r   r   r   r  Zany_slot_ancestorsr;  rA  rK  rI  Zattrs_to_validateZnames_for_globalsr.  rv   r=   rF  Zhas_factoryZ
maybe_selfZinit_factory_namer@  argZval_nameZinit_hash_cachevalsr   r7  r   r+    s`   



 




	







 r+  c                   @   s`   e Zd ZdZdZdddZdd Zedd	d
Ze	dd Z
dd Zdd Zdd Zdd ZdS )rr   a   
    *Read-only* representation of an attribute.

    :attribute name: The name of the attribute.

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

    For the version history of the fields, see `attr.ib`.
    )r`   r(   r)   r*   r2   r3   r,   r-   r/   r0   r.   r1   NFc                 C   s   t |||\}}t| t}|d| |d| |d| |d| |d| |d| |d| |d| |d	|
 |d
|rt|nt |d|	 |d| d S )Nr`   r(   r)   r*   r2   r3   r,   r-   r.   r/   r0   r1   )r4   r   r   rr   r   _empty_metadata_singleton)r    r`   r(   r)   r*   r+   r,   r-   r/   r0   r.   r1   r2   r3   bound_setattrr   r   r   r     s&    










zAttribute.__init__c                 C   s
   t  d S r   r   r   r   r   r   r     s    zAttribute.__setattr__c                    sT   |d kr j }n j d k	r"td fddtjD }| f | j j|d d|S )Nz8Type annotation and type argument cannot both be presentc                    s    i | ]}|d kr|t  |qS ))r`   r)   r(   r0   r   )r_   r   ra   r   r   rw     s    z0Attribute.from_counting_attr.<locals>.<dictcomp>)r`   r)   r(   r0   r+   )r0   r6   rr   r   
_validator_default)r   r`   ra   r0   Z	inst_dictr   rS  r   rs     s$    

zAttribute.from_counting_attrc                 C   s   t jttdd | jo| jS )zD
        Simulate the presence of a cmp attribute and warn.
        r  r   )r   r   r   r   r2   r3   r   r   r   r   r+   3  s    zAttribute.cmpc                 K   s   t  | }||  |S )z2
        Copy *self* and apply *changes*.
        )copy	_setattrsr   )r    Zchangesnewr   r   r   r|   =  s    
zAttribute._assocc                    s   t  fdd jD S )(
        Play nice with pickle.
        c                 3   s*   | ]"}|d krt  |nt jV  qdS )r/   N)rU   r   r/   r   r   r   r   rp   L  s   z)Attribute.__getstate__.<locals>.<genexpr>)r   r   r   r   r   r   r   H  s    zAttribute.__getstate__c                 C   s   |  t| j| dS )rY  N)rW  r   r   )r    r   r   r   r   r   Q  s    zAttribute.__setstate__c                 C   sH   t | t}|D ]2\}}|dkr,||| q|||r<t|nt qd S )Nr/   )r   r   rr   r   rQ  )r    Zname_values_pairsrR  r`   r   r   r   r   rW  W  s    
zAttribute._setattrs)NNNFNN)N)r"   r#   r$   r%   r   r   r   r   rs   rE   r+   r|   r   r   rW  r   r   r   r   rr     s$         
+
		rr   c                 C   s*   g | ]"}t |td dd dd|dkdd	qS )NTFr/   )	r`   r(   r)   r*   r+   r2   r3   r,   r-   rr   r   r   r   r   r   rb   e  s   rb   r  c                 C   s   g | ]}|j r|qS r   )r,   ru   r   r   r   rb   v  s      c                   @   s`   e Zd ZdZdZedd dD edddddd	dd	dd	d

f ZdZdd Z	dd Z
dd ZdS )r9   a  
    Intermediate representation of attributes that uses a counter to preserve
    the order in which the attributes have been defined.

    *Internal* data structure of the attrs library.  Running into is most
    likely the result of a bug like a forgotten `@attr.s` decorator.
    )r[   rU  r*   r2   r3   r,   r-   r/   rT  r.   r0   r1   c                 c   s*   | ]"}t |td dd dddddd
V  qd S )NTF
r`   r(   r)   r*   r+   r,   r-   r1   r2   r3   rZ  r   r   r   r   rp     s   z_CountingAttr.<genexpr>)r[   rU  r*   r2   r3   r,   r-   r/   NTFr[  r   c                 C   sz   t  jd7  _t j| _|| _|r:t|ttfr:t| | _n|| _|| _	|| _
|| _|| _|| _|| _|| _|	| _|
| _d S rq   )r9   cls_counterr[   rU  re   listr   and_rT  r*   r2   r3   r,   r-   r.   r/   r0   r1   )r    r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r   r   r   r     s    z_CountingAttr.__init__c                 C   s$   | j dkr|| _ nt| j || _ |S )z
        Decorator that adds *meth* to the list of validators.

        Returns *meth* unchanged.

        .. versionadded:: 17.1.0
        N)rT  r^  r    r   r   r   r   r)     s    
z_CountingAttr.validatorc                 C   s"   | j tk	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)rM  )rU  r   r   r8   r_  r   r   r   r(     s    

z_CountingAttr.default)r"   r#   r$   r%   r   r   rr   ry   r\  r   r)   r(   r   r   r   r   r9   z  s.   $!r9   )r   r-   r,   c                   @   s&   e Zd ZdZe Ze ZdddZdS )r8   a  
    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*
    Fc                 C   s   || _ || _dS )z
        `Factory` is part of the default machinery so if we want a default
        value here, we have to implement it ourselves.
        N)r:   rM  )r    r:   rM  r   r   r   r     s    zFactory.__init__N)F)r"   r#   r$   r%   r;   r:   rM  r   r   r   r   r   r8     s   r8   c              	   K   s   t |tr|}n*t |ttfr2tdd |D }ntd|dd}t| ||dkrXi nd|i}ztdj	
dd|_W n ttfk
r   Y nX |d	d}t||
d
|
d\|d
< |d< tf d|i||S )aR  
    A quick way to create a new class called *name* with *attrs*.

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

    :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.
    c                 s   s   | ]}|t  fV  qd S r   )r;   ru   r   r   r   rp   4  s     zmake_class.<locals>.<genexpr>z(attrs argument must be a dict or a list.r   Nr   r"   __main__r+   r2   r3   r   )re   r   r]  r   r5   popr0   sys	_getframe	f_globalsrj   r#   r   r6   r4   r   )r`   rN   basesZattributes_argumentsZcls_dictr-  Ztype_r+   r   r   r   
make_class  s8    
	 
  
rf  )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    r3  rg   r   r   r   r   r   __call__`  s    
z_AndValidator.__call__N)r"   r#   r$   r%   r;   rh  ri  r   r   r   r   rg  X  s   rg  c                  G   s6   g }| D ] }| t|tr |jn|g qtt|S )z
    A validator that composes multiple validators into one.

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

    :param validators: Arbitrary number of validators.
    :type validators: callables

    .. versionadded:: 17.1.0
    )r  re   rg  rh  r   )Z
validatorsrP  r)   r   r   r   r^  e  s    r^  )NNNTNNTFFTFFFFFNN)N)NN)QZ
__future__r   r   r   rV  r   rb  Z	threadingr   r   operatorr   r?   r   Z_compatr   r	   r
   r   r   r   
exceptionsr   r   r   r   r   objectr   r   r>  rN  rD   rR   r   rQ  r   r   r   r;   rL   rM   rS   rY   r^   r   r   r   r   r   r4   rN   r   r   r   r  r   r  r   r   r   r  Zlocalr!  r   r)  r   r1  r2  r4  r5  r6  r+  rr   r   Z_ar9   r8   rf  rg  r^  r   r   r   r   <module>   s    

 k  4                 
 ~
<'0
;
%   ~A
