B
    x\\                 @   s   d dl Z e jd  dkZer(d dlmZ nd dlmZ yd dlmZ W n  ek
rd   d dl	mZ Y nX d
ddZ
G dd	 d	eZdS )    N   )MutableMapping)	get_ident...c                s    fdd}|S )zGDecorator to make a repr function return fillvalue for a recursive callc                s>   t    fdd}td|_td|_td|_|S )Nc          	      sB   t | t f}|kr S | z| }W d | X |S )N)idr   adddiscard)selfkeyresult)	fillvaluerepr_runninguser_function :lib/python3.7/site-packages/pandas/compat/chainmap_impl.pywrapper   s    
z<recursive_repr.<locals>.decorating_function.<locals>.wrapper
__module____doc____name__)setgetattrr   r   r   )r   r   )r   )r   r   r   decorating_function   s    z+recursive_repr.<locals>.decorating_functionr   )r   r   r   )r   r   recursive_repr   s    r   c               @   s   e Zd ZdZdd Zdd Zdd Zd'd	d
Zdd Zdd Z	dd Z
dd Ze dd Zedd Zdd ZeZd(ddZedd Zdd Zdd  Zd!d" Zd#d$ Zd%d& ZdS ))ChainMapa   A ChainMap groups multiple dicts (or other mappings) together
    to create a single, updatable view.

    The underlying mappings are stored in a list.  That list is public and can
    be accessed / updated using the *maps* attribute.  There is no other state.

    Lookups search the underlying mappings successively until a key is found.
    In contrast, writes, updates, and deletions only operate on the first
    mapping.

    c             G   s   t |pi g| _dS )zInitialize a ChainMap by setting *maps* to the given mappings.
        If no mappings are provided, a single empty dictionary is used.

        N)listmaps)r	   r   r   r   r   __init__7   s    zChainMap.__init__c             C   s   t |d S )N)KeyError)r	   r
   r   r   r   __missing__>   s    zChainMap.__missing__c          	   C   s8   x,| j D ]"}y|| S  tk
r(   Y qX qW | |S )N)r   r   r   )r	   r
   mappingr   r   r   __getitem__A   s    
zChainMap.__getitem__Nc             C   s   || kr| | S |S )Nr   )r	   r
   defaultr   r   r   getK   s    zChainMap.getc             C   s   t t j| j S )N)lenr   unionr   )r	   r   r   r   __len__N   s    zChainMap.__len__c             C   s   t t j| j S )N)iterr   r$   r   )r	   r   r   r   __iter__R   s    zChainMap.__iter__c                s   t  fdd| jD S )Nc             3   s   | ]} |kV  qd S )Nr   ).0m)r
   r   r   	<genexpr>V   s    z(ChainMap.__contains__.<locals>.<genexpr>)anyr   )r	   r
   r   )r
   r   __contains__U   s    zChainMap.__contains__c             C   s
   t | jS )N)r+   r   )r	   r   r   r   __bool__X   s    zChainMap.__bool__c             C   s   d | ddd | jD S )Nz{0.__class__.__name__}({1})z, c             s   s   | ]}t |V  qd S )N)repr)r(   r)   r   r   r   r*   ^   s    z$ChainMap.__repr__.<locals>.<genexpr>)formatjoinr   )r	   r   r   r   __repr__[   s    zChainMap.__repr__c             G   s   | t j|f| S )z?Create a ChainMap with a single dict created from the iterable.)dictfromkeys)clsiterableargsr   r   r   r3   `   s    zChainMap.fromkeysc             C   s$   | j | jd  f| jdd  S )zb
        New ChainMap or subclass with a new copy of maps[0] and refs to
        maps[1:]
        r      N)	__class__r   copy)r	   r   r   r   r9   e   s    zChainMap.copyc             C   s   |dkri }| j |f| j S )z
        New ChainMap with a new map followed by all previous maps. If no
        map is provided, an empty dict is used.
        N)r8   r   )r	   r)   r   r   r   	new_childn   s    zChainMap.new_childc             C   s   | j | jdd  S )zNew ChainMap from maps[1:].r7   N)r8   r   )r	   r   r   r   parentsw   s    zChainMap.parentsc             C   s   || j d |< d S )Nr   )r   )r	   r
   valuer   r   r   __setitem__|   s    zChainMap.__setitem__c             C   s8   y| j d |= W n" tk
r2   td|Y nX d S )Nr   z(Key not found in the first mapping: {!r})r   r   r/   )r	   r
   r   r   r   __delitem__   s
    zChainMap.__delitem__c             C   s0   y| j d  S  tk
r*   tdY nX dS )zj
        Remove and return an item pair from maps[0]. Raise KeyError is maps[0]
        is empty.
        r   z#No keys found in the first mapping.N)r   popitemr   )r	   r   r   r   r?      s    zChainMap.popitemc             G   s>   y| j d j|f| S  tk
r8   td|Y nX dS )zq
        Remove *key* from maps[0] and return its value. Raise KeyError if
        *key* not in maps[0].
        r   z(Key not found in the first mapping: {!r}N)r   popr   r/   )r	   r
   r6   r   r   r   r@      s
    zChainMap.popc             C   s   | j d   dS )z'Clear maps[0], leaving maps[1:] intact.r   N)r   clear)r	   r   r   r   rA      s    zChainMap.clear)N)N)r   r   __qualname__r   r   r   r    r"   r%   r'   r,   r-   r   r1   classmethodr3   r9   __copy__r:   propertyr;   r=   r>   r?   r@   rA   r   r   r   r   r   *   s(   


	
r   )r   )sysversion_infoZPY3Zcollections.abcr   collectionsZthreadr   ImportError_threadr   r   r   r   r   r   <module>   s   
