
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
U
    #IGZ                     @   sd  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m	Z	 ddl
mZ ddlmZmZmZmZmZ ddlmZmZmZmZ ejZdZd	Zd
Zei ZG dd deZe Zedddddddddf
ddZ dd Z!e!dddgZ"dd Z#dd Z$dd Z%dd Z&dd Z'G dd  d eZ(dRd"dZ)e)Z*er:d#d$ Z+nd%d$ Z+d&d' Z,d(d) Z-d*d+ Z.d,d- Z/d.d/ Z0dSd0d1Z1d2d3 Z2dTd4d5Z3d6d7 Z4d8d9 Z5d:d; Z6d<d= Z7d>d? Z8G d@dA dAeZ9dBdC e9j:D Z;e.e1e3e9e;dDe;dDdEdC e;D dDZ9G dFdG dGeZ<e1e3e<Z<e)dd!ddHG dIdJ dJeZ=effdKdLZ>e)dddMG dNdO dOeZ?dPdQ Z@dS )U    )absolute_importdivisionprint_functionN)
itemgetter   )_config)PY2isclass	iteritemsmetadata_proxyset_closure_cell)DefaultAlreadySetErrorFrozenInstanceErrorNotAnAttrsClassErrorUnannotatedAttributeErrorz__attr_converter_{}z__attr_factory_{}z/    {attr_name} = property(itemgetter({index}))c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )_Nothingz
    Sentinel class to indicate the lack of a value when ``None`` is ambiguous.

    All instances of `_Nothing` are equal.
    c                 C   s   | S N selfr   r   ;/opt/alt/python38/lib/python3.8/site-packages/attr/_make.py__copy__    s    z_Nothing.__copy__c                 C   s   | S r   r   )r   _r   r   r   __deepcopy__#   s    z_Nothing.__deepcopy__c                 C   s
   |j tkS r   )	__class__r   r   otherr   r   r   __eq__&   s    z_Nothing.__eq__c                 C   s
   | |k S r   r   r   r   r   r   __ne__)   s    z_Nothing.__ne__c                 C   s   dS )NNOTHINGr   r   r   r   r   __repr__,   s    z_Nothing.__repr__c                 C   s   dS )Nl   >[= r   r   r   r   r   __hash__/   s    z_Nothing.__hash__N)
__name__
__module____qualname____doc__r   r   r   r   r    r!   r   r   r   r   r      s   r   Tc
           
      C   sr   |dk	r |dk	r |dk	r t d|dk	rL|	dk	r8tdtjdtdd |}	|dkrXi }t| ||||||	||d		S )
aJ  
    Create a new attribute on a class.

    ..  warning::

        Does *not* do anything unless the class is also decorated with
        :func:`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 :class:`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 :exc:`TypeError`
        will be raised.

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

    :type default: Any value.

    :param validator: :func:`callable` that is called by ``attrs``-generated
        ``__init__`` methods after the instance has been initialized.  They
        receive the initialized instance, the :class:`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
        :func:`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 bool repr: Include this attribute in the generated ``__repr__``
        method.
    :param bool cmp: Include this attribute in the generated comparison methods
        (``__eq__`` et al).
    :param hash: Include this attribute in the generated ``__hash__``
        method.  If ``None`` (default), mirror *cmp*'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: :func:`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 :ref:`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``.

    .. 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 *cmp* 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.
    NTF6Invalid value for hash.  Must be True, False, or None.HCan't pass both `convert` and `converter`.  Please use `converter` only.`The `convert` argument is deprecated in favor of `converter`.  It will be removed after 2019/01.   
stacklevel)	default	validatorreprcmphashinit	convertermetadatatype)	TypeErrorRuntimeErrorwarningswarnDeprecationWarning_CountingAttr)
r,   r-   r.   r/   r0   r1   convertr3   r4   r2   r   r   r   attrib9   s8    R r<   c                 C   sv   d | }d |dg}|rDt|D ]\}}|tj ||d q$n
|d dti}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    passr   
 exec)format	enumerateappend_tuple_property_patr   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super_attrsc                 C   s   t | dS )z
    Check whether *annot* is a typing.ClassVar.

    The implementation is gross but importing `typing` is slow and there are
    discussions to remove it from the stdlib alltogether.
    ztyping.ClassVar)str
startswith)Zannotr   r   r   _is_class_var   s    rR   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__)clsanns	super_clsr   r   r   _get_annotations   s    
rY   c              	      sL  | j t|  |dk	r6tdd t|D dd d}n|dkrdd	  D }g }t }  D ]Z\}}t|rtqb|| |t	}t
|ts|t	krt }n
t|d
}|||f qb|| }	t|	dkrtddt|	fddd d ntdd  D dd d} fdd|D }
g }dd |
D }| jdd D ]R}t|dd}|dk	rJ|D ]0}||j}|dkrh|| |||j< qhqJdd ||
 D }t| j|}|| fdd|D  }d}|D ]`}|dkr|jt	kr|jdkrtdj|dn&|dkr|jt	k	r|jdk	rd}qt||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   | ]\}}||fV  qd S r   r   ).0namecar   r   r   	<genexpr>   s   z#_transform_attrs.<locals>.<genexpr>c                 S   s
   | d j S Nr   counterer   r   r   <lambda>       z"_transform_attrs.<locals>.<lambda>)keyTc                 S   s   h | ]\}}t |tr|qS r   
isinstancer:   rZ   r[   attrr   r   r   	<setcomp>   s   
z#_transform_attrs.<locals>.<setcomp>)r,   r   z1The following `attr.ib`s lack a type annotation: , c                    s     | jS r   )getr`   )n)cdr   r   rc     rd   .c                 s   s$   | ]\}}t |tr||fV  qd S r   rf   rh   r   r   r   r]     s   
c                 S   s
   | d j S r^   r_   ra   r   r   r   rc      rd   c                    s&   g | ]\}}t j|| |d qS )r[   r\   r4   	Attributefrom_counting_attrrl   rZ   r>   r\   rW   r   r   
<listcomp>"  s   z$_transform_attrs.<locals>.<listcomp>c                 S   s   i | ]}|j |qS r   r[   rZ   ar   r   r   
<dictcomp>-  s      z$_transform_attrs.<locals>.<dictcomp>r   __attrs_attrs__c                 S   s   g | ]
}|j qS r   rw   rx   r   r   r   rv   ;  s     c                    s&   g | ]\}}t j|| |d qS rp   rq   rt   ru   r   r   rv   @  s   FzqNo mandatory attributes allowed after an attribute with a default value or factory.  Attribute in question: {a!r})ry   )__dict__rY   sortedr
   itemssetrR   addrl   r   rg   r:   r<   rD   lenr   rH   rU   rT   r[   rL   r"   r,   r1   
ValueErrorrB   rM   )rV   theseauto_attribsZca_listZca_namesZannot_namesr>   r4   ry   ZunannotatedZ	own_attrsrO   Ztaken_attr_namesrX   Z	sub_attrsZprev_arI   Z
AttrsClassrN   Zhad_defaultr   )rW   rn   r   _transform_attrs   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_delattrsb  s    r   c                   @   st   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S )_ClassBuilderz(
    Iteratively build *one* class.
    )_cls	_cls_dict_attrs_super_names_attr_names_slots_frozen_has_post_initc                 C   s   t |||\}}|| _|r$t|jni | _|| _tdd |D | _tdd |D | _	|| _
|pht|| _tt|dd| _| j| jd< |rt| jd< t| jd< d S )	Nc                 s   s   | ]}|j V  qd S r   rw   rx   r   r   r   r]   x  s     z)_ClassBuilder.__init__.<locals>.<genexpr>c                 s   s   | ]}|j V  qd S r   rw   rx   r   r   r   r]   y  s     __attrs_post_init__Fr|   __setattr____delattr__)r   r   dictr}   r   r   r   r   tupler   r   _has_frozen_superclassr   boolrT   r   r   r   )r   rV   r   slotsfrozenr   rN   rO   r   r   r   __init__r  s    
z_ClassBuilder.__init__c                 C   s   dj | jjdS )Nz<_ClassBuilder(cls={cls})>rV   )rB   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 anymore 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D ]&}||krt||ddk	rt|| q| j D ]\}}t||| qD|S )zA
        Apply accumulated methods and return the class.
        N)r   r   r   rT   delattrr   r   setattr)r   rV   super_namesr[   r   r   r   r   r     s    
z#_ClassBuilder._patch_original_classc           	         s  j fddtjD }tfddjD |d< tjdd}|dk	rX||d< tj  fdd	} fd
d}||d< ||d< tjjjjj	|}|j
 D ]T}t|ttfrt|jdd}nt|dd}|sq|D ]}|jjkrt|| qq|S )zL
        Build and return a new class with a `__slots__` attribute.
        c                    s(   i | ] \}}|t  jd  kr||qS ))r}   )r   r   )rZ   kvr   r   r   rz     s    z5_ClassBuilder._create_slots_class.<locals>.<dictcomp>c                 3   s   | ]}| kr|V  qd S r   r   rZ   r[   )r   r   r   r]     s   z4_ClassBuilder._create_slots_class.<locals>.<genexpr>	__slots__r$   Nc                    s   t  fddD S )9
            Automatically created by attrs.
            c                 3   s   | ]}t  |V  qd S r   rT   r   r   r   r   r]     s     zL_ClassBuilder._create_slots_class.<locals>.slots_getstate.<locals>.<genexpr>r   r   rI   r   r   slots_getstate  s    z9_ClassBuilder._create_slots_class.<locals>.slots_getstatec                    s.   t | t}t |D ]\}}||| qdS )r   N)_obj_setattr__get__rr   zip)r   stateZ_ClassBuilder__bound_setattrr[   r   r   r   r   slots_setstate  s    z9_ClassBuilder._create_slots_class.<locals>.slots_setstate__getstate____setstate____closure__)r   r
   r   r   r   rT   r   r4   r"   	__bases__r}   valuesrg   classmethodstaticmethod__func__cell_contentsr   )	r   rn   qualnamer   r   rV   itemZclosure_cellscellr   )rI   r   r   r   r     s<    

	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   rl   r   r   )r   r.   r   r   r   r   add_str  s    z_ClassBuilder.add_strc                 C   s   d | j d< | S Nr!   )r   r   r   r   r   make_unhashable   s    
z_ClassBuilder.make_unhashablec                 C   s   |  t| j| jd< | S r   )r   
_make_hashr   r   r   r   r   r   add_hash  s    
z_ClassBuilder.add_hashc                 C   s"   |  t| j| j| j| jd< | S )Nr   )r   
_make_initr   r   r   r   r   r   r   r   add_init  s    
z_ClassBuilder.add_initc                    sF    j } fddt jD \|d< |d< |d< |d< |d< |d<  S )	Nc                 3   s   | ]}  |V  qd S r   )r   )rZ   methr   r   r   r]     s   z(_ClassBuilder.add_cmp.<locals>.<genexpr>r   r   __lt____le____gt____ge__)r   	_make_cmpr   )r   rn   r   r   r   add_cmp  s    
 z_ClassBuilder.add_cmpc                 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#   AttributeErrorrH   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   i  s   Hr   Fc              
      s6    	f
dd}| dkr*|S || S dS )aU  
    A class decorator that adds `dunder
    <https://wiki.python.org/moin/DunderAlias>`_\ -methods according to the
    specified attributes using :func:`attr.ib` or the *these* argument.

    :param these: A dictionary of name to :func:`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.

    :type these: :class:`dict` of :class:`str` to :func:`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
        :class:`Exception`\ s.
    :param bool cmp: Create ``__eq__``, ``__ne__``, ``__lt__``, ``__le__``,
        ``__gt__``, and ``__ge__`` methods that compare the class as if it were
        a tuple of its ``attrs`` attributes.  But the attributes are *only*
        compared, if the type of both classes is *identical*!
    :param hash: If ``None`` (default), the ``__hash__`` method is generated
        according how *cmp* and *frozen* are set.

        1. If *both* are True, ``attrs`` will generate a ``__hash__`` for you.
        2. If *cmp* is True and *frozen* is False, ``__hash__`` will be set to
           None, marking it unhashable (which it is).
        3. If *cmp* is False, ``__hash__`` will be left untouched meaning the
           ``__hash__`` method of the superclass will be used (if superclass 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 the `Python documentation \
        <https://docs.python.org/3/reference/datamodel.html#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 slots_-style class that's more
        memory-efficient.  See :ref:`slots` for further ramifications.
    :param bool frozen: Make instances immutable after initialization.  If
        someone attempts to modify a frozen instance,
        :exc:`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 an own one.

            2. True immutability is impossible in Python.

            3. This *does* have a minor a runtime performance :ref:`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)``.

        ..  _slots: https://docs.python.org/3/reference/datamodel.html#slots
    :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 :func:`attr.ib` but lacks a type
        annotation, an :exc:`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 :class:`Factory` also
        works as expected.

        Attributes annotated as :data:`typing.ClassVar` are **ignored**.

        .. _`PEP 526`: https://www.python.org/dev/peps/pep-0526/

    ..  versionadded:: 16.0.0 *slots*
    ..  versionadded:: 16.1.0 *frozen*
    ..  versionadded:: 16.3.0 *str*, and 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*
    c                    s   t | dd d krtdt| 	 }dkr:| dkrJ|  dkrZ|  dk	r|dk	r|d k	r|tdnLdksȈd krdkrn2dksd krdkrdkr|  n|  dkr|  |	 S )Nr   z(attrs only works with new-style classes.TFr&   )
rT   r5   r   r   r   r   r   r   r   r   )rV   Zbuilder
r   r/   r   r0   r1   r.   repr_nsr   rP   r   r   r   wrap  s*    
 
zattrs.<locals>.wrapNr   )Z	maybe_clsr   r   r.   r/   r0   r1   r   r   rP   r   r   r   r   r   rN   4  s    g 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)rT   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   )rT   r[   rx   objr   r   r]     s     z"_attrs_to_tuple.<locals>.<genexpr>r   )r   rN   r   r   r   _attrs_to_tuple  s    r   c           
      C   s   t dd | D } t }|t| d d| f }t|}ddd|f g}| D ]}|d|j	  qX|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)r0   r/   rx   r   r   r   r]     s
   
 
 
z_make_hash.<locals>.<genexpr>utf-8z<attrs generated hash %s>zdef __hash__(self):z    return hash((z        %d,        self.%s,z    ))r?   rA   Tr!   )r   hashlibsha1updater.   encode	hexdigestr0   rD   r[   rH   rG   rF   r   
splitlines	linecachecache)
rN   r   unique_filenameZ	type_hashlinesry   scriptrK   locsbytecoder   r   r   r     s2    


r   c                 C   s   t || _| S )z%
    Add a hash method to *cls*.
    )r   r!   rV   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   r   resultr   r   r   r     s    
r   c                    s<  dd  D  t  }|t d d| f }dddg} r|d d	g} D ](}|d
|jf  |d|jf  qZ||dg 7 }n
|d d|}i }i }t	||d}	t
|	|| t|d |d|ftj|< |d }
t} 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   )r/   rx   r   r   r   rv   !  s      z_make_cmp.<locals>.<listcomp>r   z<attrs generated eq %s>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?   rA   Tr   c                    s
   t |  S )z&
        Save us some typing.
        )r   r   rN   r   r   attrs_to_tupleL  s    z!_make_cmp.<locals>.attrs_to_tuplec                    s$   t || jr |  |k S tS dS 1
        Automatically created by attrs.
        Nrg   r   r   r   r   r   r   r   R  s    z_make_cmp.<locals>.__lt__c                    s$   t || jr |  |kS tS dS r   r   r   r   r   r   r   [  s    z_make_cmp.<locals>.__le__c                    s$   t || jr |  |kS tS dS r   r   r   r   r   r   r   d  s    z_make_cmp.<locals>.__gt__c                    s$   t || jr |  |kS tS dS r   r   r   r   r   r   r   m  s    z_make_cmp.<locals>.__ge__)r   r   r   r.   r   r   rD   r[   rH   rG   rF   r   r   r   r   r   )rN   r   r   r   Zothersry   r   rK   r   r   eqner   r   r   r   r   )rN   r   r   r      sF    



				r   c                 C   s2   |dkr| j }t|\| _| _| _| _| _| _| S )z*
    Add comparison methods to *cls*.
    N)r|   r   r   r   r   r   r   r   r   r   r   r   _add_cmpy  s
    r   c                    s$   t dd | D   fdd}|S )zK
    Make a repr method for *attr_names* adding *ns* to the full name.
    c                 s   s   | ]}|j r|jV  qd S r   )r.   r[   rx   r   r   r   r]     s   z_make_repr.<locals>.<genexpr>c                    sj    j }dkr<t|dd}|dk	r4|ddd }qJ|j}nd |j }d|d fd	d
D S )r   Nr$   z>.r   r{   ro   z{0}({1})rk   c                 3   s&   | ]}|d  t t |t V  qdS )=N)r.   rT   r   r   r   r   r   r]     s   z/_make_repr.<locals>.__repr__.<locals>.<genexpr>)r   rT   rsplitr"   rB   rH   )r   Zreal_clsr   
class_namerI   r   r   r   r      s    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)r|   r   r    )rV   r   rN   r   r   r   	_add_repr  s    r   c           
      C   s   dd | D } t  }|t| d d| }t| ||\}}i }t||d}t	dd | D }	|t
|	d |d	krt|d
< t||| t|d |d	|ftj|< |d S )Nc                 S   s    g | ]}|j s|jtk	r|qS r   )r1   r,   r   rx   r   r   r   rv     s    
z_make_init.<locals>.<listcomp>r   z<attrs generated init {0}>rA   c                 s   s   | ]}|j |fV  qd S r   rw   rx   r   r   r   r]     s     z_make_init.<locals>.<genexpr>)r   	attr_dictTZ_cached_setattrr   )r   r   r   r.   r   rB   r   _attrs_to_init_scriptrG   r   r   r   rF   r   r   r   r   )
rN   	post_initr   r   r   r   rK   r   r   r   r   r   r   r     s:    
r   c                 C   s   t | jt| dd|| _| S )zR
    Add a __init__ method to *cls*.  If *frozen* is True, make it immutable.
    r   F)r   r|   rT   r   )rV   r   r   r   r   	_add_init  s    
r   c                 C   s8   t | stdt| dd}|dkr4tdj| d|S )a  
    Returns 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 :class:`attr.Attribute`

    ..  versionchanged:: 16.2.0 Returned tuple allows accessing the fields
        by name.
    zPassed object must be a class.r|   Nz({cls!r} is not an attrs-decorated class.r   )r	   r5   rT   r   rB   r   r   r   r   fields  s    
r  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_validatorsr  r   r-   rT   r[   )instry   r   r   r   r   validate  s    
r  c              
   C   s  g }|dkr(| d dd }dd }ndd }dd }g }g }i }| D ]}	|	jr^| |	 |	j}
|	jd	}t|	jt}|r|	jjrd
}nd}|	jdkrj|rt	
|	j}|	jdk	r| ||
|d
|  t
|	j}|	j||< n| ||
|d
|  |	jj||< nT|	jdk	rP| ||
dj
|
d t
|	j}|	j||< n| ||
dj
|
d qH|	jtk	r|s| dj
||
d |	jdk	r| ||
| |	j|t
|	j< n| ||
| qH|r| dj
|d | dj
|d t	
|	j}|	jdk	rd| d||
|  | d | d||
|d
|   |	j|t
|	j< n<| d||
|  | d | d||
|d
|   |	jj||< qH| | |	jdk	r| ||
| |	j|t
|	j< qH| ||
| qH|r^t|d< | d |D ]F}	d
|	j}d
|	j}
| d
||
|	j |	j||< |	||
< q|rn| d dj
d||rd |nd!d"|fS )#z
    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__``.
    Tz8_setattr = _cached_setattr.__get__(self, self.__class__)c                 S   s   d| |d S )Nz(_setattr('%(attr_name)s', %(value_var)s)r>   	value_varr   r  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  conv_init_converter_patrB   r>   r  	conv_namer   r   r   fmt_setter_with_converter/  s    
z8_attrs_to_init_script.<locals>.fmt_setter_with_converterc                 S   s   d| |d S )Nzself.%(attr_name)s = %(value)sr>   r   r   r  r   r   r   r  7  s    c                 S   s   t | }d| ||d S )Nz,self.%(attr_name)s = %(conv)s(%(value_var)s)r  r	  r  r   r   r   r  =  s    
r   r   r@   FNz({0})z attr_dict['{attr_name}'].default)r>   z+{arg_name}=attr_dict['{attr_name}'].default)arg_namer>   z{arg_name}=NOTHING)r  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(def __init__(self, {args}):
    {lines}
rk   z
    pass)argsr   )rD   r-   r[   lstriprg   r,   Factory
takes_selfr1   _init_factory_patrB   r2   r
  factoryr   r   rH   )rN   r   r   r   r  r  r  Zattrs_to_validateZnames_for_globalsry   r>   r  Zhas_factoryZ
maybe_selfZinit_factory_namer  Zval_namer   r   r   r     s    	



 



  

r   c                   @   sP   e Zd ZdZdZdddZdd Zedd	 Ze	dd
dZ
dd Zdd ZdS )rr   z
    *Read-only* representation of an attribute.

    :attribute name: The name of the attribute.

    Plus *all* arguments of :func:`attr.ib`.

    For the version history of the fields, see :func:`attr.ib`.
    )
r[   r,   r-   r.   r/   r0   r1   r3   r4   r2   Nc                 C   s   t | t}|d k	r8|d k	r$tdtjdtdd |}|d| |d| |d| |d| |d	| |d
| |d| |d| |d|	rt|	nt |d|
 d S )Nr'   r(   r)   r*   r[   r,   r-   r.   r/   r0   r1   r2   r3   r4   )	r   r   rr   r6   r7   r8   r9   r   _empty_metadata_singleton)r   r[   r,   r-   r.   r/   r0   r1   r;   r3   r4   r2   bound_setattrr   r   r   r     s2     







zAttribute.__init__c                 C   s
   t  d S r   r   r   r   r   r   r     s    zAttribute.__setattr__c                 C   s   t jdtdd | jS )NzaThe `convert` attribute is deprecated in favor of `converter`.  It will be removed after 2019/01.r)   r*   )r7   r8   r9   r2   r   r   r   r   r;     s     zAttribute.convertc                    sR   |d kr j }n j d k	r"td fddtjD }| f | j j|d|S )Nz8Type annotation and type argument cannot both be presentc                    s    i | ]}|d kr|t  |qS ))r[   r-   r,   r4   r;   r   )rZ   r   r\   r   r   rz     s    z0Attribute.from_counting_attr.<locals>.<dictcomp>)r[   r-   r,   r4   )r4   r   rr   r   
_validator_default)rV   r[   r\   r4   Z	inst_dictr   r  r   rs     s"    

   zAttribute.from_counting_attrc                    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 )r3   N)rT   r   r3   r   r   r   r   r]     s   z)Attribute.__getstate__.<locals>.<genexpr>)r   r   r   r   r   r   r     s    zAttribute.__getstate__c                 C   sP   t | t}t| j|D ]2\}}|dkr4||| q|||rDt|nt qdS )r  r3   N)r   r   rr   r   r   r   r  )r   r   r  r[   r   r   r   r   r     s    zAttribute.__setstate__)NNNN)N)r"   r#   r$   r%   r   r   r   propertyr;   r   rs   r   r   r   r   r   r   rr     s   	       
"
rr   c                 C   s.   g | ]&}|d krt |tddd|dkddqS )r;   NTr3   r[   r,   r-   r.   r/   r0   r1   rr   r   r   r   r   r   rv   $  s      rv   r   c                 C   s   g | ]}|j r|qS r   )r0   rx   r   r   r   rv   -  s      c                
   @   sZ   e Zd ZdZdZedd dD edddddd	dd
f ZdZdd Z	dd Z
dd ZdS )r:   a  
    Intermediate representation of attributes that uses a counter to preserve
    the order in which the attributes have been defined.

    *Internal* data structure of the attrs library.  Running into is most
    likely the result of a bug like a forgotten `@attr.s` decorator.
    )
r`   r  r.   r/   r0   r1   r3   r  r2   r4   c              
   c   s$   | ]}t |td dddddV  qd S )NTr  r  r   r   r   r   r]   ;  s      z_CountingAttr.<genexpr>)r`   r  r.   r/   r0   r1   r3   NTFr  r   c
           
      C   sn   t  jd7  _t j| _|| _|r:t|ttfr:t| | _n|| _|| _	|| _
|| _|| _|| _|| _|	| _d S r^   )r:   cls_counterr`   r  rg   listr   and_r  r.   r/   r0   r1   r2   r3   r4   )
r   r,   r-   r.   r/   r0   r1   r2   r3   r4   r   r   r   r   F  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)r  r"  r   r   r   r   r   r-   X  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)r  )r  r   r   r  r#  r   r   r   r,   f  s    

z_CountingAttr.default)r"   r#   r$   r%   r   r   rr   r|   r   r   r-   r,   r   r   r   r   r:   1  s"      	r:   )r   r1   r0   c                   @   s&   e Zd ZdZe Ze ZdddZdS )r  a  
    Stores a factory callable.

    If passed as the default value to :func:`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  r  )r   r  r  r   r   r   r     s    zFactory.__init__N)F)r"   r#   r$   r%   r<   r  r  r   r   r   r   r   r  {  s   r  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 tf d	|i||S )
a  
    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.
    :type attrs: :class:`list` or :class:`dict`

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

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

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

    ..  versionadded:: 17.1.0 *bases*
    c                 s   s   | ]}|t  fV  qd S r   )r<   rx   r   r   r   r]     s     zmake_class.<locals>.<genexpr>z(attrs argument must be a dict or a list.r   Nr   r"   __main__r   )rg   r   r!  r   r5   popr4   sys	_getframe	f_globalsrl   r#   r   r   r   )r[   rN   basesZattributes_argumentsZcls_dictr   Ztype_r   r   r   
make_class  s&    
	 
r*  )r   r0   c                   @   s   e Zd ZdZe Zdd ZdS )_AndValidatorz2
    Compose many validators to a single one.
    c                 C   s   | j D ]}|||| qd S r   )_validators)r   r  ri   r   r   r   r   r   __call__  s    
z_AndValidator.__call__N)r"   r#   r$   r%   r<   r,  r-  r   r   r   r   r+    s   r+  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
    )extendrg   r+  r,  r   )Z
validatorsvalsr-   r   r   r   r"    s    r"  )NNNTTNTFFFF)N)NN)A
__future__r   r   r   r   r   r&  r7   operatorr   r@   r   _compatr   r	   r
   r   r   
exceptionsr   r   r   r   objectr   r   r
  r  rE   r  r   r   r<   rL   rM   rR   rY   r   r   r   r   rN   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   rr   r   Z_ar:   r  r*  r+  r"  r   r   r   r   <module>   s         
t
p L               
 
(Y
"
, $iG3
