o ]Lb@sddlmZmZmZddlZddlmZddlmZm Z m Z ddl m Z dde dfd d Zddedfd d Zd dZddZddZdS))absolute_importdivisionprint_functionN) iteritems)NOTHINGfields _obj_setattr)AttrsAttributeNotFoundErrorTFc st|j}}|D]k}t||j}dur||sq |durpt|jr1t|dd||j<q t|ttt frR|dur@|jnt} | fdd|D||j<q t|t rjfddt |D||j<q |||j<q |||j<q |S)a Return the ``attrs`` attribute values of *inst* as a dict. Optionally recurse into other ``attrs``-decorated classes. :param inst: Instance of an ``attrs``-decorated class. :param bool recurse: Recurse into classes that are also ``attrs``-decorated. :param callable filter: A callable whose return code deteremines whether an attribute or element is included (``True``) or dropped (``False``). Is called with the :class:`attr.Attribute` as the first argument and the value as the second argument. :param callable dict_factory: A callable to produce dictionaries from. For example, to produce ordered dictionaries instead of normal Python dictionaries, pass in ``collections.OrderedDict``. :param bool retain_collection_types: Do not convert to ``list`` when encountering an attribute whose type is ``tuple`` or ``set``. Only meaningful if ``recurse`` is ``True``. :rtype: return type of *dict_factory* :raise attr.exceptions.NotAnAttrsClassError: If *cls* is not an ``attrs`` class. .. versionadded:: 16.0.0 *dict_factory* .. versionadded:: 16.1.0 *retain_collection_types* NTrecursefilter dict_factorycs*g|]}t|jrt|ddn|qS)Tr has __class__asdict).0i)rr B/usr/lib/python3/dist-packages/mercurial/thirdparty/attr/_funcs.py 3s zasdict..c3sH|]\}}t|jrt|dn|t|jrt|dn|fVqdS))rNrrkkvv)dfrr ;s  zasdict..) rrgetattrnamerr isinstancetuplelistsetdictr) instr r rretain_collection_typesattrsrvavcfr)rrr rr s0       rc st|j}g}||D]u}t||j}dur||sq |dur{t|jr3|t|ddq t|tt t frUdurB|jnt } || fdd|Dq t|t rudura|jnt } || fddt |Dq ||q ||q t ur|S|S)a8 Return the ``attrs`` attribute values of *inst* as a tuple. Optionally recurse into other ``attrs``-decorated classes. :param inst: Instance of an ``attrs``-decorated class. :param bool recurse: Recurse into classes that are also ``attrs``-decorated. :param callable filter: A callable whose return code determines whether an attribute or element is included (``True``) or dropped (``False``). Is called with the :class:`attr.Attribute` as the first argument and the value as the second argument. :param callable tuple_factory: A callable to produce tuples from. For example, to produce lists instead of tuples. :param bool retain_collection_types: Do not convert to ``list`` or ``dict`` when encountering an attribute which type is ``tuple``, ``dict`` or ``set``. Only meaningful if ``recurse`` is ``True``. :rtype: return type of *tuple_factory* :raise attr.exceptions.NotAnAttrsClassError: If *cls* is not an ``attrs`` class. .. versionadded:: 16.2.0 NTr r tuple_factoryr%c s,g|]}t|jrt|ddn|qS)Tr+rrastuple)rjr retainr,rrrps zastuple..c3sL|]!\}}t|jrt|dn|t|jrt|dn|fVqdS))r,r%Nr-r)r1r,rrrys&  zastuple..) rrrrrappendr.rr r!r"r#r) r$r r r,r%r&r'r(r)r*rrr0rr.Fs4        r.cCst|ddduS)z Check whether *cls* is a class with ``attrs`` attributes. :param type cls: Class to introspect. :raise TypeError: If *cls* is not a class. :rtype: :class:`bool` __attrs_attrs__N)r)clsrrrrs rcKsrddl}|dtt|}t|j}t|D]\}}t||t}|tur0t dj ||jdt |||q|S)a Copy *inst* and apply *changes*. :param inst: Instance of a class with ``attrs`` attributes. :param changes: Keyword changes in the new copy. :return: A copy of inst with *changes* incorporated. :raise attr.exceptions.AttrsAttributeNotFoundError: If *attr_name* couldn't be found on *cls*. :raise attr.exceptions.NotAnAttrsClassError: If *cls* is not an ``attrs`` class. .. deprecated:: 17.1.0 Use :func:`evolve` instead. rNz6assoc is deprecated and will be removed after 2018/01.z&{k} is not an attrs attribute on {cl}.)kcl) warningswarnDeprecationWarningcopyrrrrrr formatr )r$changesr7newr&r5r)r(rrrassocs    r>cKsf|j}t|}|D]"}|jsq |j}|ddkr|n|dd}||vr+t||||<q |di|S)a Create a new instance, based on *inst* with *changes* applied. :param inst: Instance of a class with ``attrs`` attributes. :param changes: Keyword changes in the new copy. :return: A copy of inst with *changes* incorporated. :raise TypeError: If *attr_name* couldn't be found in the class ``__init__``. :raise attr.exceptions.NotAnAttrsClassError: If *cls* is not an ``attrs`` class. .. versionadded:: 17.1.0 r_rNr)rrinitrr)r$r<r4r&r( attr_name init_namerrrevolvesrC) __future__rrrr:_compatr_makerrr exceptionsr r#rr r.rr>rCrrrrs   < H !