B
    u9aO!  ã               @   s†   d dl mZmZ d dlmZ d dlZddddgZG dd	„ d	ejj	ƒZ
G d
d„ dejj	ƒZG dd„ deƒZG dd„ deƒZddd„ZdS )é    )ÚPicklerÚ	Unpickler)ÚBytesIONÚShelfÚ
BsdDbShelfÚDbfilenameShelfÚopenc               @   s4   e Zd Zdd„ Ze Z Z Z Z ZZ	dd„ Z
dS )Ú_ClosedDictc             G   s   t dƒ‚d S )Nz!invalid operation on closed shelf)Ú
ValueError)ÚselfÚargs© r   ú/usr/lib/python3.7/shelve.pyÚclosedE   s    z_ClosedDict.closedc             C   s   dS )Nz<Closed Dictionary>r   )r   r   r   r   Ú__repr__I   s    z_ClosedDict.__repr__N)Ú__name__Ú
__module__Ú__qualname__r   Ú__iter__Ú__len__Ú__getitem__Ú__setitem__Ú__delitem__Úkeysr   r   r   r   r   r	   B   s   r	   c               @   sx   e Zd Zdd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dd„ Zdd„ Zdd„ Zdd„ ZdS ) r   NFúutf-8c             C   s.   || _ |d krd}|| _|| _i | _|| _d S )Né   )ÚdictÚ	_protocolÚ	writebackÚcacheÚkeyencoding)r   r   Úprotocolr   r    r   r   r   Ú__init__T   s    zShelf.__init__c             c   s&   x | j  ¡ D ]}| | j¡V  qW d S )N)r   r   Údecoder    )r   Úkr   r   r   r   ^   s    zShelf.__iter__c             C   s
   t | jƒS )N)Úlenr   )r   r   r   r   r   b   s    zShelf.__len__c             C   s   |  | j¡| jkS )N)Úencoder    r   )r   Úkeyr   r   r   Ú__contains__e   s    zShelf.__contains__c             C   s   |  | j¡| jkr| | S |S )N)r&   r    r   )r   r'   Údefaultr   r   r   Úgeth   s    z	Shelf.getc             C   sZ   y| j | }W nF tk
rT   t| j| | j¡ ƒ}t|ƒ ¡ }| jrP|| j |< Y nX |S )N)	r   ÚKeyErrorr   r   r&   r    r   Úloadr   )r   r'   ÚvalueÚfr   r   r   r   m   s    zShelf.__getitem__c             C   sF   | j r|| j|< tƒ }t|| jƒ}| |¡ | ¡ | j| | j	¡< d S )N)
r   r   r   r   r   ÚdumpÚgetvaluer   r&   r    )r   r'   r-   r.   Úpr   r   r   r   w   s    

zShelf.__setitem__c             C   s6   | j | | j¡= y| j|= W n tk
r0   Y nX d S )N)r   r&   r    r   r+   )r   r'   r   r   r   r      s
    zShelf.__delitem__c             C   s   | S )Nr   )r   r   r   r   Ú	__enter__†   s    zShelf.__enter__c             C   s   |   ¡  d S )N)Úclose)r   Útyper-   Ú	tracebackr   r   r   Ú__exit__‰   s    zShelf.__exit__c             C   sf   | j d krd S z0|  ¡  y| j  ¡  W n tk
r:   Y nX W d ytƒ | _ W n   d | _ Y nX X d S )N)r   Úsyncr3   ÚAttributeErrorr	   )r   r   r   r   r3   Œ   s    

zShelf.closec             C   s   t | dƒsd S |  ¡  d S )Nr   )Úhasattrr3   )r   r   r   r   Ú__del__   s    
zShelf.__del__c             C   sX   | j r>| jr>d| _ x| j ¡ D ]\}}|| |< qW d| _ i | _t| jdƒrT| j ¡  d S )NFTr7   )r   r   Úitemsr9   r   r7   )r   r'   Úentryr   r   r   r7   ¤   s    z
Shelf.sync)NFr   )N)r   r   r   r"   r   r   r(   r*   r   r   r   r2   r6   r3   r:   r7   r   r   r   r   r   M   s    
	

c               @   s>   e Zd Zddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ ZdS )r   NFúutf-8c             C   s   t  | ||||¡ d S )N)r   r"   )r   r   r!   r   r    r   r   r   r"   ¼   s    zBsdDbShelf.__init__c             C   s0   | j  |¡\}}t|ƒ}| | j¡t|ƒ ¡ fS )N)r   Úset_locationr   r#   r    r   r,   )r   r'   r-   r.   r   r   r   r>   À   s    zBsdDbShelf.set_locationc             C   s.   t | jƒ\}}t|ƒ}| | j¡t|ƒ ¡ fS )N)Únextr   r   r#   r    r   r,   )r   r'   r-   r.   r   r   r   r?   Å   s    zBsdDbShelf.nextc             C   s.   | j  ¡ \}}t|ƒ}| | j¡t|ƒ ¡ fS )N)r   Úpreviousr   r#   r    r   r,   )r   r'   r-   r.   r   r   r   r@   Ê   s    zBsdDbShelf.previousc             C   s.   | j  ¡ \}}t|ƒ}| | j¡t|ƒ ¡ fS )N)r   Úfirstr   r#   r    r   r,   )r   r'   r-   r.   r   r   r   rA   Ï   s    zBsdDbShelf.firstc             C   s.   | j  ¡ \}}t|ƒ}| | j¡t|ƒ ¡ fS )N)r   Úlastr   r#   r    r   r,   )r   r'   r-   r.   r   r   r   rB   Ô   s    zBsdDbShelf.last)NFr=   )	r   r   r   r"   r>   r?   r@   rA   rB   r   r   r   r   r   ¯   s    
c               @   s   e Zd Zddd„ZdS )r   ÚcNFc             C   s$   dd l }t | | ||¡||¡ d S )Nr   )Údbmr   r"   r   )r   ÚfilenameÚflagr!   r   rD   r   r   r   r"   á   s    zDbfilenameShelf.__init__)rC   NF)r   r   r   r"   r   r   r   r   r   Ú   s   rC   Fc             C   s   t | |||ƒS )N)r   )rE   rF   r!   r   r   r   r   r   æ   s    )rC   NF)Úpickler   r   Úior   Zcollections.abcÚcollectionsÚ__all__ÚabcÚMutableMappingr	   r   r   r   r   r   r   r   r   Ú<module>;   s   b+