a
    Sic$                     @   s   d Z ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
 ddlmZmZ d	d
lmZmZmZmZmZ d	dlmZ G dd deddZdZejdd Zee jkrdZdd ZG dd dZG dd dZdS )z=
    High-level interface for creating HDF5 virtual datasets
    )deepcopy)
namedtupleN   filename_encode)Datatype)SimpleSelectionselect   )h5dh5ph5sh5th5)versionc                   @   s   e Zd ZdZdS )VDSmapzNDefines a region in a virtual dataset mapping to part of a source dataset
    N)__name__
__module____qualname____doc__ r   r   H/var/www/html/django/DPS/env/lib/python3.9/site-packages/h5py/_hl/vds.pyr      s   r   )vspace	file_nameZ	dset_name	src_spaceF   Tc                 C   s   t |tr|n|f}|  }|tjkr|  r|  }t|}d}|  \}}}}	t	|D ]R\}
}t |t
r|jtjkrt|}|
| }tj||< t|}qZ|tu rZ|| }qZ| ||||	 dS )zz
    Converts the space with the given key. Mainly used to allow unlimited
    dimensions in virtual space selection.
    r   N)
isinstancetupleget_select_typer   SEL_HYPERSLABSis_regular_hyperslabget_simple_extent_ndimslenget_regular_hyperslab	enumerateslicestop	UNLIMITEDlistEllipsisselect_hyperslab)spacekey	type_coderanknargsZ
idx_offsetstartstridecountblockislcountsidxr   r   r   _convert_space_for_key'   s"    



r8   c                   @   s.   e Zd ZdZd	ddZedd Zdd ZdS )
VirtualSourcea  Source definition for virtual data sets.

    Instantiate this class to represent an entire source dataset, and then
    slice it to indicate which regions should be used in the virtual dataset.

    path_or_dataset
        The path to a file, or an h5py dataset. If a dataset is given,
        no other parameters are allowed, as the relevant values are taken from
        the dataset instead.
    name
        The name of the source dataset within the file.
    shape
        A tuple giving the shape of the dataset.
    dtype
        Numpy dtype or string.
    maxshape
        The source dataset is resizable up to this shape. Use None for
        axes you want to be unlimited.
    Nc           
      C   s   ddl m} t||rldd ||||d D }|rFtdj|d|}|jj}	|j}|j	}|j
}|j}nF|}	|d u rtd|d u rtd	nt|tr|f}t|tr|f}|	| _|| _|| _
|d u r|| _ntd
d |D | _t|| _d S )Nr   )Datasetc                 S   s   i | ]\}}|d ur||qS Nr   ).0kvr   r   r   
<dictcomp>`   s   z*VirtualSource.__init__.<locals>.<dictcomp>)nameshapedtypemaxshapezhIf a Dataset is passed as the first argument then no other arguments may be passed.  You passed {failed})failedz?The name parameter is required when specifying a source by pathz@The shape parameter is required when specifying a source by pathc                 S   s   g | ]}|d u rt jn|qS r;   r   r'   )r<   ixr   r   r   
<listcomp>   s   z*VirtualSource.__init__.<locals>.<listcomp>)datasetr:   r   items	TypeErrorformatfilefilenamer@   rA   rB   rC   intpathr   r   sel)
selfZpath_or_datasetr@   rA   rB   rC   r:   rD   dsrO   r   r   r   __init__\   sF    




zVirtualSource.__init__c                 C   s   | j jS r;   )rP   array_shape)rQ   r   r   r   rA      s    zVirtualSource.shapec                 C   s,   t | }t| j|d d|_t|jj| |S )NrH   )copyr	   rA   rP   r8   id)rQ   r,   tmpr   r   r   __getitem__   s    zVirtualSource.__getitem__)NNNN)r   r   r   r   rS   propertyrA   rY   r   r   r   r   r9   H   s     
,
r9   c                   @   sF   e Zd ZdZdddZdd Zeeddd	Zd
d Z	dddZ
dS )VirtualLayouta!  Object for building a virtual dataset.

    Instantiate this class to define a virtual dataset, assign to slices of it
    (using VirtualSource objects), and then pass it to
    group.create_virtual_dataset() to add the virtual dataset to a file.

    This class does not allow access to the data; the virtual dataset must
    be created in a file before it can be used.

    shape
        A tuple giving the shape of the dataset.
    dtype
        Numpy dtype or string.
    maxshape
        The virtual dataset is resizable up to this shape. Use None for
        axes you want to be unlimited.
    filename
        The name of the destination file, if known in advance. Mappings from
        data in the same file will be stored with filename '.', allowing the
        file to be renamed later.
    Nc                 C   sR   t |tr|fn|| _|| _t |tr,|fn|| _|| _t | _t	tj
| _d S r;   )r   rN   rA   rB   rC   	_filenameset_src_filenamesr   createDATASET_CREATEdcpl)rQ   rA   rB   rC   rM   r   r   r   rS      s    zVirtualLayout.__init__c                 C   sf   t | j|d d}t|j| | |j| j}| j|j||j	
d|jj | jd u rb| j| d S )NrU   utf-8)r	   rA   r8   rW   _source_file_namerO   r\   ra   set_virtualr@   encoderP   r^   add)rQ   r,   sourcerP   src_filenamer   r   r   __setitem__   s    
zVirtualLayout.__setitem__)returnc                 C   s$   t | } |r| t |krdS t | S )N   .r   )rh   dst_filenamer   r   r   rc      s    zVirtualLayout._source_file_namec              	   C   s   t |}| jdur:|t | jkr4t|d| j| jS || jv rttj}t| j	 D ]F}| j
|}|| j|| ||| j|d| j| q^|S | jS dS )zGet the property list containing virtual dataset mappings

        If the destination filename wasn't known when the VirtualLayout was
        created, it is handled here.
        Nz != rb   )r   r\   	Exceptionra   r^   r   r_   r`   rangeget_virtual_countget_virtual_filenamerd   get_virtual_vspacerc   get_virtual_dsetnamere   get_virtual_srcspace)rQ   rl   Znew_dcplr4   rh   r   r   r   	_get_dcpl   s"    




zVirtualLayout._get_dcplc           	      C   s   |  |jj}|dur(|t|g | j}|durHtdd |D }t	| j
|}t| jtrl| jj}nt| j}tj|dd}tj|j||||dS )zA Return a new low-level dataset identifier for a virtual dataset Nc                 s   s    | ]}|d ur|nt jV  qd S r;   rE   )r<   mr   r   r   	<genexpr>       z-VirtualLayout.make_dataset.<locals>.<genexpr>r   )logical)r@   tidr+   ra   )rt   rL   rM   set_fill_valuenparrayrC   r   r   create_simplerA   r   rB   r   rW   r   	py_creater   r_   )	rQ   parentr@   	fillvaluera   rC   Zvirt_dspacery   rB   r   r   r   make_dataset   s    
zVirtualLayout.make_dataset)NN)N)r   r   r   r   rS   ri   staticmethodbytesrc   rt   r   r   r   r   r   r[      s   
	r[   )r   rV   r   collectionsr   numpyr{   compatr   datatyper   
selectionsr   r	    r   r   r   r   r   r   r   vds_supporthdf5_version_tuplehdf5_version
get_configvds_min_hdf5_versionr8   r9   r[   r   r   r   r   <module>
   s    !J