σ
ΎχXc           @@  sΒ  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z m Z m	 Z	 m
 Z
 m Z d d l m Z d d l m Z d d	 l m Z m Z m Z m Z m Z m Z m Z d d
 l m Z m Z d   Z d   Z d   Z d   Z e   Z e   Z d   Z  d e! f d     YZ" d e! f d     YZ# d e" f d     YZ$ d e
 f d     YZ% d e f d     YZ& d e f d     YZ' d e' e f d     YZ( d e! f d     YZ) d S(    sJ   
    Implements operations common to all high-level objects (File, etc.).
i    (   t   absolute_importN(   t   Mappingt   MutableMappingt   KeysViewt
   ValuesViewt	   ItemsViewi   (   t   fspath(   t   fsencodei   (   t   h5dt   h5it   h5rt   h5pt   h5ft   h5tt   h5s(   t   philt	   with_philc         C@  sR   t  F t j j t |    }  t j j |   rD t j t |    St	 SWd QXd S(   s@    Determine if a file is valid HDF5 (False if it doesn't exist). N(
   R   t   ost   patht   abspathR   t   isfileR   t   is_hdf5R   t   False(   t   fname(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR   "   s
    c         C@  s©   t   t |  t j  r, t j d t j  St |  t j  rQ t j d t j  St |   t k rs t j d t  St |   t	 j
 k r t j d t	 j
  Sd SWd QXd S(   s±    Attempt to guess an appropriate dtype for the object, returning None
    if nothing is appropriate (or if it should be left up the the array
    constructor to figure out)
    t   reft   vlenN(   R   t
   isinstanceR
   t   RegionReferenceR   t   special_dtypet	   Referencet   typet   bytest   sixt	   text_typet   None(   t   data(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   guess_dtype,   s    c          C@  sE   t  j t  j  }  t  j t  j  } | j t j  |  j |  |  S(   s#    Default link access property list (   R   t   createt   LINK_ACCESSt   FILE_ACCESSt   set_fclose_degreeR   t   CLOSE_STRONGt   set_elink_fapl(   t   laplt   fapl(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   default_lapl>   s
    c          C@  s#   t  j t  j  }  |  j t  |  S(   s%    Default link creation property list (   R   R%   t   LINK_CREATEt   set_create_intermediate_groupt   True(   t   lcpl(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   default_lcplG   s    c         C@  s#   |  j    j   t j k r t St S(   s)    Check if an object's dataspace is empty (   t	   get_spacet   get_simple_extent_typeR   t   NULLR0   R   (   t   obj(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   is_empty_dataspaceQ   s    t   CommonStateObjectc           B@  sA   e  Z d  Z e d    Z e d    Z d d  Z d   Z RS(   s  
        Mixin class that allows sharing information between objects which
        reside in the same HDF5 file.  Requires that the host class have
        a ".id" attribute which returns a low-level ObjectID subclass.

        Also implements Unicode operations.
    c         C@  s   t  S(   sI    Fetch the link access property list appropriate for this object
        (   t   dlapl(   t   self(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   _laplb   s    c         C@  s   t  S(   sK    Fetch the link creation property list appropriate for this object
        (   t   dlcpl(   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   _lcplh   s    c         @  s¦     f d   } | d k r) | r% d Sd St | t  rD t j } nH y | j d  } t j } Wn) t k
 r | j d  } t j } n X| r’ | | |  f S| S(   sG   Encode a name according to the current file settings.

        Returns name, or 2-tuple (name, lcpl) if lcpl is True

        - Binary strings are always passed as-is, h5t.CSET_ASCII
        - Unicode strings are encoded utf8, h5t.CSET_UTF8

        If name is None, returns either None or (None, None) appropriately.
        c         @  s      j  j   } | j |   | S(   s3    Create an appropriate link creation property list (   R=   t   copyt   set_char_encoding(   t   codingR1   (   R:   (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   get_lcplx   s    t   asciit   utf8N(   NN(   R"   R   R   R   t
   CSET_ASCIIt   encodet   UnicodeEncodeErrort	   CSET_UTF8(   R:   t   nameR1   RA   R@   (    (   R:   s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   _en   s    
c         C@  s9   | d k r d Sy | j d  SWn t k
 r4 n X| S(   s΄    Decode a name according to the current file settings.

        - Try to decode utf8
        - Failing that, return the byte string

        If name is None, returns None.
        RC   N(   R"   t   decodet   UnicodeDecodeError(   R:   RH   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   _d   s    N(	   t   __name__t
   __module__t   __doc__t   propertyR;   R=   R"   RI   RL   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR8   X   s
   !t   _RegionProxyc           B@  s8   e  Z d  Z d   Z e d    Z d   Z d   Z RS(   s	  
        Proxy object which handles region references.

        To create a new region reference (datasets only), use slicing syntax:

            >>> newref = obj.regionref[0:10:2]

        To determine the target dataset shape from an existing reference:

            >>> shape = obj.regionref.shape(existingref)

        where <obj> may be any object in the file. To determine the shape of
        the selection in use on the target dataset:

            >>> selection_shape = obj.regionref.selection(existingref)
    c         C@  s   | j  |  _  d  S(   N(   t   id(   R:   R6   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   __init__΄   s    c         C@  st   t  |  j t j  s$ t d   n  d d l m } | j |  j j | d |  j } t	 j
 |  j d t	 j | j  S(   Ns.   Region references can only be made to datasetsi   (   t
   selectionst   dsidt   .(   R   RR   R   t	   DatasetIDt	   TypeErrort    RT   t   selectt   shapeR
   R%   t   DATASET_REGION(   R:   t   argsRT   t	   selection(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   __getitem__·   s
    !c         C@  s-   t  ! t j | |  j  } | j SWd QXd S(   s=    Get the shape of the target dataspace referred to by *ref*. N(   R   R
   t
   get_regionRR   R[   (   R:   R   t   sid(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR[   Ώ   s    c         C@  sC   t  7 d d l m } t j | |  j  } | j |  SWd QXd S(   sN    Get the shape of the target dataspace selection referred to by *ref*
        i   (   RT   N(   R   RY   RT   R
   R`   RR   t   guess_shape(   R:   R   RT   Ra   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR^   Ε   s    (   RM   RN   RO   RS   R   R_   R[   R^   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyRQ   ‘   s
   		t   HLObjectc           B@  sμ   e  Z d  Z e e d     Z e e d     Z e e d     Z e e d     Z e e d     Z	 e e d     Z
 e e d     Z e d    Z e d	    Z e d
    Z e d    Z d   Z e Z RS(   s:   
        Base class for high-level interface objects.
    c         C@  s    d d l  m } | j |  j  S(   s4    Return a File instance associated with this object i   (   t   files(   RY   Rd   t   FileRR   (   R:   Rd   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   fileΤ   s    c         C@  s   |  j  t j |  j   S(   s:    Return the full name of this object.  None if anonymous. (   RL   R	   t   get_nameRR   (   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyRH   Ϋ   s    c         C@  s5   |  j  d k r t d   n  |  j t j |  j   S(   s­   Return the parent group of this object.

        This is always equivalent to obj.file[posixpath.dirname(obj.name)].
        ValueError if this object is anonymous.
        s*   Parent of an anonymous object is undefinedN(   RH   R"   t
   ValueErrorRf   t	   posixpatht   dirname(   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   parentα   s    c         C@  s   |  j  S(   s2    Low-level identifier appropriate for this object (   t   _id(   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyRR   ν   s    c         C@  s   t  j |  j d t  j  S(   s+    An (opaque) HDF5 reference to this object RV   (   R
   R%   RR   t   OBJECT(   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR   σ   s    c         C@  s
   t  |   S(   sz  Create a region reference (Datasets only).

        The syntax is regionref[<slices>]. For example, dset.regionref[...]
        creates a region reference in which the whole dataset is selected.

        Can also be used to determine the shape of the referenced dataset
        (via .shape property), or the shape of the selection (via the
        .selection property).
        (   RQ   (   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt	   regionrefω   s    c         C@  s   d d l  m } | j |   S(   s$    Attributes attached to this object i   (   t   attrs(   RY   Ro   t   AttributeManager(   R:   Ro   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyRo     s    c         C@  s   | |  _  d S(   s3    Setup this object, given its low-level identifier N(   Rl   (   R:   t   oid(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyRS     s    c         C@  s   t  |  j  S(   N(   t   hashRR   (   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   __hash__  s    c         C@  s#   t  | d  r |  j | j k St S(   NRR   (   t   hasattrRR   R   (   R:   t   other(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   __eq__  s    c         C@  s   |  j  |  S(   N(   Rv   (   R:   Ru   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   __ne__  s    c         C@  s   t   t |  j  SWd  QXd  S(   N(   R   t   boolRR   (   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   __bool__!  s    (   RM   RN   RO   RP   R   Rf   RH   Rk   RR   R   Rn   Ro   RS   Rs   Rv   Rw   Ry   t   __nonzero__(    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyRc   Ξ   s*   	t   ValuesViewHDF5c           B@  s    e  Z d  Z d   Z d   Z RS(   sΗ   
        Wraps e.g. a Group or AttributeManager to provide a value view.
        
        Note that __contains__ will have poor performance as it has
        to scan all the links or attributes.
    c         C@  sE   t  9 x- |  j D]" } | |  j j |  k r t Sq Wt SWd  QXd  S(   N(   R   t   _mappingt   getR0   R   (   R:   t   valuet   key(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   __contains__:  s
    c         c@  s6   t  * x" |  j D] } |  j j |  Vq WWd  QXd  S(   N(   R   R|   R}   (   R:   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   __iter__A  s    (   RM   RN   RO   R   R   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR{   1  s   	t   ItemsViewHDF5c           B@  s    e  Z d  Z d   Z d   Z RS(   sN   
        Wraps e.g. a Group or AttributeManager to provide an items view.
    c         C@  sF   t  : | \ } } | |  j k r8 | |  j j |  k St SWd  QXd  S(   N(   R   R|   R}   R   (   R:   t   itemR   t   val(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR   M  s
    c         c@  s<   t  0 x( |  j D] } | |  j j |  f Vq WWd  QXd  S(   N(   R   R|   R}   (   R:   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR   T  s    (   RM   RN   RO   R   R   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR   G  s   	t   MappingHDF5c           B@  sb   e  Z d  Z e j rE d   Z d   Z d   Z d   Z d   Z	 n d   Z d   Z d   Z RS(	   s  
        Wraps a Group, AttributeManager or DimensionManager object to provide
        an immutable mapping interface.
        
        We don't inherit directly from MutableMapping because certain
        subclasses, for example DimensionManager, are read-only.
    c         C@  s   t   t |   SWd QXd S(   s$    Get a list containing member names N(   R   t   list(   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   keysd  s    c         C@  s1   t  % g  |  D] } |  j |  ^ q SWd QXd S(   s&    Get a list containing member objects N(   R   R}   (   R:   t   x(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   valuesi  s    c         c@  s#   x |  D] } |  j  |  Vq Wd S(   s%    Get an iterator over member objects N(   R}   (   R:   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt
   itervaluesn  s    c      	   C@  s7   t  + g  |  D] } | |  j |  f ^ q SWd QXd S(   s6    Get a list of tuples containing (name, object) pairs N(   R   R}   (   R:   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   itemss  s    c         c@  s)   x" |  D] } | |  j  |  f Vq Wd S(   s+    Get an iterator over (name, object) pairs N(   R}   (   R:   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt	   iteritemsx  s    c         C@  s
   t  |   S(   s#    Get a view object on member names (   R   (   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR   ~  s    c         C@  s
   t  |   S(   s%    Get a view object on member objects (   R{   (   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR     s    c         C@  s
   t  |   S(   s#    Get a view object on member items (   R   (   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR     s    (
   RM   RN   RO   R    t   PY2R   R   R   R   R   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR   Z  s   							t   MutableMappingHDF5c           B@  s   e  Z d  Z RS(   s£   
        Wraps a Group or AttributeManager object to provide a mutable
        mapping interface, in contrast to the read-only mapping of
        MappingHDF5.
    (   RM   RN   RO   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR     s   t   Emptyc           B@  s/   e  Z d  Z d Z d   Z d   Z d   Z RS(   sΟ   
        Proxy object to represent empty/null dataspaces (a.k.a H5S_NULL).

        This can have an associated dtype, but has no shape or data. This is not
        the same as an array with shape (0,).
    c         C@  s   | |  _  d  S(   N(   t   dtype(   R:   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyRS      s    c         C@  s)   t  | t  r% |  j | j k r% t St S(   N(   R   R   R   R0   R   (   R:   Ru   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyRv   £  s    !c         C@  s   d j  |  j  S(   Ns   Empty(dtype={0!r})(   t   formatR   (   R:   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   __repr__¨  s    N(   RM   RN   RO   R"   R[   RS   Rv   R   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyR     s
   		(*   RO   t
   __future__R    Ri   R   R    t   collectionsR   R   R   R   R   t   compatR   R   RY   R   R	   R
   R   R   R   R   t   _objectsR   R   R   R$   R-   R2   R9   R<   R7   t   objectR8   RQ   Rc   R{   R   R   R   R   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/base.pyt   <module>   s0   (4	
							I-c1