ó
¾÷Xc           @@  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 d d l 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 e j ƒ  j Z e j d d !Z e Z e e j ƒ  j k re Z n  e r&d d l Z n  i e j  d 6e j! d 6Z" e# d „  e	 j$ e" ƒ Dƒ ƒ Z% d „  Z& d e d „ Z( d e f d „  ƒ  YZ) d S(   s:   
    Implements high-level support for HDF5 file objects.
i    (   t   absolute_importNi   (   t   fspath(   t   fsencode(   t   fsdecode(   t   philt	   with_phil(   t   Groupi   (   t   h5t   h5ft   h5pt   h5it   h5fdt   _objects(   t   versioni   t   earliestt   latestc         c@  s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0t   xt   y(    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pys	   <genexpr>)   s    c         K@  sŒ  t  j t  j ƒ } | d k	 ri | t k r@ t | } t j } n d „  | Dƒ \ } } | j | | ƒ n  |  d k s |  d k rÇ t j	 d k rÇ | rÃ d j
 d t t | ƒ ƒ ƒ } t | ƒ ‚ n  | S|  d k rã | j |   n¥ |  d k rÿ | j |   n‰ |  d k r| j |   nm |  d	 k rC| j d
 | j ƒ  |  nE |  d k rx| j d t j j ƒ  ƒ | j |   n t d |  ƒ ‚ | S(   s$    Set up a file access property list c         s@  s   |  ] } t  | Vq d  S(   N(   t   libver_dict(   R   R   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pys	   <genexpr>5   s    t   windowst   win32s8   '{key}' is an invalid keyword argument for this functiont   keyt   sec2t   stdiot   coret   familyt	   memb_faplt   mpiot   infos   Unknown driver type "%s"N(   R	   t   createt   FILE_ACCESSt   NoneR   R   t   LIBVER_LATESTt   set_libver_boundst   syst   platformt   formatt   nextt   itert	   TypeErrort   set_fapl_sec2t   set_fapl_stdiot   set_fapl_coret   set_fapl_familyt   copyt
   setdefaultt   mpi4pyt   MPIt   Infot   set_fapl_mpiot
   ValueError(   t   drivert   libvert   kwdst   plistt   lowt   hight   msg(    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyt	   make_fapl,   s4    
'	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    R3   t   intR(   R	   R   t   FILE_CREATEt   set_userblockR   t
   ACC_RDONLYt   swmr_supportt   ACC_SWMR_READt   opent   ACC_RDWRt   ACC_EXCLt	   ACC_TRUNCt   IOErrort   get_create_plistt   get_userblockt   close(	   t   namet   modet   userblock_sizeR=   R>   t   swmrt   flagst   fidt   existing_fcpl(    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyt   make_fidQ   sX    	$$(,&
t   Filec           B@  sj  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 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 „ Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   s&   
        Represents an HDF5 file.
    c         C@  s!   d d l  m } | j |  d ƒ S(   s$    Attributes attached to this object i   (   t   attrst   /(   t    RX   t   AttributeManager(   t   selfRX   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyRX   ”   s    c         C@  s   t  t j |  j ƒ ƒ S(   s   File name on disk(   R   R   t   get_nameRT   (   R\   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyt   filename   s    c         C@  sk   i d 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   R   R   t   mpiposixt   unknown(   R   t   SEC2t   STDIOt   COREt   FAMILYt   WINDOWSt   MPIOt   MPIPOSIXt   getRT   t   get_access_plistt
   get_driver(   R\   t   drivers(    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyR4   £   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   RD   RH   Rh   RT   t
   get_intent(   R\   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyRP   ­   s    c         C@  s   |  j  S(   s"   File ID (backwards compatibility) (   t   id(   R\   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyRT   ´   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,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pys	   <genexpr>¿   s    (   Rm   Ri   t   get_libver_boundst   tuple(   R\   t   bounds(    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyR5   º   s    c         C@  s   |  j  j ƒ  } | j ƒ  S(   s    User block size (in bytes) (   RT   RL   RM   (   R\   R>   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyRQ   Á   s    i   i   i	   c         C@  s   |  j  j ƒ  S(   s(    Set/get MPI-IO atomic mode
            (   Rm   t   get_mpi_atomicity(   R\   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyt   atomicË   s    c         C@  s   |  j  j | ƒ d  S(   N(   Rm   t   set_mpi_atomicity(   R\   t   value(    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyRs   Ò   s    c         C@  s   |  j  S(   s-    Controls single-writer multiple-reader mode (   t
   _swmr_mode(   R\   (    (    s,   /tmp/pip-build-isqEY4/h5py/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.(   Rm   t   start_swmr_writet   TrueRv   R3   (   R\   Ru   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyRw   Þ   s    c   
      K@  sÐ   | r t  r t d ƒ ‚ n  t ¨ t | t j ƒ rG t j | ƒ } no t t	 | ƒ ƒ } t
 | | |  }	 t | | | |	 d | ƒ} t  r¶ t |  _ | r¶ | d k r¶ t |  _ q¶ n  t j |  | ƒ Wd QXd S(   sU  Create a new file object.

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

        name
            Name of the file on disk.  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'.
        Additional keywords
            Passed on to the selected file driver.
        sE   The SWMR feature is not available in this version of the HDF5 libraryRR   R<   N(   RE   R3   R   t
   isinstanceR   t   ObjectIDR
   t   get_file_idR   R   R;   RV   t   FalseRv   Ry   R   t   __init__(
   R\   RO   RP   R4   R5   RQ   RR   R6   RT   R=   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyR~   è   s    	c         C@  s#  t  t j |  j t j ƒ } t j |  j t j ƒ } g  | D]* } t j | ƒ j |  j j k r? | ^ q? } g  | D]* } t j | ƒ j |  j j k rv | ^ qv } x+ | D]# } x | j rÏ t j | ƒ q¶ Wq­ Wx+ | D]# } x | j rý t j | ƒ qä WqÛ W|  j j	 ƒ  t
 j ƒ  Wd QXd S(   s2    Close the file.  All open objects become invalid N(   R   R   t   get_obj_idsRm   t   OBJ_FILER
   R|   t   validt   dec_refRN   R   t   nonlocal_close(   R\   t   id_listt	   file_listR   t   id_(    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyRN     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   flushRT   (   R\   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyR‡   0  s    c         C@  s   |  S(   N(    (   R\   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyt	   __enter__6  s    c         G@  s   |  j  r |  j ƒ  n  d  S(   N(   Rm   RN   (   R\   t   args(    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyt   __exit__:  s    	c         C@  sŠ   |  j  s t j d ƒ } nU |  j } t | t ƒ rH | j d d ƒ } n  t j d ƒ t j j	 | ƒ |  j
 f } t j r† | j d ƒ S| S(   Ns   <Closed HDF5 file>t   utf8t   replaces   <HDF5 file "%s" (mode %s)>(   Rm   t   sixt   uR^   Rz   t   bytest   decodet   ost   patht   basenameRP   t   PY2t   encode(   R\   R<   R^   (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyt   __repr__?  s    			(   i   i   i	   N(   t   __name__t
   __module__t   __doc__t   propertyR   RX   R^   R4   RP   RT   R5   RQ   t   mpit   hdf5_versionRs   t   setterRE   Rw   R    R}   R~   RN   R‡   Rˆ   RŠ   R–   (    (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyRW   Ž   s>   		/		(*   R™   t
   __future__R    R#   R‘   t   compatR   R   R   R   t   baseR   R   t   groupR   RZ   R   R   R	   R
   R   R   R   t
   get_configR›   t   hdf5_version_tupleRœ   R}   RE   t   swmr_min_hdf5_versionRy   R/   t   LIBVER_EARLIESTR!   R   t   dictt	   iteritemsRn   R;   R    RV   RW   (    (    (    s,   /tmp/pip-build-isqEY4/h5py/h5py/_hl/files.pyt   <module>   s.   .		%=