ó
ĒX[\c           @` sī   d  d l  m Z m Z m Z d  d l Z d  d l Z y d  d l m Z m Z Wn' e	 k
 rw d  d l
 m Z m Z n Xd d l m Z d   Z d   Z d e f d	     YZ d S(
   i    (   t   absolute_importt   divisiont   print_functionN(   t   quotet   unquotei   (   t   ZictBasec         C` s   t  |  d d S(   s;   
    Escape key so as to be usable on all filesystems.
    t   safet    (   R   (   t   key(    (    s(   lib/python2.7/site-packages/zict/file.pyt	   _safe_key   s    c         C` s
   t  |   S(   s0   
    Undo the escaping done by _safe_key().
    (   R   (   R   (    (    s(   lib/python2.7/site-packages/zict/file.pyt   _unsafe_key   s    t   Filec           B` se   e  Z d  Z d d  Z d   Z e Z d   Z d   Z d   Z d   Z	 e	 Z
 d   Z d	   Z RS(
   sŲ   Mutable Mapping interface to a directory

    Keys must be strings, values must be bytes

    Note this shouldn't be used for interprocess persistence, as keys
    are cached in memory.

    Parameters
    ----------
    directory: string
    mode: string, ('r', 'w', 'a'), defaults to 'a'

    Examples
    --------
    >>> z = File('myfile')  # doctest: +SKIP
    >>> z['x'] = b'123'  # doctest: +SKIP
    >>> z['x']  # doctest: +SKIP
    b'123'

    Also supports writing lists of bytes objects

    >>> z['y'] = [b'123', b'4567']  # doctest: +SKIP
    >>> z['y']  # doctest: +SKIP
    b'1234567'

    Or anything that can be used with file.write, like a memoryview

    >>> z['data'] = np.ones(5).data  # doctest: +SKIP
    t   ac         C` s}   | |  _  | |  _ t   |  _ t j j |  j   sF t j |  j   n3 x0 t j |  j   D] } |  j j	 t
 |   qY Wd  S(   N(   t	   directoryt   modet   sett   _keyst   ost   patht   existst   mkdirt   listdirt   addR
   (   t   selfR   R   t   n(    (    s(   lib/python2.7/site-packages/zict/file.pyt   __init__:   s    		c         C` s   d |  j  |  j t |   f S(   Ns"   <File: %s, mode="%s", %d elements>(   R   R   t   len(   R   (    (    s(   lib/python2.7/site-packages/zict/file.pyt   __str__D   s    c         C` s\   | |  j  k r t |   n  t t j j |  j t |   d   } | j   SWd  QXd  S(   Nt   rb(	   R   t   KeyErrort   openR   R   t   joinR   R	   t   read(   R   R   t   f(    (    s(   lib/python2.7/site-packages/zict/file.pyt   __getitem__I   s    *c         C` s   t  t j j |  j t |   d  J } t | t t f  r` x+ | D] } | j	 |  qF Wn | j	 |  Wd  QX|  j
 j |  d  S(   Nt   wb(   R   R   R   R   R   R	   t
   isinstancet   tuplet   listt   writeR   R   (   R   R   t   valueR!   t   v(    (    s(   lib/python2.7/site-packages/zict/file.pyt   __setitem__O   s    *c         C` s   | |  j  k S(   N(   R   (   R   R   (    (    s(   lib/python2.7/site-packages/zict/file.pyt   __contains__X   s    c         C` s   t  |  j  S(   N(   t   iterR   (   R   (    (    s(   lib/python2.7/site-packages/zict/file.pyt   keys[   s    c         C` sW   | |  j  k r t |   n  t j t j j |  j t |    |  j  j |  d  S(   N(   R   R   R   t   removeR   R   R   R	   (   R   R   (    (    s(   lib/python2.7/site-packages/zict/file.pyt   __delitem__`   s    %c         C` s   t  |  j  S(   N(   R   R   (   R   (    (    s(   lib/python2.7/site-packages/zict/file.pyt   __len__f   s    (   t   __name__t
   __module__t   __doc__R   R   t   __repr__R"   R*   R+   R-   t   __iter__R/   R0   (    (    (    s(   lib/python2.7/site-packages/zict/file.pyR      s   
							(   t
   __future__R    R   R   t   errnoR   t   urllib.parseR   R   t   ImportErrort   urllibt   commonR   R	   R
   R   (    (    (    s(   lib/python2.7/site-packages/zict/file.pyt   <module>   s   		