ó
\c           @@  s÷  d  Z  d d l m Z d d l Z d d l Z d d l m Z d d l m Z m	 Z	 d d l
 Z
 d d l m Z m Z d d l m Z d	 d
 l m Z m Z m Z m Z m Z m Z d	 d l m Z d	 d l m Z e j ƒ  j Z e j d d !Z e Z e e j ƒ  j  k re! Z n  i e j" d 6e j# d 6Z$ e% d „  e
 j& e$ ƒ Dƒ ƒ Z' d „  Z( d „  Z) i d „  d 6d „  d 6d „  d 6d „  d 6e( d 6e) d 6Z* d „  Z+ d „  Z, d „  Z- d  „  Z. e d! „ Z/ d e d" „ Z1 d# e f d$ „  ƒ  YZ2 d S(%   s:   
    Implements high-level support for HDF5 file objects.
i    (   t   absolute_importN(   t   warni   (   t   filename_decodet   filename_encode(   t   philt	   with_phil(   t   Groupi   (   t   h5t   h5ft   h5pt   h5it   h5fdt   _objects(   t   version(   t   H5pyDeprecationWarningi   t   earliestt   latestc         c@  s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0t   xt   y(    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pys	   <genexpr>'   s    c         K@  s6   d d  l  } | j d | j j ƒ  ƒ |  j |   d  S(   Ni    t   info(   t   mpi4pyt
   setdefaultt   MPIt   Infot   set_fapl_mpio(   t   plistt   kwargsR   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   _set_fapl_mpio*   s    c         K@  s    |  j  t j | j d ƒ ƒ d  S(   Nt   fileobj(   t   set_fileobj_driverR   t   fileobj_drivert   get(   R   R   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   _set_fapl_fileobj0   s    c         K@  s   |  j  |   S(   N(   t   set_fapl_sec2(   R   R   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   <lambda>5   s    t   sec2c         K@  s   |  j  |   S(   N(   t   set_fapl_stdio(   R   R   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyR#   6   s    t   stdioc         K@  s   |  j  |   S(   N(   t   set_fapl_core(   R   R   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyR#   7   s    t   corec         K@  s   |  j  d |  j ƒ  |  S(   Nt	   memb_fapl(   t   set_fapl_familyt   copy(   R   R   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyR#   8   s   		t   familyt   mpioR   c         C@  s   | t  |  <d S(   sä   Register a custom driver.

    Parameters
    ----------
    name : str
        The name of the driver.
    set_fapl : callable[PropFAID, **kwargs] -> NoneType
        The function to set the fapl to use your custom driver.
    N(   t   _drivers(   t   namet   set_fapl(    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   register_driverA   s    
c         C@  s   t  |  =d S(   sn   Unregister a custom driver.

    Parameters
    ----------
    name : str
        The name of the driver.
    N(   R.   (   R/   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   unregister_driverN   s    c           C@  s
   t  t ƒ S(   sF   Return a frozenset of the names of all of the registered drivers.
    (   t	   frozensetR.   (    (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   registered_driversY   s    c         K@  s‡  t  j t  j ƒ } | d
 k	 rY | t k r@ t | } t j } ql d „  | Dƒ \ } } n t j t j } } | j | | ƒ t	 | j
 ƒ  ƒ }	 | d
 k	 r§ | |	 d <n  | d
 k	 rÀ | |	 d <n  | d
 k	 rÙ | |	 d <n  | j |	 Œ  |  d
 k s|  d k rDt j d k rD| r@d j d t t | ƒ ƒ ƒ }
 t |
 ƒ ‚ n  | Sy t |  } Wn! t k
 rut d	 |  ƒ ‚ n X| | |  | S(   s$    Set up a file access property list c         s@  s   |  ] } t  | Vq d  S(   N(   t   libver_dict(   R   R   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pys	   <genexpr>h   s    i   i   i   t   windowst   win32s8   '{key}' is an invalid keyword argument for this functiont   keys   Unknown driver type "%s"N(   R	   t   createt   FILE_ACCESSt   NoneR5   R   t   LIBVER_LATESTt   LIBVER_EARLIESTt   set_libver_boundst   listt	   get_cachet	   set_cachet   syst   platformt   formatt   nextt   itert	   TypeErrorR.   t   KeyErrort
   ValueError(   t   drivert   libvert   rdcc_nslotst   rdcc_nbytest   rdcc_w0t   kwdsR   t   lowt   hight   cache_settingst   msgR0   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt	   make_fapl_   s8    
'	c         C@  sS   |  rI t  j t  j ƒ } | j t  j t  j Bƒ | j t  j t  j Bƒ n d } | S(   s&    Set up a file creation property list N(   R	   R9   t   FILE_CREATEt   set_link_creation_ordert   CRT_ORDER_TRACKEDt   CRT_ORDER_INDEXEDt   set_attr_creation_orderR;   (   t   track_orderR   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt	   make_fcpl‰   s    c   	      C@  sÔ  | d k	 rŽ | d k r' t d ƒ ‚ n  y t | ƒ } Wn# t t f k
 r\ t d ƒ ‚ n X| d k r~ t j t j ƒ } n  | j | ƒ n  | d k rÚ t j	 } | r¿ t
 r¿ | t j O} n  t j |  | d | ƒ} n| d k rt j |  t j d | ƒ} ne| d k r4t j |  t j d | d | ƒ} n5| d	 k rdt j |  t j d | d | ƒ} n| d
 k rÇy t j |  t j d | ƒ} Wqit k
 rÃt j |  t j d | d | ƒ} qiXn¢ | d k r]y t j |  t j d | ƒ} Wqit k
 rYy t j |  t j	 d | ƒ} WqZt k
 rUt j |  t j d | d | ƒ} qZXqiXn t d ƒ ‚ yP | d k	 r¸| j ƒ  } | j ƒ  | k r¸t d | | j ƒ  f ƒ ‚ q¸n  Wn | j ƒ  ‚  n X| S(   sR    Get a new FileID by opening or creating a file.
    Also validates mode argument.t   rs   r+s5   User block may only be specified when creating a files"   User block size must be an integert   fapls   w-R   t   fcplt   wt   as/   Invalid mode; must be one of r, r+, w, w-, x, asG   Requested userblock size (%d) does not match that of existing file (%d)N(   R\   s   r+(   s   w-R   (   R;   RI   t   intRG   R	   R9   RU   t   set_userblockR   t
   ACC_RDONLYt   swmr_supportt   ACC_SWMR_READt   opent   ACC_RDWRt   ACC_EXCLt	   ACC_TRUNCt   IOErrort   get_create_plistt   get_userblockt   close(	   R/   t   modet   userblock_sizeR]   R^   t   swmrt   flagst   fidt   existing_fcpl(    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   make_fid–   sX    	$$(,&
t   Filec        
   B@  sp  e  Z d  Z 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 rÛ e d k rÛ e e d „  ƒ ƒ Z e j e d „  ƒ ƒ Z n  e re d „  ƒ Z e j e d „  ƒ ƒ Z n  d d d d e d d d d d „	 Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   s&   
        Represents an HDF5 file.
    c         C@  s2   d d l  m } t  | j |  d ƒ SWd QXd S(   s$    Attributes attached to this object i   (   t   attrst   /N(   t    Rv   R   t   AttributeManager(   t   selfRv   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyRv   Ù   s    c         C@  s   t  t j |  j ƒ ƒ S(   s   File name on disk(   R   R   t   get_namet   id(   Rz   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   filenameâ   s    c         C@  su   i d t  j 6d t  j 6d t  j 6d t  j 6d t  j 6d t  j 6d t  j 6d t  j 6} | j	 |  j
 j ƒ  j ƒ  d	 ƒ S(
   s,   Low-level HDF5 file driver used to open fileR$   R&   R(   R,   R6   R-   t   mpiposixR   t   unknown(   R   t   SEC2t   STDIOt   COREt   FAMILYt   WINDOWSt   MPIOt   MPIPOSIXR   R    R|   t   get_access_plistt
   get_driver(   Rz   t   drivers(    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyRJ   è   s    





c         C@  s*   i d t  j 6d t  j 6j |  j j ƒ  ƒ S(   s    Python mode used to open file R\   s   r+(   R   Rc   Rg   R    R|   t
   get_intent(   Rz   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyRn   ö   s    c         C@  s   t  d t ƒ |  j S(   s"   File ID (backwards compatibility) s2   File.fid has been deprecated. Use File.id instead.(   R   R   R|   (   Rz   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyRr   ý   s    c         C@  s)   |  j  j ƒ  j ƒ  } t d „  | Dƒ ƒ S(   s/   File format version bounds (2-tuple: low, high)c         s@  s   |  ] } t  | Vq d  S(   N(   t   libver_dict_r(   R   R   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pys	   <genexpr>
  s    (   R|   R‡   t   get_libver_boundst   tuple(   Rz   t   bounds(    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyRK     s    c         C@  s   |  j  j ƒ  } | j ƒ  S(   s    User block size (in bytes) (   R|   Rk   Rl   (   Rz   R^   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyRo     s    i   i   i	   c         C@  s   |  j  j ƒ  S(   s(    Set/get MPI-IO atomic mode
            (   R|   t   get_mpi_atomicity(   Rz   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   atomic  s    c         C@  s   |  j  j | ƒ d  S(   N(   R|   t   set_mpi_atomicity(   Rz   t   value(    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyR     s    c         C@  s   |  j  S(   s-    Controls single-writer multiple-reader mode (   t
   _swmr_mode(   Rz   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt	   swmr_mode$  s    c         C@  s/   | r |  j  j ƒ  t |  _ n t d ƒ ‚ d  S(   Ns4   It is not possible to forcibly switch SWMR mode off.(   R|   t   start_swmr_writet   TrueR“   RI   (   Rz   R’   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyR”   )  s    c         K@  sž  | r t  r t d ƒ ‚ n  t | t j ƒ rM t  t j | ƒ } Wd QXn=t | d ƒ rÞ t | d ƒ rÞ | d k r† t d ƒ ‚ n  d } | j
 d | ƒ | k r³ t d ƒ ‚ n  | j d | ƒ t | ƒ j d d	 ƒ } n t | ƒ } |
 d k rt j ƒ  j }
 n  t J t | | | | |	 |  } t | | | | d
 t d |
 ƒ d | ƒ} Wd QXt  rŠt |  _ | rŠ| d k rŠt |  _ qŠn  t j |  | ƒ d S(   s=  Create a new file object.

        See the h5py user guide for a detailed explanation of the options.

        name
            Name of the file on disk, or file-like object.  Note: for files
            created with the 'core' driver, HDF5 still requires this be
            non-empty.
        mode
            r        Readonly, file must exist
            r+       Read/write, file must exist
            w        Create file, truncate if exists
            w- or x  Create file, fail if exists
            a        Read/write if exists, create otherwise (default)
        driver
            Name of the driver to use.  Legal values are None (default,
            recommended), 'core', 'sec2', 'stdio', 'mpio'.
        libver
            Library version bounds.  Currently only the strings 'earliest'
            and 'latest' are defined.
        userblock
            Desired size of user block.  Only allowed when creating a new
            file (mode w, w- or x).
        swmr
            Open the file in SWMR read mode. Only used when mode = 'r'.
        rdcc_nbytes
            Total size of the raw data chunk cache in bytes. The default size
            is 1024**2 (1 MB) per dataset.
        rdcc_w0
            The chunk preemption policy for all datasets.  This must be
            between 0 and 1 inclusive and indicates the weighting according to
            which chunks which have been fully read or written are penalized
            when determining which chunks to flush from cache.  A value of 0
            means fully read or written chunks are treated no differently than
            other chunks (the preemption is strictly LRU) while a value of 1
            means fully read or written chunks are always preempted before
            other chunks.  If your application only reads or writes data once,
            this can be safely set to 1.  Otherwise, this should be set lower
            depending on how often you re-read or re-write the same data.  The
            default value is 0.75.
        rdcc_nslots
            The number of chunk slots in the raw data chunk cache for this
            file. Increasing this value reduces the number of cache collisions,
            but slightly increases the memory used. Due to the hashing
            strategy, this value should ideally be a prime number. As a rule of
            thumb, this value should be at least 10 times the number of chunks
            that can fit in rdcc_nbytes bytes. For maximum performance, this
            value should be set approximately 100 times that number of
            chunks. The default value is 521.
        track_order
            Track dataset/group/attribute creation order under root group
            if True. If None use global default h5.get_config().track_order.
        Additional keywords
            Passed on to the selected file driver.

        sE   The SWMR feature is not available in this version of the HDF5 libraryNt   readt   seekR   s;   Driver must be 'fileobj' for file-like object if specified.sQ   Invalid value of 'fileobj' argument; must equal to file-like object if specified.t   ASCIIt   replaceR^   RZ   Rp   R\   (   NR   (   Rd   RI   t
   isinstanceR   t   ObjectIDR   R
   t   get_file_idt   hasattrR;   R    t   updatet   reprt   encodeR   R   t
   get_configRZ   RT   Rt   R[   t   FalseR“   R–   R   t   __init__(   Rz   R/   Rn   RJ   RK   Ro   Rp   RL   RM   RN   RZ   RO   Rr   R]   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyR¤   3  s4    =	c         C@  s2  t  &|  j j r(t j |  j t j ƒ } t j |  j t j ƒ } g  | D]* } t j | ƒ j |  j j k rK | ^ qK } g  | D]* } t j | ƒ j |  j j k r‚ | ^ q‚ } x+ | D]# } x | j rÛ t j | ƒ qÂ Wq¹ Wx+ | D]# } x | j r	t j | ƒ qð Wqç W|  j j	 ƒ  t
 j ƒ  n  Wd QXd S(   s2    Close the file.  All open objects become invalid N(   R   R|   t   validR   t   get_obj_idst   OBJ_FILER
   R   t   dec_refRm   R   t   nonlocal_close(   Rz   t   id_listt	   file_listR   t   id_(    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyRm   “  s    77c         C@  s!   t   t j |  j ƒ Wd QXd S(   s5    Tell the HDF5 library to flush its buffers.
        N(   R   R   t   flushR|   (   Rz   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyR­   ­  s    c         C@  s   |  S(   N(    (   Rz   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt	   __enter__³  s    c         G@  s   |  j  r |  j ƒ  n  d  S(   N(   R|   Rm   (   Rz   t   args(    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   __exit__·  s    	c         C@  sx   |  j  s d } nL |  j } t | t ƒ r? | j d d ƒ } n  d t j j | ƒ |  j f } t	 j
 rt | j d ƒ S| S(   Nu   <Closed HDF5 file>t   utf8Rš   u   <HDF5 file "%s" (mode %s)>(   R|   R}   R›   t   bytest   decodet   ost   patht   basenameRn   t   sixt   PY2R¡   (   Rz   R\   R}   (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   __repr__¼  s    				(   i   i   i	   N(   t   __name__t
   __module__t   __doc__t   propertyRv   R   R}   RJ   Rn   Rr   RK   Ro   t   mpit   hdf5_versionR   t   setterRd   R”   R;   R£   R¤   Rm   R­   R®   R°   R¹   (    (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyRu   Ó   s@   				]		(3   R¼   t
   __future__R    RB   R´   t   warningsR   t   compatR   R   R·   t   baseR   R   t   groupR   Rx   R   R   R	   R
   R   R   R   t   h5py_warningsR   R¢   R¾   t   hdf5_version_tupleR¿   R£   Rd   t   swmr_min_hdf5_versionR–   R=   R<   R5   t   dictt	   iteritemsR‹   R   R!   R.   R1   R2   R4   RT   R[   R;   Rt   Ru   (    (    (    s-   lib/python2.7/site-packages/h5py/_hl/files.pyt   <module>   sD   .			




				*=