a
    ãzeO!  ã                   @   s‚   d dl mZmZ d dlmZ d dlZg d¢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.9/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 u 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"   | j  ¡ D ]}| | j¡V  q
d S ©N)r   r   Údecoder!   )r   Úkr   r   r   r   ^   s    zShelf.__iter__c                 C   s
   t | jƒS r%   )Úlenr   r   r   r   r   r   b   s    zShelf.__len__c                 C   s   |  | j¡| jv S r%   ©Úencoder!   r   ©r   Úkeyr   r   r   Ú__contains__e   s    zShelf.__contains__c                 C   s   |  | j¡| jv r| | S |S r%   r)   )r   r,   Údefaultr   r   r   Úgeth   s    z	Shelf.getc                 C   sX   z| j | }W nD tyR   t| j| | j¡ ƒ}t|ƒ ¡ }| jrN|| j |< Y n0 |S r%   )	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 r%   )
r   r    r   r   r   ÚdumpÚgetvaluer   r*   r!   )r   r,   r3   r4   Úpr   r   r   r   w   s    

zShelf.__setitem__c                 C   s4   | j | | j¡= z| j|= W n ty.   Y n0 d S r%   )r   r*   r!   r    r0   r+   r   r   r   r      s
    zShelf.__delitem__c                 C   s   | S r%   r   r   r   r   r   Ú	__enter__†   s    zShelf.__enter__c                 C   s   |   ¡  d S r%   )Úclose)r   Útyper3   Ú	tracebackr   r   r   Ú__exit__‰   s    zShelf.__exit__c                 C   s„   | j d u rd S zN|  ¡  z| j  ¡  W n ty8   Y n0 W ztƒ | _ W q€   d | _ Y q€0 n"ztƒ | _ W n   d | _ Y n0 0 d S r%   )r   Úsyncr9   ÚAttributeErrorr	   r   r   r   r   r9   Œ   s     
ýzShelf.closec                 C   s   t | dƒsd S |  ¡  d S )Nr   )Úhasattrr9   r   r   r   r   Ú__del__   s    
zShelf.__del__c                 C   sT   | j r:| jr:d| _ | j ¡ D ]\}}|| |< qd| _ i | _t| jdƒrP| j ¡  d S )NFTr=   )r   r    Úitemsr?   r   r=   )r   r,   Úentryr   r   r   r=   ¤   s    
z
Shelf.sync)NFr   )N)r   r   r   r$   r   r   r-   r/   r   r   r   r8   r<   r9   r@   r=   r   r   r   r   r   M   s     ÿ



r   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   NFr   c                 C   s   t  | ||||¡ d S r%   )r   r$   r"   r   r   r   r$   ¼   s    zBsdDbShelf.__init__c                 C   s0   | j  |¡\}}t|ƒ}| | j¡t|ƒ ¡ fS r%   )r   Úset_locationr   r&   r!   r   r1   r2   r   r   r   rC   À   s    zBsdDbShelf.set_locationc                 C   s.   t | jƒ\}}t|ƒ}| | j¡t|ƒ ¡ fS r%   )Únextr   r   r&   r!   r   r1   r2   r   r   r   rD   Å   s    zBsdDbShelf.nextc                 C   s.   | j  ¡ \}}t|ƒ}| | j¡t|ƒ ¡ fS r%   )r   Úpreviousr   r&   r!   r   r1   r2   r   r   r   rE   Ê   s    zBsdDbShelf.previousc                 C   s.   | j  ¡ \}}t|ƒ}| | j¡t|ƒ ¡ fS r%   )r   Úfirstr   r&   r!   r   r1   r2   r   r   r   rF   Ï   s    zBsdDbShelf.firstc                 C   s.   | j  ¡ \}}t|ƒ}| | j¡t|ƒ ¡ fS r%   )r   Úlastr   r&   r!   r   r1   r2   r   r   r   rG   Ô   s    zBsdDbShelf.last)NFr   )	r   r   r   r$   rC   rD   rE   rF   rG   r   r   r   r   r   ¯   s     ÿ
r   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   rI   r   r   r   r$   á   s    zDbfilenameShelf.__init__)rH   NF)r   r   r   r$   r   r   r   r   r   Ú   s   r   rH   Fc                 C   s   t | |||ƒS r%   )r   )rJ   rK   r#   r   r   r   r   r   æ   s    r   )rH   NF)Úpickler   r   Úior   Úcollections.abcÚcollectionsÚ__all__ÚabcÚMutableMappingr	   r   r   r   r   r   r   r   r   Ú<module>;   s   b+