U
    ôáêb©  ã                   @   sâ   d Z ddlmZmZmZ ddlmZ zddlmZm	Z	 W n$ e
k
r\   ddlmZm	Z	 Y nX ddlmZ ddlmZ d	d
„ ZG dd„ deƒZdd„ ddd„ fdd„Zdd„ ddd„ fdd„Zdd„ ddd„ fdd„Zdd„ ZdS )zCommon collection classes.é    )Úprint_functionÚdivisionÚabsolute_import)Úreduce)ÚMappingÚSeté   )Ú
isiterableé   )Ú
frozendictc                 C   sˆ   t | tƒr.t | tƒr| S tdd„ |  ¡ D ƒƒS t | tƒrXt | tƒrF| S tdd„ | D ƒƒS t| ƒr€t | tƒrn| S tdd„ | D ƒƒS | S d S )Nc                 s   s   | ]\}}|t |ƒfV  qd S ©N©Úmake_immutable©Ú.0ÚkÚv© r   ú6lib/python3.8/site-packages/conda/auxlib/collection.pyÚ	<genexpr>   s     z!make_immutable.<locals>.<genexpr>c                 s   s   | ]}t |ƒV  qd S r   r   ©r   r   r   r   r   r      s     c                 s   s   | ]}t |ƒV  qd S r   r   r   r   r   r   r      s     )Ú
isinstancer   r   Úitemsr   Ú	frozensetr	   Útuple)Úvaluer   r   r   r      s    




r   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚAttrDictz÷Sub-classes dict, and further allows attribute-like access to dictionary items.

    Examples:
        >>> d = AttrDict({'a': 1})
        >>> d.a, d['a'], d.get('a')
        (1, 1, 1)
        >>> d.b = 2
        >>> d.b, d['b']
        (2, 2)
    c                    s   t t| ƒj||Ž | | _d S r   )Úsuperr   Ú__init__Ú__dict__)ÚselfÚargsÚkwargs©Ú	__class__r   r   r   -   s    zAttrDict.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r#   r   r   "   s   
r   c                 C   s   t | ƒS r   ©Úbool©Úxr   r   r   Ú<lambda>2   ó    r.   Nc                 C   s   | S r   r   r,   r   r   r   r.   2   r/   c                    s(   t ‡ ‡fdd„| D ƒt|ƒr"|ƒ n|ƒS )aÛ  Give the first value that satisfies the key test.

    Args:
        seq (iterable):
        key (callable): test for each element of iterable
        default: returned when all elements fail test
        apply (callable): applied to element before return, but not to default value

    Returns: first element in seq that passes key, mutated with optional apply

    Examples:
        >>> first([0, False, None, [], (), 42])
        42
        >>> first([0, False, None, [], ()]) is None
        True
        >>> first([0, False, None, [], ()], default='ohai')
        'ohai'
        >>> import re
        >>> m = first(re.match(regex, 'abc') for regex in ['b.*', 'a(.*)'])
        >>> m.group(1)
        'bc'

        The optional `key` argument specifies a one-argument predicate function
        like that used for `filter()`.  The `key` argument, if supplied, must be
        in keyword form.  For example:
        >>> first([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0)
        4

    c                 3   s   | ]}ˆ|ƒrˆ |ƒV  qd S r   r   ©r   r-   ©ÚapplyÚkeyr   r   r   P   s      zfirst.<locals>.<genexpr>)ÚnextÚcallable©Úseqr3   Údefaultr2   r   r1   r   Úfirst2   s    r9   c                 C   s   t | ƒS r   r*   ©r   r   r   r   r   r.   S   r/   c                 C   s   | |fS r   r   r:   r   r   r   r.   S   r/   c                    s   t ‡ ‡fdd„| D ƒ|ƒS )Nc                 3   s&   | ]\}}ˆ||ƒrˆ ||ƒV  qd S r   r   r   r1   r   r   r   T   s     
 zfirstitem.<locals>.<genexpr>)r4   )Úmapr3   r8   r2   r   r1   r   Ú	firstitemS   s    r<   c                 C   s   t | ƒS r   r*   r,   r   r   r   r.   W   r/   c                 C   s   | S r   r   r,   r   r   r   r.   W   r/   c                    s   t ‡ ‡fdd„t| ƒD ƒ|ƒS )Nc                 3   s   | ]}ˆ|ƒrˆ |ƒV  qd S r   r   r0   r1   r   r   r   X   s      zlast.<locals>.<genexpr>)r4   Úreversedr6   r   r1   r   ÚlastW   s    r>   c              
   C   sH   zt dd„ | ƒ W n0 tk
rB } zt|ƒdkr2‚ W 5 d}~X Y nX dS )zjCalls each element of sequence to invoke the side effect.

    Args:
        seq:

    Returns: None

    c                 S   s   |ƒ S r   r   )Ú_Úyr   r   r   r.   e   r/   zcall_each.<locals>.<lambda>z0reduce() of empty sequence with no initial valueN)r   Ú	TypeErrorÚstr)r7   Úer   r   r   Ú	call_each[   s
    	rD   )r(   Z
__future__r   r   r   Ú	functoolsr   Zcollections.abcr   r   ÚImportErrorÚcollectionsÚcompatr	   Z_vendor.frozendictr   r   Údictr   r9   r<   r>   rD   r   r   r   r   Ú<module>   s   !