o
    .d                     @   s\   d 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 G dd dee	e
f Zd	S )
zA read-only chain map.

Based on "A greatly simplified read-only version of Chainmap" by Raymond Hettinger.
https://code.activestate.com/recipes/305268/
    )deque)chain)Any)Iterator)Mappingc                   @   s   e Zd ZdZdeeef fddZdedefddZde	e fd	d
Z
defddZdefddZddededefddZdeeef ddfddZdeeef fddZdS )ReadOnlyChainMapz0Combine multiple mappings for sequential lookup.mapsc                 G   s   t || _d S N)r   _maps)selfr    r   H/var/www/Matress/matenv/lib/python3.10/site-packages/liquid/chain_map.py__init__   s   zReadOnlyChainMap.__init__keyreturnc              	   C   s4   | j D ]}z|| W   S  ty   Y qw t|r	   )r
   KeyError)r   r   mappingr   r   r   __getitem__   s   
zReadOnlyChainMap.__getitem__c                 C   s
   t | j S r	   )r   r
   r   r   r   r   __iter__   s   
zReadOnlyChainMap.__iter__c                 C   s   t dd | jD S )Nc                 s   s    | ]}t |V  qd S r	   )len).0_mapr   r   r   	<genexpr>   s    z+ReadOnlyChainMap.__len__.<locals>.<genexpr>)sumr
   r   r   r   r   __len__   s   zReadOnlyChainMap.__len__c                 C   s
   t | jS )z'Return the number of maps in the chain.)r   r
   r   r   r   r   size!      
zReadOnlyChainMap.sizeNdefaultc                 C   s"   z| | W S  t y   | Y S w )zCReturn the value for key if key is in the dictionary, else default.)r   )r   r   r   r   r   r   get%   s
   
zReadOnlyChainMap.get	namespacec                 C   s   | j | dS )z,Add a mapping to the front of the chain map.N)r
   
appendleft)r   r    r   r   r   push,   s   zReadOnlyChainMap.pushc                 C   s
   | j  S )z1Remove a mapping from the front of the chain map.)r
   popleftr   r   r   r   pop0   r   zReadOnlyChainMap.popr	   )__name__
__module____qualname____doc__r   strobjectr   r   r   r   intr   r   r   r   r"   r$   r   r   r   r   r      s    r   N)r(   collectionsr   	itertoolsr   typingr   r   r   r)   r*   r   r   r   r   r   <module>   s    