Viewing File: /opt/alt/python35/lib/python3.5/site-packages/attr/__pycache__/_make.cpython-35.opt-1.pyc



#IGZ
@sddlmZmZmZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
mZmZmZmZddlmZmZmZmZejZdZd	Zd
ZeiZGdddeZeZedd
d
dd
dddddd
Z ddZ!e!dddgZ"ddZ#ddZ$ddZ%ddZ&ddZ'Gdd d eZ(dddd
d
dd
d!d!d!d!d"dZ)e)Z*e
rd#d$Z+nd%d$Z+d&d'Z,d(d)Z-d*d+Z.d,d-Z/d.d/Z0dd0d1Z1d2d3Z2ddd4d5Z3d6d7Z4d8d9Z5d:d;Z6d<d=Z7d>d?Z8Gd@dAdAeZ9dBdCe9j:DZ;e.e1e3e9de;de;ddDdCe;DZ9GdEdFdFeZ<e1e3e<Z<e)dGd
dHd!dId
GdJdKdKeZ=efdLdMZ>e)dGd
dId
GdNdOdOeZ?dPdQZ@dS)R)absolute_importdivisionprint_functionN)
itemgetter)_config)PY2isclass	iteritemsmetadata_proxyset_closure_cell)DefaultAlreadySetErrorFrozenInstanceErrorNotAnAttrsClassErrorUnannotatedAttributeErrorz__attr_converter_{}z__attr_factory_{}z/    {attr_name} = property(itemgetter({index}))c@s^eZdZdZddZddZddZdd	Zd
dZdd
Z	dS)_Nothingz
    Sentinel class to indicate the lack of a value when ``None`` is ambiguous.

    All instances of `_Nothing` are equal.
    cCs|S)N)selfrr	/_make.py__copy__ sz_Nothing.__copy__cCs|S)Nr)r_rrr__deepcopy__#sz_Nothing.__deepcopy__cCs
|jtkS)N)	__class__r)rotherrrr__eq__&sz_Nothing.__eq__cCs||kS)Nr)rrrrr__ne__)sz_Nothing.__ne__cCsdS)NNOTHINGr)rrrr__repr__,sz_Nothing.__repr__cCsdS)Nl>[=r)rrrr__hash__/sz_Nothing.__hash__N)
__name__
__module____qualname____doc__rrrrrrrrrrrsrTc

Cs|dk	r0|dk	r0|dk	r0td|dk	rp|	dk	rTtdtjdtdd|}	|dkri}td	|d
|d|d|d
|d|d|	d|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.
    NTFz6Invalid value for hash.  Must be True, False, or None.zHCan't pass both `convert` and `converter`.  Please use `converter` only.z`The `convert` argument is deprecated in favor of `converter`.  It will be removed after 2019/01.
stackleveldefault	validatorreprcmphashinit	convertermetadatatype)	TypeErrorRuntimeErrorwarningswarnDeprecationWarning
_CountingAttr)
r%r&r'r(r)r*convertr,r-r+rrrattrib9s.R$		
r5cCsdj|}dj|dg}|rixIt|D]+\}}|jtjd|d|q7Wn
|jddti}ttdj|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{}Attributeszclass {}(tuple):z    __slots__ = ()index	attr_namez    passr
exec)format	enumerateappend_tuple_property_patrevalcompilejoin)Zcls_name
attr_namesZattr_class_nameZattr_class_templateir7globsrrr_make_attr_tuple_classs
	
"rE_Attributesattrssuper_attrscCst|jdS)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.
    ztyping.ClassVar)str
startswith)Zannotrrr
_is_class_varsrKcCs`t|dd}|dkr"iSx7|jddD]"}|t|ddkr6iSq6W|S)z$
    Get annotations for *cls*.
    __annotations__Nr)getattr__mro__)clsanns	super_clsrrr_get_annotationssrRc	s5|jt||dk	rOtddt|Dddd}nG|dkrkdd	jD}g}t}xjD]\}}t|rq|j|j|t	}t
|ts|t	krt}ntd
|}|j
||fqW||}	t|	dkrtdd
jt|	dfdddn+tddjDddd}fdd|D}
g}dd|
D}x|jddD]m}
t|
dd}|dk	rxF|D]>}|j|j}|dkr|j
||||j<qWqWdd||
D}t|j|}||fdd|D}d}x|D]{}|dkr|jt	kr|jdkrtdjd|q|dkr|jt	k	r|jdk	rd}qWt||fS)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`.
    Ncss!|]\}}||fVqdS)Nr).0namecarrr	<genexpr>sz#_transform_attrs.<locals>.<genexpr>keycSs|djS)Nr)counter)errr<lambda>sz"_transform_attrs.<locals>.<lambda>TcSs+h|]!\}}t|tr|qSr)
isinstancer3)rSrTattrrrr	<setcomp>s		z#_transform_attrs.<locals>.<setcomp>r%rz1The following `attr.ib`s lack a type annotation: z, csj|jS)N)getrX)n)cdrrrZs.css0|]&\}}t|tr||fVqdS)N)r[r3)rSrTr\rrrrVs	cSs|djS)Nr)rX)rYrrrrZ sc
s=g|]3\}}tjd|d|dj|qS)rTrUr-)	Attributefrom_counting_attrr^)rSr7rU)rPrr
<listcomp>#s	z$_transform_attrs.<locals>.<listcomp>cSsi|]}||jqSr)rT)rSarrr
<dictcomp>-s	z$_transform_attrs.<locals>.<dictcomp>r__attrs_attrs__cSsg|]}|jqSr)rT)rSrerrrrd;s	c
s=g|]3\}}tjd|d|dj|qS)rTrUr-)rbrcr^)rSr7rU)rPrrrdAs	FzqNo mandatory attributes allowed after an attribute with a default value or factory.  Attribute in question: {a!r}re)__dict__rRsortedr
itemssetrKaddr^rr[r3r5r=lenrrArNrMrTrErr%r*
ValueErrorr;rF)rOtheseauto_attribsZca_listZca_namesZannot_namesr7r-reZunannotatedZ	own_attrsrHZtaken_attr_namesrQZ	sub_attrsZprev_arBZ
AttrsClassrGZhad_defaultr)rPr`r_transform_attrssv				

5	



*	
rrcCs
tdS)z4
    Attached to frozen classes as __setattr__.
    N)r)rrTvaluerrr_frozen_setattrs[srtcCs
tdS)z4
    Attached to frozen classes as __delattr__.
    N)r)rrTrrr_frozen_delattrsbsruc@seZdZdZd#Zd
dZdd
ZddZddZddZ	ddZ
ddZddZddZ
ddZddZd d!Zd"S)$
_ClassBuilderz(
    Iteratively build *one* class.
    _cls	_cls_dict_attrs_super_names_attr_names_slots_frozen_has_post_initcCst|||\}}||_|r6t|jni|_||_tdd|D|_tdd|D|_	||_
|pt||_t
t|dd|_|j|jd<|rt|jd<t|jd<dS)	Ncss|]}|jVqdS)N)rT)rSrerrrrVxsz)_ClassBuilder.__init__.<locals>.<genexpr>css|]}|jVqdS)N)rT)rSrerrrrVys__attrs_post_init__Frg__setattr____delattr__)rrrwdictrirxryrlrztupler{r|_has_frozen_superclassr}boolrMr~rtru)rrOrpslotsfrozenrqrGrHrrr__init__rs			
z_ClassBuilder.__init__cCsdjd|jjS)Nz<_ClassBuilder(cls={cls})>rO)r;rwr)rrrrrsz_ClassBuilder.__repr__cCs'|jdkr|jS|jSdS)z
        Finalize class based on the accumulated configuration.

        Builder cannot be used anymore after calling this method.
        TN)r|_create_slots_class_patch_original_class)rrrrbuild_classs
z_ClassBuilder.build_classcCs|j}|j}xB|jD]7}||krt||ddk	rt||qWx-|jjD]\}}t|||qgW|S)zA
        Apply accumulated methods and return the class.
        N)rwrzr{rMdelattrrxrksetattr)rrOsuper_namesrTrsrrrrs		z#_ClassBuilder._patch_original_classc	sjfddtjD}tfddjD|d<tjdd}|dk	r|||d<tjfdd	}fd
d}||d<||d
<tjjjjj	|}x|j
jD]~}t|t
tfr-t|jdd}nt|dd}|sHqx-|D]%}|jjkrOt||qOWqW|S)zL
        Build and return a new class with a `__slots__` attribute.
        cs8i|].\}}|tjdkr||qS)ri)ri)rr{)rSkv)rrrrfs		z5_ClassBuilder._create_slots_class.<locals>.<dictcomp>c3s!|]}|kr|VqdS)Nr)rSrT)rrrrVsz4_ClassBuilder._create_slots_class.<locals>.<genexpr>	__slots__r!NcstfddDS)z9
            Automatically created by attrs.
            c3s|]}t|VqdS)N)rM)rSrT)rrrrVszL_ClassBuilder._create_slots_class.<locals>.slots_getstate.<locals>.<genexpr>)r)r)rB)rrslots_getstatesz9_ClassBuilder._create_slots_class.<locals>.slots_getstatecsCtj|t}x*t|D]\}}|||q"WdS)z9
            Automatically created by attrs.
            N)_obj_setattr__get__rbzip)rstateZ_ClassBuilder__bound_setattrrTrs)rBrrslots_setstatesz9_ClassBuilder._create_slots_class.<locals>.slots_setstate__getstate____setstate____closure__)rzr
rxrr{rMrwr-r	__bases__rivaluesr[classmethodstaticmethod__func__
cell_contentsr)	rr`qualnamerrrOitemZ
closure_cellsZcellr)rBrrrrs8	
	

				
z!_ClassBuilder._create_slots_classcCs)|jt|jd||jd<|S)Nnsr)_add_method_dunders
_make_reprryrx)rrrrradd_reprsz_ClassBuilder.add_reprcCsP|jjd}|dkr*tddd}|j||jd<|S)Nrz3__str__ can only be generated if a __repr__ exists.cSs
|jS)N)r)rrrr__str__sz&_ClassBuilder.add_str.<locals>.__str__r)rxr^ror)rr'rrrradd_strs	z_ClassBuilder.add_strcCsd|jd<|S)Nr)rx)rrrrmake_unhashables
z_ClassBuilder.make_unhashablecCs#|jt|j|jd<|S)Nr)r
_make_hashryrx)rrrradd_hashsz_ClassBuilder.add_hashcCs/|jt|j|j|j|jd<|S)Nr)r
_make_initryr~r}rx)rrrradd_initsz_ClassBuilder.add_initcsYj}fddtjD\|d<|d<|d<|d<|d<|d<S)	Nc3s|]}j|VqdS)N)r)rSmeth)rrrrVsz(_ClassBuilder.add_cmp.<locals>.<genexpr>rr__lt____le____gt____ge__)rx	_make_cmpry)rr`r)rradd_cmps	=z_ClassBuilder.add_cmpcCsfy|jj|_Wntk
r'YnXy%dj|jj|jf|_Wntk
raYnX|S)zL
        Add __module__ and __qualname__ to a *method* if possible.
        ra)rwr AttributeErrorrAr!r)rmethodrrrr!s

z!_ClassBuilder._add_method_dundersN)rwrxryrzr{r|r}r~)rr r!r"rrrrrrrrrrrrrrrrrrvisH
rvFc
sK	f
dd}|dkr=|S||SdS)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*
    csBt|dddkr$tdt|	}dkrU|jdkrk|jdkr|jdk	rdk	rdk	rtdnndks"dkrdkrnGdksdkrdkrdkr|jn
|jdkr8|j|j	S)Nrz(attrs only works with new-style classes.TFz6Invalid value for hash.  Must be True, False, or None.)
rMr.rvrrrrrrr)rOZbuilder)
rqr(rr)r*r'repr_nsrrIrprrwraps(


$$0


zattrs.<locals>.wrapNr)Z	maybe_clsrprr'r(r)r*rrrIrqrr)
rqr(rr)r*r'rrrIrprrG4sg- cCs1t|jddtjko0|jjtjkS)zb
        Check whether *cls* has a frozen ancestor by looking at its
        __setattr__.
        r N)rMrrtr r)rOrrrrsrcCs
|jtkS)zb
        Check whether *cls* has a frozen ancestor by looking at its
        __setattr__.
        )rrt)rOrrrrscstfdd|DS)z:
    Create a tuple of all values of *obj*'s *attrs*.
    c3s!|]}t|jVqdS)N)rMrT)rSre)objrrrVsz"_attrs_to_tuple.<locals>.<genexpr>)r)rrGr)rr_attrs_to_tuplesrc
Cstdd|D}tj}|jt|jdd|jf}t|}ddd|fg}x"|D]}|jd|j	q}W|jd	d
j
|}i}i}t||d}	t|	||t
|d|jd|ftj|<|d
S)NcssB|]8}|jdks6|jdkr|jdkr|VqdS)TN)r)r()rSrerrrrVsz_make_hash.<locals>.<genexpr>zutf-8z<attrs generated hash %s>zdef __hash__(self):z    return hash((z        %d,z        self.%s,z    ))r8r:Tr)rhashlibsha1updater'encode	hexdigestr)r=rTrAr@r?rn
splitlines	linecachecache)
rGrunique_filenameZ	type_hashlinesrescriptrDlocsbytecoderrrrs.	


	rcCst||_|S)z%
    Add a hash method to *cls*.
    )rr)rOrGrrr	_add_hashsrcCs$|j|}|tkrtS|S)z^
    Check equality and either forward a NotImplemented or return the result
    negated.
    )rNotImplemented)rrresultrrrrsrcsddDtj}|jtjdd|jf}dddg}r|jdd	g}x<D]4}|jd
|jf|jd|jfqW||dg7}n
|jd
dj|}i}i}t	||d}	t
|	||t|d|jd|ft
j|<|d}
t}fddfdd}fdd}
fdd}fdd}|
|||
||fS)NcSsg|]}|jr|qSr)r()rSrerrrrd!s	z_make_cmp.<locals>.<listcomp>zutf-8z<attrs generated eq %s>zdef __eq__(self, other):z-    if other.__class__ is not self.__class__:z        return NotImplementedz
    return  (z
    ) == (z        self.%s,z        other.%s,z    )z    return Truer8r:Trcs
t|S)z&
        Save us some typing.
        )r)r)rGrrattrs_to_tupleLsz!_make_cmp.<locals>.attrs_to_tuplecs0t||jr(||kStSdS)z1
        Automatically created by attrs.
        N)r[rr)rr)rrrrRsz_make_cmp.<locals>.__lt__cs0t||jr(||kStSdS)z1
        Automatically created by attrs.
        N)r[rr)rr)rrrr[sz_make_cmp.<locals>.__le__cs0t||jr(||kStSdS)z1
        Automatically created by attrs.
        N)r[rr)rr)rrrrdsz_make_cmp.<locals>.__gt__cs0t||jr(||kStSdS)z1
        Automatically created by attrs.
        N)r[rr)rr)rrrrmsz_make_cmp.<locals>.__ge__)rrrr'rrr=rTrAr@r?rnrrrr)rGrrrZothersrerrDrreqnerrrrr)rGrrr s@	
	

	
				rcCsI|dkr|j}t|\|_|_|_|_|_|_|S)z*
    Add comparison methods to *cls*.
    N)rgrrrrrrr)rOrGrrr_add_cmpys	0rcs2tdd|Dfdd}|S)zK
    Make a repr method for *attr_names* adding *ns* to the full name.
    css!|]}|jr|jVqdS)N)r'rT)rSrerrrrVsz_make_repr.<locals>.<genexpr>csj}dkrXt|dd}|dk	rL|jddd
}qi|j}nd|j}dj|djfdd	DS)z1
        Automatically created by attrs.
        Nr!z>.rraz{0}({1})z, c3s/|]%}|dtt|tVqdS)=N)r'rMr)rSrT)rrrrVsz/_make_repr.<locals>.__repr__.<locals>.<genexpr>rh)rrMrsplitrr;rA)rZreal_clsr
class_name)rBr)rrrs	z_make_repr.<locals>.__repr__)r)rGrrr)rBrrrs
	
rcCs+|dkr|j}t|||_|S)z%
    Add a repr method to *cls*.
    N)rgrr)rOrrGrrr	_add_reprs	rc
Csdd|D}tj}|jt|jddj|j}t|||\}}i}t||d}t	dd|D}	|jdt
d	|	i|d
krt|d<t|||t
|d|jd
|ftj|<|dS)
NcSs.g|]$}|js$|jtk	r|qSr)r*r%r)rSrerrrrds	z_make_init.<locals>.<listcomp>zutf-8z<attrs generated init {0}>r:css|]}|j|fVqdS)N)rT)rSrerrrrVsz_make_init.<locals>.<genexpr>r	attr_dictTZ_cached_setattrr)rrrr'rr;r_attrs_to_init_scriptr@rrrr?rnrrr)
rG	post_initrrrrrDrrrrrrrs0	


	rcCs(t|jt|dd||_|S)zR
    Add a __init__ method to *cls*.  If *frozen* is True, make it immutable.
    rF)rrgrMr)rOrrrr	_add_inits
rcCsRt|stdt|dd}|dkrNtdjd||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.
    zPassed object must be a class.rgNz({cls!r} is not an attrs-decorated class.rO)r	r.rMrr;)rOrGrrrfieldssrcCsbtjdkrdSxHt|jD]7}|j}|dk	r#|||t||jq#WdS)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_validatorsrrr&rMrT)instrerrrrvalidates	rcCsg}|dkr:|jddd}dd}ndd}dd}g}g}i}x|D]}	|	jr|j|	|	j}
|	jjd	}t|	jt}|r|	jjrd
}
nd}
|	jdkr|rt	j
|	j}|	jd
k	rP|j||
|dj
|
tj
|	j}|	j||<n#|j||
|dj
|
|	jj
||<q|	jd
k	r|j||
dj
d|
tj
|	j}|	j||<q|j||
dj
d|
qk|	jtk	r|r|jdj
d|d|
|	jd
k	rt|j||
||	j|tj
|	j<q|j||
|qk|r|jdj
d||jdj
d|t	j
|	j}|	jd
k	rP|jd||
||jd|jd||
|dj
|
|	j|tj
|	j<nN|jd||
||jd|jd||
|dj
|
|	jj
||<qk|j||	jd
k	r|j||
||	j|tj
|	j<qk|j||
|qkW|rt|d<|jdxh|D]`}	dj
|	j}dj
|	j}
|jdj
||
|	j|	j||<|	||
<q=W|r|jddj
ddj|d |rd!j|nd"|fS)#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__)cSsdd|d|iS)Nz(_setattr('%(attr_name)s', %(value_var)s)r7	value_varr)r7rrrr
fmt_setter)sz)_attrs_to_init_script.<locals>.fmt_settercSs)tj|}dd|d|d|iS)Nz2_setattr('%(attr_name)s', %(conv)s(%(value_var)s))r7rconv)_init_converter_patr;)r7r	conv_namerrrfmt_setter_with_converter/s
z8_attrs_to_init_script.<locals>.fmt_setter_with_convertercSsdd|d|iS)Nzself.%(attr_name)s = %(value)sr7rsr)r7rsrrrr7scSs)tj|}dd|d|d|iS)Nz,self.%(attr_name)s = %(conv)s(%(value_var)s)r7rr)rr;)r7rrrrrr=s
rrr9FNz({0})z attr_dict['{attr_name}'].defaultr7z+{arg_name}=attr_dict['{attr_name}'].defaultarg_namez{arg_name}=NOTHINGzif {arg_name} is not NOTHING:z    zelse:rz#if _config._run_validators is True:z__attr_validator_{}z	__attr_{}z    {}(self, {}, self.{})zself.__attrs_post_init__()z(def __init__(self, {args}):
    {lines}
argsz, rz
    pass)r=r&rTlstripr[r%Factory
takes_selfr*_init_factory_patr;r+rfactoryrrrA)rGrrrrrrZattrs_to_validateZnames_for_globalsrer7rZhas_factoryZ
maybe_selfZinit_factory_namerZval_namerrrrs	
	
						
			









	rc
@seZdZdZdZddddd
dZddZeddZe	dddZ
ddZddZdS)rbz
    *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`.
    rTr%r&r'r(r)r*r,r-r+Nc
Cstj|t}|dk	rR|dk	r6tdtjdtdd|}|d||d||d||d||d	||d
||d||d||d
|	rt|	nt|d|
dS)NzHCan't pass both `convert` and `converter`.  Please use `converter` only.z`The `convert` argument is deprecated in favor of `converter`.  It will be removed after 2019/01.r#r$rTr%r&r'r(r)r*r+r,r-)	rrrbr/r0r1r2r_empty_metadata_singleton)
rrTr%r&r'r(r)r*r4r,r-r+
bound_setattrrrrrs*	








zAttribute.__init__cCs
tdS)N)r)rrTrsrrrrszAttribute.__setattr__cCstjdtdd|jS)NzaThe `convert` attribute is deprecated in favor of `converter`.  It will be removed after 2019/01.r#r$)r0r1r2r+)rrrrr4s
zAttribute.convertc
sw|dkrj}njdk	r3tdfddtjD}|d|djdjd||S)Nz8Type annotation and type argument cannot both be presentcs.i|]$}|dkrt||qS)rTr&r%r-r4)rTr&r%r-r4)rM)rSr)rUrrrfs	z0Attribute.from_counting_attr.<locals>.<dictcomp>rTr&r%r-)r-rorbr
_validator_default)rOrTrUr-	inst_dictr)rUrrcs	
zAttribute.from_counting_attrcs tfddjDS)z(
        Play nice with pickle.
        c3s9|]/}|dkr$t|ntjVqdS)r,N)rMrr,)rSrT)rrrrVsz)Attribute.__getstate__.<locals>.<genexpr>)rr)rr)rrrszAttribute.__getstate__cCsttj|t}x[t|j|D]G\}}|dkrM|||q%|||ret|ntq%WdS)z(
        Play nice with pickle.
        r,N)rrrbrrrr)rrrrTrsrrrrszAttribute.__setstate__)
rTr%r&r'r(r)r*r,r-r+)
rr r!r"rrrpropertyr4rrcrrrrrrrbs	!	rbcCsUg|]K}|dkrtd|dtddddddd|d	kd
dqS)r4rTr%r&Nr'Tr(r)r,r*)rbr)rSrTrrrrd%s	rdcCsg|]}|jr|qSr)r))rSrerrrrd-s	c@seZdZdZdZedd
dDeddddddddddddddfZdZddZ	ddZ
ddZdS)r3a
    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.
    rXrr'r(r)r*r,rr+r-ccsB|]8}td|dtddddddddddVqdS)	rTr%r&Nr'Tr(r)r*)rbr)rSrTrrrrV<sz_CountingAttr.<genexpr>rTr%Nr&TFrc

Cstjd7_tj|_||_|rQt|ttfrQt||_n	||_||_	||_
||_||_||_
||_|	|_dS)Nr)r3cls_counterrXrr[listrand_rr'r(r)r*r+r,r-)
rr%r&r'r(r)r*r+r,r-rrrrFs								z_CountingAttr.__init__cCs4|jdkr||_nt|j||_|S)z
        Decorator that adds *meth* to the list of validators.

        Returns *meth* unchanged.

        .. versionadded:: 17.1.0
        N)rr)rrrrrr&Xsz_CountingAttr.validatorcCs1|jtk	rtt|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
        rT)rrr
r)rrrrrr%fs
	z_CountingAttr.default)
rXrr'r(r)r*r,rr+r-)rXrr'r(r)r*)rr r!r"rrrbrgrrr&r%rrrrr31s	
r3rr*r)c@s7eZdZdZeZeZdddZdS)ra
    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*
    FcCs||_||_dS)z
        `Factory` is part of the default machinery so if we want a default
        value here, we have to implement it ourselves.
        N)rr)rrrrrrrs	zFactory.__init__N)rr r!r"r5rrrrrrrr{s		rcKst|tr|}n=t|ttfrItdd|D}ntd|jdd}t|||dkrin	d|i}y%tjdj	j
dd|_Wntt
fk
rYnXtd	|||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*
    css|]}|tfVqdS)N)r5)rSrerrrrVszmake_class.<locals>.<genexpr>z(attrs argument must be a dict or a list.rNrr__main__rp)r[rrrr.popr-sys	_getframe	f_globalsr^r rrory)rTrGbasesZattributes_argumentsZcls_dictrZtype_rrr
make_classs 	!rc@s+eZdZdZeZddZdS)
_AndValidatorz2
    Compose many validators to a single one.
    cCs(x!|jD]}||||q
WdS)N)_validators)rrr\rsrrrr__call__sz_AndValidator.__call__N)rr r!r"r5rrrrrrrs	rcGsOg}x6|D].}|jt|tr1|jn|gq
Wtt|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
    )extendr[rrr)Z
validatorsvalsr&rrrrs
r)AZ
__future__rrrrrrr0operatorrr9rZ_compatrr	r
rr
exceptionsr
rrrobjectrrrrr>rrrr5rErFrKrRrrrtrurvrGryrrrrrrrrrrrrrrrbrZ_ar3rrrrrrrr<module>s|("		r
p	(Y
",j	
G%3
Back to Directory File Manager