3
_½µ_.  ã               @   st   d Z ddl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
 G d
d„ dejƒZG dd„ dejƒZdS )z3
    Implements support for HDF5 dimension scales.
é    Né   )Úh5ds)ÚH5pyDeprecationWarningé   )Úbase)ÚphilÚ	with_phil)ÚDatasetc               @   s®   e Zd ZdZeedd„ ƒƒZejedd„ ƒƒZedd„ ƒZedd„ ƒZ	ed	d
„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdS )ÚDimensionProxyz-
        Represents an HDF5 "dimension".
    c             C   s8   yt | jƒ}|jd | j S  ttfk
r2   dS X dS )z& Get or set the dimension scale label ZDIMENSION_LABELSÚ N)r	   Ú_idÚattrsÚ
_dimensionÚKeyErrorÚ
IndexError)ÚselfÚdset© r   ú//tmp/pip-install-xpigntgx/h5py/h5py/_hl/dims.pyÚlabel   s
    
zDimensionProxy.labelc             C   s   t j| j| j| j|ƒƒ d S )N)r   Z	set_labelr   r   Ú_e)r   Úvalr   r   r   r   )   s    c             C   s   || _ || _d S )N)r   r   )r   Zid_Z	dimensionr   r   r   Ú__init__/   s    zDimensionProxy.__init__c             C   s   t t| ƒ| j| jfƒS )N)ÚhashÚtyper   r   )r   r   r   r   Ú__hash__4   s    zDimensionProxy.__hash__c             C   s   t | ƒt |ƒkS )N)r   )r   Úotherr   r   r   Ú__eq__8   s    zDimensionProxy.__eq__c             c   s   x| j ƒ D ]
}|V  q
W d S )N)Úkeys)r   Úkr   r   r   Ú__iter__<   s    zDimensionProxy.__iter__c             C   s   t j| j| jƒS )N)r   Zget_num_scalesr   r   )r   r   r   r   Ú__len__A   s    zDimensionProxy.__len__c                sn   t ˆ tƒr0g }tjˆjˆj|jdƒ t|ˆ  ƒS ‡ ‡fdd„}tjˆjˆj|dƒ}|d krbtˆ ƒ‚t|ƒS d S )Nr   c                s   t j| ƒˆjˆ ƒkr| S dS )z- Iterate over scales to find a matching name N)r   Úget_scale_namer   )Zdsid)Úitemr   r   r   ÚfN   s    z%DimensionProxy.__getitem__.<locals>.f)	Ú
isinstanceÚintr   Úiterater   r   Úappendr	   r   )r   r#   Úscalesr$   Úresr   )r#   r   r   Ú__getitem__E   s    
zDimensionProxy.__getitem__c             C   s(   t � tj| j|j| jƒ W dQ R X dS )zo Attach a scale to this dimension.

        Provide the Dataset of the scale you would like to attach.
        N)r   r   Úattach_scaler   Úidr   )r   r   r   r   r   r,   X   s    zDimensionProxy.attach_scalec             C   s(   t � tj| j|j| jƒ W dQ R X dS )zq Remove a scale from this dimension.

        Provide the Dataset of the scale you would like to remove.
        N)r   r   Údetach_scaler   r-   r   )r   r   r   r   r   r.   `   s    zDimensionProxy.detach_scalec                sH   t �: g }tˆ ƒdkr,tjˆ jˆ j|jdƒ ‡ fdd„|D ƒS Q R X dS )zX Get a list of (name, Dataset) pairs with all scales on this
        dimension.
        r   c                s$   g | ]}ˆ j tj|ƒƒt|ƒf‘qS r   )Z_dr   r"   r	   )Ú.0Úx)r   r   r   ú
<listcomp>u   s   z(DimensionProxy.items.<locals>.<listcomp>N)r   Úlenr   r'   r   r   r(   )r   r)   r   )r   r   Úitemsh   s    
zDimensionProxy.itemsc          	   C   s"   t � dd„ | jƒ D ƒS Q R X dS )z7 Get a list of names for the scales on this dimension. c             S   s   g | ]\}}|‘qS r   r   )r/   ÚkeyÚ_r   r   r   r1   |   s    z'DimensionProxy.keys.<locals>.<listcomp>N)r   r3   )r   r   r   r   r   y   s    zDimensionProxy.keysc          	   C   s"   t � dd„ | jƒ D ƒS Q R X dS )z5 Get a list of Dataset for scales on this dimension. c             S   s   g | ]\}}|‘qS r   r   )r/   r5   r   r   r   r   r1   �   s    z)DimensionProxy.values.<locals>.<listcomp>N)r   r3   )r   r   r   r   Úvalues~   s    zDimensionProxy.valuesc             C   s"   | j s
dS d| j| jt| j ƒf S )Nz"<Dimension of closed HDF5 dataset>z)<"%s" dimension %d of HDF5 dataset at %s>)r   r   r   r-   )r   r   r   r   Ú__repr__ƒ   s    zDimensionProxy.__repr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   Úsetterr   r   r   r    r!   r+   r,   r.   r3   r   r6   r7   r   r   r   r   r
      s"   r
   c               @   sV   e Zd ZdZedd„ ƒZedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZ	ddd„Z
dS )ÚDimensionManagerzÍ
        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 )z Private constructor.
        N)r-   r   )r   Úparentr   r   r   r   ”   s    zDimensionManager.__init__c             C   s$   |t | ƒd krtdƒ‚t| j|ƒS )z# Return a Dimension object
        r   zIndex out of range)r2   r   r
   r   )r   Úindexr   r   r   r+   š   s    zDimensionManager.__getitem__c             C   s   t t| jƒjƒS )z3 Number of dimensions associated with the dataset. )r2   r	   r   Úshape)r   r   r   r   r!   ¢   s    zDimensionManager.__len__c             c   s$   xt t| ƒƒD ]}| | V  qW dS )z Iterate over the dimensions. N)Úranger2   )r   Úir   r   r   r    §   s    zDimensionManager.__iter__c             C   s   | j s
dS dt| j ƒ S )Nz#<Dimensions of closed HDF5 dataset>z!<Dimensions of HDF5 object at %s>)r   r-   )r   r   r   r   r7   ­   s    zDimensionManager.__repr__r   c             C   s   t jdtdd� |j|ƒ dS )zo Create a new dimension, from an initial scale.

        Provide the dataset and a name for the scale.
        zTother_ds.dims.create_scale(ds, name) is deprecated. Use ds.make_scale(name) instead.r   )Ú
stacklevelN)ÚwarningsÚwarnr   Z
make_scale)r   r   Únamer   r   r   Úcreate_scale³   s    
zDimensionManager.create_scaleN)r   )r8   r9   r:   r;   r   r   r+   r!   r    r7   rH   r   r   r   r   r>   ‹   s   r>   )r;   rE   r   r   Zh5py_warningsr   r   r   r   Zdatasetr	   ZCommonStateObjectr
   r>   r   r   r   r   Ú<module>   s   t