U #IGZ @sdddlmZmZmZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z mZmZmZmZddlmZmZmZmZejZdZd Zd ZeiZGd d d eZeZedd d dd ddddf ddZ ddZ!e!dddgZ"ddZ#ddZ$ddZ%ddZ&ddZ'Gdd d eZ(dRd"dZ)e)Z*e r:d#d$Z+nd%d$Z+d&d'Z,d(d)Z-d*d+Z.d,d-Z/d.d/Z0dSd0d1Z1d2d3Z2dTd4d5Z3d6d7Z4d8d9Z5d:d;Z6dd?Z8Gd@dAdAeZ9dBdCe9j:DZ;e.e1e3e9e;dDe;dDdEdCe;DdDZ9GdFdGdGeZe)d d dMGdNdOdOeZ?dPdQZ@dS)U)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 d Zd d Z dS)_Nothingz Sentinel class to indicate the lack of a value when ``None`` is ambiguous. All instances of `_Nothing` are equal. cCs|SNselfrr /_make.py__copy__ sz_Nothing.__copy__cCs|Srr)r_rrr __deepcopy__#sz_Nothing.__deepcopy__cCs |jtkSr) __class__rrotherrrr__eq__&sz_Nothing.__eq__cCs ||k Srrrrrr__ne__)sz_Nothing.__ne__cCsdS)NNOTHINGrrrrr__repr__,sz_Nothing.__repr__cCsdS)Nl>[=rrrrr__hash__/sz_Nothing.__hash__N) __name__ __module__ __qualname____doc__rrrrr r!rrrrrsrTc Csr|dk r |dk r |dk r td|dk rL| dk r8tdtjdtdd|} |dkrXi}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 `_). 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 validatorreprcmphashinit convertermetadatatype) TypeError RuntimeErrorwarningswarnDeprecationWarning _CountingAttr) r,r-r.r/r0r1convertr3r4r2rrrattrib9s8Rr<cCsvd|}d|dg}|rDt|D]\}}|tj||dq$n |ddti}ttd|dd |||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_templateir>globsrrr_make_attr_tuple_classs   rL _Attributesattrs super_attrscCst|dS)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_varsrRcCsHt|dd}|dkriS|jddD]}|t|ddkr&iSq&|S)z$ Get annotations for *cls*. __annotations__Nr)getattr__mro__)clsanns super_clsrrr_get_annotationss  rYc sL|jt||dk r6tddt|Dddd}n|dkrdd D}g}t}D]Z\}}t|rtqb|||t }t |t s|t krt }n t |d }| ||fqb||} t| d krtd d t| fddddntddDddd}fdd|D} g} dd| D} |jddD]R} t| dd}|dk rJ|D]0}| |j}|dkrh| ||| |j<qhqJdd| | D}t|j|}|| fdd|D}d}|D]`}|dkr|jt kr|jdkrtdj|dn&|dkr|jt k r|jdk rd}qt|| 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|]\}}||fVqdSrr).0namecarrr sz#_transform_attrs..cSs |djSNrcountererrrz"_transform_attrs..)keyTcSsh|]\}}t|tr|qSr isinstancer:rZr[attrrrr s z#_transform_attrs..)r,rz1The following `attr.ib`s lack a type annotation: , cs |jSr)getr`)n)cdrrrcrd.css$|]\}}t|tr||fVqdSrrfrhrrrr]s cSs |djSr^r_rarrrrc rdcs&g|]\}}tj|||dqS)r[r\r4 Attributefrom_counting_attrrlrZr>r\rWrr "s z$_transform_attrs..cSsi|] }|j|qSrr[rZarrr -sz$_transform_attrs..r__attrs_attrs__cSsg|] }|jqSrrwrxrrrrv;scs&g|]\}}tj|||dqSrprqrtrurrrv@s FzqNo mandatory attributes allowed after an attribute with a default value or factory. Attribute in question: {a!r})ry)__dict__rYsortedr itemssetrRaddrlrrgr:r<rDlenrrHrUrTr[rLr"r,r1 ValueErrorrBrM)rVthese auto_attribsZca_listZca_namesZ annot_namesr>r4ryZ unannotatedZ own_attrsrOZtaken_attr_namesrXZ sub_attrsZprev_arIZ AttrsClassrNZ had_defaultr)rWrnr_transform_attrss                " rcCs tdS)z4 Attached to frozen classes as __setattr__. Nrrr[valuerrr_frozen_setattrs[srcCs tdS)z4 Attached to frozen classes as __delattr__. Nr)rr[rrr_frozen_delattrsbsrc@steZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZdS) _ClassBuilderz( Iteratively build *one* class. )_cls _cls_dict_attrs _super_names _attr_names_slots_frozen_has_post_initcCst|||\}}||_|r$t|jni|_||_tdd|D|_tdd|D|_ ||_ |pht ||_ t t|dd|_|j|jd<|rt|jd<t|jd<dS) Ncss|] }|jVqdSrrwrxrrrr]xsz)_ClassBuilder.__init__..css|] }|jVqdSrrwrxrrrr]ys__attrs_post_init__Fr| __setattr__ __delattr__)rrdictr}rrrrtuplerr_has_frozen_superclassrboolrTrrr)rrVrslotsfrozenrrNrOrrr__init__rs  z_ClassBuilder.__init__cCsdj|jjdS)Nz<_ClassBuilder(cls={cls})>rV)rBrr"rrrrr sz_ClassBuilder.__repr__cCs|jdkr|S|SdS)z Finalize class based on the accumulated configuration. Builder cannot be used anymore after calling this method. TN)r_create_slots_class_patch_original_classrrrr build_classs z_ClassBuilder.build_classcCs^|j}|j}|jD]&}||krt||ddk rt||q|jD]\}}t|||qD|S)zA Apply accumulated methods and return the class. N)rrrrTdelattrrrsetattr)rrV super_namesr[rrrrrs  z#_ClassBuilder._patch_original_classc sjfddtjD}tfddjD|d<tjdd}|dk rX||d<tjfdd }fd d }||d <||d <tjjjjj |}|j D]T}t |t tfrt|jdd}n t|dd}|sq|D]}|jjkrt||qq|S)zL Build and return a new class with a `__slots__` attribute. cs(i|] \}}|tjdkr||qS))r})rr)rZkvrrrrzsz5_ClassBuilder._create_slots_class..c3s|]}|kr|VqdSrrrZr[)rrrr]sz4_ClassBuilder._create_slots_class.. __slots__r$NcstfddDS)9 Automatically created by attrs. c3s|]}t|VqdSrrTrrrrr]szL_ClassBuilder._create_slots_class..slots_getstate..rrrIrrslots_getstatesz9_ClassBuilder._create_slots_class..slots_getstatecs.t|t}t|D]\}}|||qdS)rN) _obj_setattr__get__rrzip)rstateZ_ClassBuilder__bound_setattrr[rrrrslots_setstates z9_ClassBuilder._create_slots_class..slots_setstate __getstate__ __setstate__ __closure__)rr rrrrTrr4r" __bases__r}valuesrg classmethod staticmethod__func__ cell_contentsr ) rrnqualnamerrrVitemZ closure_cellsZcellr)rIrrrrs<         z!_ClassBuilder._create_slots_classcCs|t|j|d|jd<|S)N)nsr )_add_method_dunders _make_reprrr)rrrrradd_reprs z_ClassBuilder.add_reprcCs8|jd}|dkrtddd}|||jd<|S)Nr z3__str__ can only be generated if a __repr__ exists.cSs|Sr)r rrrr__str__sz&_ClassBuilder.add_str..__str__r)rrlrr)rr.rrrradd_strs z_ClassBuilder.add_strcCsd|jd<|SNr!)rrrrrmake_unhashables z_ClassBuilder.make_unhashablecCs|t|j|jd<|Sr)r _make_hashrrrrrradd_hashs z_ClassBuilder.add_hashcCs"|t|j|j|j|jd<|S)Nr)r _make_initrrrrrrrradd_init s z_ClassBuilder.add_initcsFj}fddtjD\|d<|d<|d<|d<|d<|d<S) Nc3s|]}|VqdSr)r)rZmethrrrr]sz(_ClassBuilder.add_cmp..rr__lt____le____gt____ge__)r _make_cmpr)rrnrrradd_cmps  z_ClassBuilder.add_cmpcCsXz|jj|_Wntk r"YnXzd|jj|jf|_Wntk rRYnX|S)zL Add __module__ and __qualname__ to a *method* if possible. ro)rr#AttributeErrorrHr$r")rmethodrrrr!s z!_ClassBuilder._add_method_dundersN)r"r#r$r%rrr rrrrrrrrrrrrrrris H   rFc s6 f dd} |dkr*| S| |SdS)aU A class decorator that adds `dunder `_\ -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 \ `_ and the `GitHub issue that led to the default behavior \ `_ 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 ` 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* cst|dddkrtdt| }dkr:|dkrJ|dkrZ|dk r|dk r|dk r|tdnLdksȈdkrdkrn2dksdkrdkrdkr|n|dkr|| S)Nrz(attrs only works with new-style classes.TFr&) rTr5rrrrrrrr)rVZbuilder rr/rr0r1r.repr_nsrrPrrrwraps*   zattrs..wrapNr) Z maybe_clsrrr.r/r0r1rrrPrrrrrrN4sg cCs"t|jddtjko |jjtjkS)b Check whether *cls* has a frozen ancestor by looking at its __setattr__. r#N)rTrrr#r"rrrrrs rcCs |jtkS)r)rrrrrrrscstfdd|DS)z: Create a tuple of all values of *obj*'s *attrs*. c3s|]}t|jVqdSr)rTr[rxobjrrr]sz"_attrs_to_tuple..r)rrNrrr_attrs_to_tuplesrc Cstdd|D}t}|t|dd|f}t|}ddd|fg}|D]}|d|j qX|d d |}i}i}t ||d } t | ||t |d|d |ftj|<|d S)Ncss0|](}|jdks$|jdkr|jdkr|VqdS)TN)r0r/rxrrrr]s  z_make_hash..utf-8zzdef __hash__(self):z return hash((z %d, self.%s,z ))r?rATr!)rhashlibsha1updater.encode hexdigestr0rDr[rHrGrFr splitlines linecachecache) rNrunique_filenameZ type_hashlinesryscriptrKlocsbytecoderrrrs2     rcCst||_|S)z% Add a hash method to *cls*. )rr!rVrNrrr _add_hash s rcCs||}|tkrtS| S)z^ Check equality and either forward a NotImplemented or return the result negated. )rNotImplemented)rrresultrrrrs rcs<ddDt}|tdd|f}dddg}r|dd g}D](}|d |jf|d |jfqZ||d g7}n |d d|}i}i}t ||d} t | ||t |d| d|ft j|<|d} t} fddfdd} fdd} fdd}fdd}| | | | ||fS)NcSsg|]}|jr|qSr)r/rxrrrrv!sz_make_cmp..rzzdef __eq__(self, other):z- if other.__class__ is not self.__class__:z return NotImplementedz return (z ) == (rz other.%s,z )z return Truer?rATrcs t|S)z& Save us some typing. )rrrNrrattrs_to_tupleLsz!_make_cmp..attrs_to_tuplecs$t||jr||kStSdS1 Automatically created by attrs. NrgrrrrrrrRs z_make_cmp..__lt__cs$t||jr||kStSdSrrrrrrr[s z_make_cmp..__le__cs$t||jr||kStSdSrrrrrrrds z_make_cmp..__gt__cs$t||jr||kStSdSrrrrrrrms z_make_cmp..__ge__)rrrr.rrrDr[rHrGrFrrrrr)rNrrrZothersryrrKrreqnerrrrr)rNrrr sF        rcCs2|dkr|j}t|\|_|_|_|_|_|_|S)z* Add comparison methods to *cls*. N)r|rrrrrrrrrrr_add_cmpys rcs$tdd|Dfdd}|S)zK Make a repr method for *attr_names* adding *ns* to the full name. css|]}|jr|jVqdSr)r.r[rxrrrr]sz_make_repr..csjj}dkr.rr{roz{0}({1})rkc3s&|]}|dtt|tVqdS)=N)r.rTrrrrrr]sz/_make_repr..__repr__..)rrTrsplitr"rBrH)rZreal_clsr class_namerIrrrr s z_make_repr..__repr__r)rNrr rrrrs rcCs|dkr|j}t|||_|S)z% Add a repr method to *cls*. N)r|rr )rVrrNrrr _add_reprs rc Csdd|D}t}|t|dd|}t|||\}}i}t||d}t dd|D} |t | d|d krt |d <t |||t |d|d |ftj|<|d S) NcSs g|]}|js|jtk r|qSr)r1r,rrxrrrrvs z_make_init..rzrAcss|]}|j|fVqdSrrwrxrrrr]sz_make_init..)r attr_dictTZ_cached_setattrr)rrrr.rrBr_attrs_to_init_scriptrGrrrrFrrrr) rN post_initrrrrrKrrrrrrrs:   rcCst|jt|dd||_|S)zR Add a __init__ method to *cls*. If *frozen* is True, make it immutable. rF)rr|rTr)rVrrrr _add_inits  rcCs8t|stdt|dd}|dkr4tdj|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. zPassed object must be a class.r|Nz({cls!r} is not an attrs-decorated class.r)r r5rTrrBrrrrfieldss  rcCsDtjdkrdSt|jD]&}|j}|dk r|||t||jqdS)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-rTr[)instryrrrrvalidates  rc Csg}|dkr(|ddd}dd}ndd}dd}g}g}i}|D]} | jr^|| | j} | jd } t| jt} | r| jjrd } nd } | jd krj| rt | j}| j d k r||| |d | t | j}| j ||<n||| |d | | jj ||<nT| j d k rP||| dj | dt | j}| j ||<n||| dj | dqH| jtk r| s|dj | | d| j d k r||| | | j |t | j<n||| | qH| r|dj | d|dj | dt | j}| j d k rd|d|| | |d|d|| |d | | j |t | j<n<|d|| | |d|d|| |d | | jj ||<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|ddj d||rd |nd!d"|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__)cSsd||dS)Nz(_setattr('%(attr_name)s', %(value_var)s)r> value_varrrrrr fmt_setter)sz)_attrs_to_init_script..fmt_settercSst|}d|||dS)Nz2_setattr('%(attr_name)s', %(conv)s(%(value_var)s))r>rZconv_init_converter_patrBr>r conv_namerrrfmt_setter_with_converter/s  z8_attrs_to_init_script..fmt_setter_with_convertercSsd||dS)Nzself.%(attr_name)s = %(value)sr>rrr rrrr7scSst|}d|||dS)Nz,self.%(attr_name)s = %(conv)s(%(value_var)s)rrr rrrr =s  rrr@FNz({0})z attr_dict['{attr_name}'].default)r>z+{arg_name}=attr_dict['{attr_name}'].default)arg_namer>z{arg_name}=NOTHING)r zif {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} rkz pass)argsr)rDr-r[lstriprgr,Factory takes_selfr1_init_factory_patrBr2rfactoryrrrH)rNrrrrr rZattrs_to_validateZnames_for_globalsryr>r Z has_factoryZ maybe_selfZinit_factory_namer Zval_namerrrrs                                rc@sPeZdZdZdZdddZddZedd Ze dd d Z d d Z ddZ dS)rrz *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/r0r1r3r4r2Nc Cst|t} |dk r8| dk r$tdtjdtdd|} | d|| d|| d|| d|| d || d || d || d | | d | rt| nt| d| dS)Nr'r(r)r*r[r,r-r.r/r0r1r2r3r4) rrrrr6r7r8r9r _empty_metadata_singleton) rr[r,r-r.r/r0r1r;r3r4r2 bound_setattrrrrrs2          zAttribute.__init__cCs tdSrrrrrrrszAttribute.__setattr__cCstjdtdd|jS)NzaThe `convert` attribute is deprecated in favor of `converter`. It will be removed after 2019/01.r)r*)r7r8r9r2rrrrr;s zAttribute.convertcsR|dkrj}njdk r"tdfddtjD}|f|jj|d|S)Nz8Type annotation and type argument cannot both be presentcs i|]}|dkr|t|qS))r[r-r,r4r;r)rZrr\rrrzsz0Attribute.from_counting_attr..)r[r-r,r4)r4rrrr _validator_default)rVr[r\r4Z inst_dictrrrrss"  zAttribute.from_counting_attrcstfddjDS)( Play nice with pickle. c3s*|]"}|dkrt|ntjVqdS)r3N)rTrr3rrrrr]sz)Attribute.__getstate__..)rrrrrrrs zAttribute.__getstate__cCsPt|t}t|j|D]2\}}|dkr4|||q|||rDt|ntqdS)rr3N)rrrrrrr r)rrrr[rrrrrs  zAttribute.__setstate__)NNNN)N) r"r#r$r%rrrpropertyr;rrsrrrrrrrrs  "  rrc Cs.g|]&}|dkrt|tddd|dkddqS)r;NTr3r[r,r-r.r/r0r1rrrrrrrrv$srvrcCsg|]}|jr|qSr)r0rxrrrrv-sc @sZeZdZdZdZedddDedddddd dd fZd Zd d Z ddZ ddZ dS)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`rr.r/r0r1r3rr2r4c cs$|]}t|tddddddVqdS)NTrrrrrrr];sz_CountingAttr.)r`rr.r/r0r1r3NTFrrc Csntjd7_tj|_||_|r:t|ttfr:t||_n||_||_ ||_ ||_ ||_ ||_ ||_| |_dSr^)r: cls_counterr`rrglistrand_rr.r/r0r1r2r3r4) rr,r-r.r/r0r1r2r3r4rrrrFs z_CountingAttr.__init__cCs$|jdkr||_nt|j||_|S)z Decorator that adds *meth* to the list of validators. Returns *meth* unchanged. .. versionadded:: 17.1.0 N)rr rrrrrr-Xs z_CountingAttr.validatorcCs"|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 T)r)rrr rr!rrrr,fs z_CountingAttr.default) r"r#r$r%rrrrr|rrr-r,rrrrr:1s" r:)rr1r0c@s&eZdZdZeZeZdddZdS)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)rrrrrrrszFactory.__init__N)F)r"r#r$r%r<rrrrrrrr{s rc Kst|tr|}n*t|ttfr2tdd|D}ntd|dd}t|||dkrXind|i}ztdj dd|_ Wnt t fk rYnXtfd |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* css|]}|tfVqdSr)r<rxrrrr]szmake_class..z(attrs argument must be a dict or a list.rNrr"__main__r)rgrrrr5popr4sys _getframe f_globalsrlr#rrr)r[rNbasesZattributes_argumentsZcls_dictrZtype_rrr make_classs&     r()rr0c@seZdZdZeZddZdS) _AndValidatorz2 Compose many validators to a single one. cCs|jD]}||||qdSr) _validators)rrrirrrrr__call__s z_AndValidator.__call__N)r"r#r$r%r<r*r+rrrrr)sr)cGs6g}|D] }|t|tr |jn|gqtt|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 )extendrgr)r*r)Z validatorsZvalsr-rrrr s r ) NNNTTNTFFFF)N)NN)AZ __future__rrrrrr$r7operatorrr@rZ_compatrr r r r exceptionsr rrrobjectrrrrrErrrr<rLrMrRrYrrrrrNrrrrrrrrrrrrrrrrrrZ_ar:rr(r)r rrrrs   t pL  ( Y " , $i G  3