σ
ΎχXc           @@  s   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z m Z d d l m	 Z	 d	 e j
 f d
     YZ d e j e j
 f d     YZ d S(   s3   
    Implements support for HDF5 dimension scales.
i    (   t   absolute_importi   (   t   h5dsi   (   t   base(   t   philt	   with_phil(   t   Datasett   DimensionProxyc           B@  sΡ   e  Z d  Z e e d     Z e j e d     Z e d    Z e d    Z e d    Z	 e d    Z
 e d    Z e d    Z d	   Z d
   Z d   Z d   Z d   Z e d    Z RS(   s-   
        Represents an HDF5 "dimension".
    c         C@  sM   y. t  |  j  } |  j | j d |  j  SWn t t f k
 rH d SXd S(   s&    Get or set the dimension scale label t   DIMENSION_LABELSt    N(   R   t   _idt   _dt   attrst
   _dimensiont   KeyErrort
   IndexError(   t   selft   dset(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   label   s
    c         C@  s&   t  j |  j |  j |  j |   d  S(   N(   R   t	   set_labelR	   R   t   _e(   R   t   val(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR   (   s    c         C@  s   | |  _  | |  _ d  S(   N(   R	   R   (   R   t   id_t	   dimension(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   __init__.   s    	c         C@  s   t  t |   |  j |  j f  S(   N(   t   hasht   typeR	   R   (   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   __hash__3   s    c         C@  s   t  |   t  |  k S(   N(   R   (   R   t   other(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   __eq__7   s    c         c@  s    x |  j    D] } | Vq Wd  S(   N(   t   keys(   R   t   k(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   __iter__;   s    c         C@  s   t  j |  j |  j  S(   N(   R   t   get_num_scalesR	   R   (   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   __len__@   s    c         @  s   t    t  rB g  } t j  j  j | j d  t |    S   f d   } t j  j  j | d  } | d  k r t	     n  t |  Sd  S(   Ni    c         @  s&   t  j |    j    k r" |  Sd S(   s-    Iterate over scales to find a matching name N(   R   t   get_scale_nameR   (   t   dsid(   t   itemR   (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   fM   s    (
   t
   isinstancet   intR   t   iterateR	   R   t   appendR   t   NoneR   (   R   R$   t   scalesR%   t   res(    (   R$   R   s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   __getitem__D   s    c         C@  s-   t  ! t j |  j | j |  j  Wd QXd S(   sw    Attach a scale to this dimension.
        
        Provide the Dataset of the scale you would like to attach.
        N(   R   R   t   attach_scaleR	   t   idR   (   R   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR.   W   s    c         C@  s-   t  ! t j |  j | j |  j  Wd QXd S(   sy    Remove a scale from this dimension.
        
        Provide the Dataset of the scale you would like to remove.
        N(   R   R   t   detach_scaleR	   R/   R   (   R   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR0   _   s    c      	   C@  s   t  t g  } t |   d k rA t j |  j |  j | j d  n  g  | D]* } |  j t j |   t	 |  f ^ qH SWd QXd S(   sX    Get a list of (name, Dataset) pairs with all scales on this
        dimension.
        i    N(
   R   t   lenR   R(   R	   R   R)   R
   R"   R   (   R   R+   t   x(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   itemsg   s    "c         C@  s4   t  ( g  |  j   D] \ } } | ^ q SWd QXd S(   s7    Get a list of names for the scales on this dimension. N(   R   R3   (   R   t   keyt   _(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR   x   s    c         C@  s4   t  ( g  |  j   D] \ } } | ^ q SWd QXd S(   s5    Get a list of Dataset for scales on this dimension. N(   R   R3   (   R   R5   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   values}   s    c         C@  s-   |  j  s d Sd |  j |  j t |  j   f S(   Ns"   <Dimension of closed HDF5 dataset>s)   <"%s" dimension %d of HDF5 dataset at %s>(   R	   R   R   R/   (   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   __repr__   s    	(   t   __name__t
   __module__t   __doc__t   propertyR   R   t   setterR   R   R   R   R!   R-   R.   R0   R3   R   R6   R7   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR      s"   					t   DimensionManagerc           B@  se   e  Z d  Z e d    Z e d    Z e d    Z e d    Z e d    Z d d  Z	 RS(   sΥ   
        Represents a collection of dimension associated with a dataset.
        
        Like AttributeManager, an instance of this class is returned when
        accessing the ".dims" property on a Dataset.
    c         C@  s   | j  |  _ d S(   s    Private constructor.
        N(   R/   R	   (   R   t   parent(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR      s    c         C@  s5   | t  |   d k r% t d   n  t |  j |  S(   s#    Return a Dimension object
        i   s   Index out of range(   R1   R   R   R	   (   R   t   index(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR-      s    c         C@  s   t  t |  j  j  S(   s3    Number of dimensions associated with the dataset. (   R1   R   R	   t   shape(   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR!   ‘   s    c         c@  s*   x# t  t |    D] } |  | Vq Wd S(   s    Iterate over the dimensions. N(   t   rangeR1   (   R   t   i(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR   ¦   s    c         C@  s   |  j  s d Sd t |  j   S(   Ns#   <Dimensions of closed HDF5 dataset>s!   <Dimensions of HDF5 object at %s>(   R	   R/   (   R   (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR7   ¬   s    	R   c         C@  s-   t  ! t j | j |  j |   Wd QXd S(   sw    Create a new dimension, from an initial scale.
        
        Provide the dataset and a name for the scale.
        N(   R   R   t	   set_scaleR/   R   (   R   R   t   name(    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   create_scale²   s    (
   R8   R9   R:   R   R   R-   R!   R   R7   RE   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyR=      s   N(   R:   t
   __future__R    R   R   R   R   R   t   datasetR   t   CommonStateObjectR   t   MappingHDF5R=   (    (    (    s+   /tmp/pip-build-isqEY4/h5py/h5py/_hl/dims.pyt   <module>   s   t