Your IP : 3.145.168.68


Current Path : /opt/alt/python37/lib/python3.7/site-packages/attr/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/attr/__pycache__/_funcs.cpython-37.pyc

B

���`V4�@s�ddlmZmZmZddlZddlmZddlmZm	Z	m
Z
ddlmZdde
ddfd	d
�Zdd�Zddedfd
d�Zdd�Zdd�Zdd�Zddd�ZdS)�)�absolute_import�division�print_functionN�)�	iteritems)�NOTHING�_obj_setattr�fields)�AttrsAttributeNotFoundErrorTFcst|j�}��}�x|D]�}t||j�}	�dk	r<�||	�s<q�dk	rP�|||	�}	|dk�rt|	j�r~t|	d�����||j<n�t|	ttt	t
f�rƈdkr�|	jnt}
|
����fdd�|	D��||j<n@t|	t�r��������fdd�t|	�D��||j<n
|	||j<q|	||j<qW|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 determines whether an
        attribute or element is included (``True``) or dropped (``False``).  Is
        called with the `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``.
    :param Optional[callable] value_serializer: A hook that is called for every
        attribute or dict key/value.  It receives the current instance, field
        and value and must return the (updated) value.  The hook is run *after*
        the optional *filter* has been applied.

    :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*
    ..  versionadded:: 20.3.0 *value_serializer*
    NTcsg|]}t|������qS�)�_asdict_anything)�.0�i)�dict_factory�filter�retain_collection_types�value_serializerr�</opt/alt/python37/lib/python3.7/site-packages/attr/_funcs.py�
<listcomp>Jszasdict.<locals>.<listcomp>c3s2|]*\}}t|�����t|�����fVqdS)N)r)r
�kk�vv)�dfrrrrr�	<genexpr>Wszasdict.<locals>.<genexpr>)
r	�	__class__�getattr�name�has�asdict�
isinstance�tuple�list�set�	frozenset�dictr)�inst�recurserrrr�attrs�rv�a�v�cfr)rrrrrrr
s<(



rcs�t|jdd�dk	r&t|d�����}n�t|ttttf�rh�dkrF|jnt}|����fdd�|D��}nHt|t�r��������fdd�t	|�D��}n|}�dk	r��dd|�}|S)zK
    ``asdict`` only works on attrs instances, this works on anything.
    �__attrs_attrs__NTcsg|]}t|������qSr)r)r
r)rrrrrrr�sz$_asdict_anything.<locals>.<listcomp>c3s2|]*\}}t|�����t|�����fVqdS)N)r)r
rr)rrrrrrr�sz#_asdict_anything.<locals>.<genexpr>)
rrrrrr r!r"r#r)�valrrrrr'r*r)rrrrrrrps,

rc
st|j�}g}|�x�|D]�}t||j�}�dk	r<�||�s<q|dkr�t|j�rh|�t|d���d��n�t|tt	t
tf�r��dkr�|jnt	}	|�|	���fdd�|D���nJt|t�r�dkr�|jnt}
|�|
��fdd�t
|�D���n
|�|�q|�|�qW�t	k�r|S�|�S)a1
    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 `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
    NT)r%r�
tuple_factoryrc	s,g|]$}t|j�r$t|d���d�n|�qS)T)r%rr-r)rr�astuple)r
�j)r�retainr-rrr�s	zastuple.<locals>.<listcomp>c3sJ|]B\}}t|j�r"t|��d�n|t|j�r<t|��d�n|fVqdS))r-rN)rrr.)r
rr)r0r-rrr�szastuple.<locals>.<genexpr>)r	rrrr�appendr.rrr r!r"r#r)r$r%rr-rr&r'r(r)r*rr)rr0r-rr.�s>!


	
r.cCst|dd�dk	S)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: bool
    r+N)r)�clsrrrrs	rcKszddl}|jdtdd�t�|�}t|j�}xHt|�D]<\}}t||t�}|tkrft	dj
||jd���t|||�q6W|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 `evolve` instead.
    rNz6assoc is deprecated and will be removed after 2018/01.�)�
stacklevelz&{k} is not an attrs attribute on {cl}.)�kZcl)�warnings�warn�DeprecationWarning�copyr	rrrrr
�formatr)r$�changesr6�newr&r5r)r(rrr�assocs

r=cKsf|j}t|�}xL|D]D}|js q|j}|ddkr6|n
|dd�}||krt||�||<qW|f|�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�_rN)rr	�initrr)r$r;r2r&r(�	attr_nameZ	init_namerrr�evolve=s
rAc	Cs|y
|jWnltk
rvddl}|j|||d�}x8|dkrDt|�n|D] }|j|krHt|d||j�qHWd|_YnX|S)a	
    Resolve any strings and forward annotations in type annotations.

    This is only required if you need concrete types in `Attribute`'s *type*
    field. In other words, you don't need to resolve your types if you only
    use them for static type checking.

    With no arguments, names will be looked up in the module in which the class
    was created. If this is not what you want, e.g. if the name only exists
    inside a method, you may pass *globalns* or *localns* to specify other
    dictionaries in which to look up these names. See the docs of
    `typing.get_type_hints` for more details.

    :param type cls: Class to resolve.
    :param Optional[dict] globalns: Dictionary containing global variables.
    :param Optional[dict] localns: Dictionary containing local variables.
    :param Optional[list] attribs: List of attribs for the given class.
        This is necessary when calling from inside a ``field_transformer``
        since *cls* is not an ``attrs`` class yet.

    :raise TypeError: If *cls* is not a class.
    :raise attr.exceptions.NotAnAttrsClassError: If *cls* is not an ``attrs``
        class and you didn't pass any attribs.
    :raise NameError: If types cannot be resolved because of missing variables.

    :returns: *cls* so you can use this function also as a class decorator.
        Please note that you have to apply it **after** `attr.s`. That means
        the decorator has to come in the line **before** `attr.s`.

    ..  versionadded:: 20.1.0
    ..  versionadded:: 21.1.0 *attribs*

    rN)�globalns�localns�typeT)Z__attrs_types_resolved__�AttributeError�typing�get_type_hintsr	rr)r2rBrCZattribsrF�hints�fieldrrr�
resolve_typesZs"

rJ)NNN)�
__future__rrrr9�_compatr�_makerrr	�
exceptionsr
r#rrrr.rr=rArJrrrr�<module>s$`9_&

?>