U
    |eh                     @   s@   d Z dgZddlZddlmZmZ ddlmZ G dd dZdS )ze
Replacement for shelve, using json.
This was needed to correctly support db between Python 2 and 3.
	JsonStore    N)loaddump)existsc                   @   sN   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdddZdd Z	dd Z
dS )r   c              	   C   s^   || _ i | _t|rZz(tj|dd}t|| _W 5 Q R X W n tk
rX   td Y nX d S )Nzutf-8)encodingz6Unable to read the state.db, content will be replaced.)filenamedatar   ioopenr   
ValueErrorprint)selfr   fd r   7/tmp/pip-unpacked-wheel-ohd2lbr1/buildozer/jsonstore.py__init__   s    zJsonStore.__init__c                 C   s
   | j | S Nr   r   keyr   r   r   __getitem__   s    zJsonStore.__getitem__c                 C   s   || j |< |   d S r   r   sync)r   r   valuer   r   r   __setitem__   s    
zJsonStore.__setitem__c                 C   s   | j |= |   d S r   r   r   r   r   r   __delitem__    s    zJsonStore.__delitem__c                 C   s
   || j kS r   r   )r   itemr   r   r   __contains__$   s    zJsonStore.__contains__Nc                 C   s   | j ||S r   )r   get)r   r   defaultr   r   r   r   '   s    zJsonStore.getc                 C   s
   | j  S r   )r   keys)r   r   r   r   r    *   s    zJsonStore.keysc              	   C   s,   t | jd}t| j|dd W 5 Q R X d S )NwF)ensure_ascii)r
   r   r   r   )r   r   r   r   r   r   -   s    zJsonStore.sync)N)__name__
__module____qualname__r   r   r   r   r   r   r    r   r   r   r   r   r      s   

)	__doc____all__r	   jsonr   r   os.pathr   r   r   r   r   r   <module>   s
   