B
    ؓ(Sl                 @   sV  d dl mZ d dl mZ d dl mZ d dl mZ d dlmZ d dlmZ d dl	Z	yd dlm
Z
 W n  ek
r   d dl
m
Z
 Y nX yd d	lmZ W n  ek
r   d d	lmZ Y nX yd d
lmZ W nJ ek
r   yd d
lmZ W n" ek
r   d d
lmZ Y nX Y nX dddZG dd deZG dd de
Zdd ZG dd deZdS )    )absolute_import)division)print_function)unicode_literals)ABCMeta)MutableMappingN)UserDict)OrderedDict)	get_ident...c                s    fdd}|S )zGDecorator to make a repr function return fillvalue for a recursive callc                sL   t    fdd}td|_td|_td|_tdi |_|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 5lib/python3.7/site-packages/singledispatch_helpers.pywrapper#   s    
z<recursive_repr.<locals>.decorating_function.<locals>.wrapper
__module____doc____name____annotations__)setgetattrr   r   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
e dd Zedd Zdd ZeZ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, updateable view.

    The underlying mappings are stored in a list.  That list is public and can
    accessed or 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__E   s    zChainMap.__init__c             C   s   t |d S )N)KeyError)r   r   r   r   r   __missing__L   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__O   s    
zChainMap.__getitem__Nc             C   s   || kr| | S |S )Nr   )r   r   defaultr   r   r   getW   s    zChainMap.getc             C   s   t t j| j S )N)lenr   unionr"   )r   r   r   r   __len__Z   s    zChainMap.__len__c             C   s   t t j| j S )N)iterr   r+   r"   )r   r   r   r   __iter__]   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>a   s    z(ChainMap.__contains__.<locals>.<genexpr>)anyr"   )r   r   r   )r   r   __contains__`   s    zChainMap.__contains__c             C   s   d | dtt| jS )Nz{0.__class__.__name__}({1})z, )formatjoinmapreprr"   )r   r   r   r   __repr__c   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   r:   h   s    zChainMap.fromkeysc             C   s$   | j | jd  f| jdd  S )zHNew ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]r      N)	__class__r"   copy)r   r   r   r   r@   m   s    zChainMap.copyc             C   s   | j i f| j S )z;New ChainMap with a new dict followed by all previous maps.)r?   r"   )r   r   r   r   	new_childs   s    zChainMap.new_childc             C   s   | j | jdd  S )zNew ChainMap from maps[1:].r>   N)r?   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$   r4   )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 )zPRemove 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   rF      s    zChainMap.popitemc             G   s>   y| j d j|f| S  tk
r8   td|Y nX dS )zWRemove *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$   r4   )r   r   r=   r   r   r   rG      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   rH      s    zChainMap.clear)N)r   r   __qualname__r   r#   r%   r'   r)   r,   r.   r3   r   r8   classmethodr:   r@   __copy__rA   propertyrB   rD   rE   rF   rG   rH   r   r   r   r   r    8   s&   
r    c               @   s   e Zd Zdd ZdS )MappingProxyTypec             C   s   t |  || _d S )N)r   r#   data)r   rN   r   r   r   r#      s    
zMappingProxyType.__init__N)r   r   rI   r#   r   r   r   r   rM      s   rM   c               C   s   t jS )N)r   Z_abc_invalidation_counterr   r   r   r   get_cache_token   s    rO   c               @   s   e Zd Zdd Zdd ZdS )Supportc             C   s   d S )Nr   )r   r   r   r   dummy   s    zSupport.dummyc             C   s   dt jkr| jS |S )NZPyPy)sysversionrQ   )r   funcr   r   r   cpython_only   s    
zSupport.cpython_onlyN)r   r   rI   rQ   rU   r   r   r   r   rP      s   rP   )r   )Z
__future__r   r   r   r   abcr   collectionsr   rR   r   ImportErrorr	   ZordereddictZthreadr
   _threadZ_dummy_threadr   r    rM   rO   objectrP   r   r   r   r   <module>   s4   
`