
:>"^>                 @   s   d  Z  d d l Z d d l Z d d l Z y d d l Z Wn e k
 rZ d d l Z Yn Xd d l Z d d l m	 Z	 e j
 d e	  Gd d   d e  Z Gd d   d e  Z e Z d S)	a  Index text files.

This module provides a way to create indexes to text files.

Classes:
Index     Dictionary-like class used to store index information.

_ShelveIndex    An Index class based on the shelve module.
_InMemoryIndex  An in-memory Index class.

    N)BiopythonDeprecationWarningzBio.Index has been deprecated, and we intend to remove it in a future release of Biopython. If you would like to continue using Bio.Index, please contact the Biopython developers via the mailing list or GitHub.c               @   s=   e  Z d  Z d Z d Z d Z d d d  Z d d   Z d S)	_ShelveIndexz$An index file wrapped around shelve.   	__versionNc             C   s"  t  j |   yy | rm | d | d | d g } x- | D]% } t j j |  r8 t j |  q8 Wt d   t j | d d |  _	 Wn= t k
 r t j | d d |  _	 |  j
 |  j	 |  j <YnY X|  j	 j |  j  } | d  k r t d   n( | |  j
 k rt d	 | |  j
 f   d  S)
Nz.dirz.datz.bakzopen a new shelfflagrnzUnrecognized index formatz&Version %s doesn't match my version %s)dict__init__ospathexistsunlink	Exceptionshelveopendata_ShelveIndex__version_ShelveIndex__version_keygetIOError)self	indexnametruncatefilesfileversion r   ./tmp/pip-build-ww9dw3qa/biopython/Bio/Index.pyr
   2   s(    z_ShelveIndex.__init__c             C   s    d |  j  k r |  j j   d  S)Nr   )__dict__r   close)r   r   r   r   __del__N   s    z_ShelveIndex.__del__)__name__
__module____qualname____doc__r   r   r
   r!   r   r   r   r   r   '   s
   r   c               @   s   e  Z d  Z d Z d Z 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 S)_InMemoryIndexz*Creates an in-memory index file (PRIVATE).   r   Nc             C   s  | |  _  t j |   d |  _ | rM t j j |  rM t j |  d |  _ t j j |  rt |   } |  j	 | j
   j    } | |  j k r t d | |  j f   xI | D]A } | j   \ } } |  j	 |  |  j	 |  } } | |  | <q Wd |  _ Wd  QRXd  S)Nr      z&Version %s doesn't match my version %s)
_indexnamer	   r
   _InMemoryIndex__changedr   r   r   r   r   _toobjreadlinerstrip_InMemoryIndex__versionr   split)r   r   r   handler   linekeyvaluer   r   r   r
   ^   s"    			z_InMemoryIndex.__init__c             C   s   d |  _  | j |  |  d  S)Nr(   )r*   update)r   r	   r   r   r   r4   u   s    	z_InMemoryIndex.updatec             C   s    d |  _  t j |  | |  d  S)Nr(   )r*   r	   __setitem__)r   r2   r3   r   r   r   r5   y   s    	z_InMemoryIndex.__setitem__c             C   s   d |  _  t j |  |  d  S)Nr(   )r*   r	   __delitem__)r   r2   r   r   r   r6   }   s    	z_InMemoryIndex.__delitem__c             C   s   d |  _  t j |   d  S)Nr(   )r*   r	   clear)r   r   r   r   r7      s    	z_InMemoryIndex.clearc             C   s   |  j  r t |  j d  j } | j d |  j |  j   xC |  j   D]5 \ } } | j d |  j |  |  j |  f  qH WWd  QRXd  S)Nwz%s
z%s %s
)r*   r   r)   write_tostrr.   items)r   r0   r2   r3   r   r   r   r!      s    		z_InMemoryIndex.__del__c             C   s;   t  j |  } t j d |  } d j d d   | D  S)Nb,c             s   s   |  ] } t  |  Vq d  S)N)str).0ir   r   r   	<genexpr>   s    z(_InMemoryIndex._tostr.<locals>.<genexpr>)pickledumpsarrayjoin)r   objsintlistr   r   r   r:      s    z_InMemoryIndex._tostrc             C   sQ   d d   | j  d  D } t j d |  } t j d j d d   | D   S)Nc             S   s   g  |  ] } t  |   q Sr   )int)r?   r@   r   r   r   
<listcomp>   s   	 z)_InMemoryIndex._toobj.<locals>.<listcomp>r=   r<    c             s   s   |  ] } t  |  Vq d  S)N)chr)r?   r@   r   r   r   rA      s    z(_InMemoryIndex._toobj.<locals>.<genexpr>)r/   rD   rB   loadsrE   )r   r>   rH   r   r   r   r+      s    z_InMemoryIndex._toobj)r"   r#   r$   r%   r.   Z_InMemoryIndex__version_keyr
   r4   r5   r6   r7   r!   r:   r+   r   r   r   r   r&   S   s   r&   )r%   r   rD   r   cPicklerB   ImportErrorwarningsZBior   warnr	   r   r&   Indexr   r   r   r   <module>   s   	,L