a
    Sic5=                     @   sr  d Z ddlmZmZmZmZmZ ddlZddlZddl	Z
ddlmZmZ ddlmZmZmZmZmZmZmZ ddlmZmZ d	d
 Zdd Zdd Zdd Zd/ddZdd Zdd Ze Z e Z!dd Z"G dd dZ#G dd dZ$G dd de#Z%G dd  d eZ&G d!d" d"eZ'G d#d$ d$eZ(G d%d& d&eZ)G d'd( d(e)eZ*G d)d* d*Z+d+d, Z,G d-d. d.e-Z.dS )0zJ
    Implements operations common to all high-level objects (File, etc.).
    )MappingMutableMappingKeysView
ValuesView	ItemsViewN   )phil	with_phil)h5dh5ih5rh5ph5fh5th5s   )fspathfilename_encodec                 C   sb   t J tjt| } tj| r>tt| W  d   S W d   dS 1 sT0    Y  dS )z@ Determine if a file is valid HDF5 (False if it doesn't exist). NF)	r   ospathabspathr   isfiler   is_hdf5r   )fname r   I/var/www/html/django/DPS/env/lib/python3.9/site-packages/h5py/_hl/base.pyr      s
    r   c                 C   s   t | tjrH| jjdkrBt| jsBt| jsBdd | jD }qndS n&t | t	t
frfdd | D }nt| S t|dkr~dS | S )a  Find the item type of a simple object or collection of objects.

    E.g. [[['a']]] -> str

    The focus is on collections where all items have the same type; we'll return
    None if that's not the case.

    The aim is to treat numpy arrays of Python objects like normal Python
    collections, while treating arrays with specific dtypes differently.
    We're also only interested in array-like collections - lists and tuples,
    possibly nested - not things like sets or dicts.
    Oc                 S   s   h | ]}t |qS r   )type.0er   r   r   	<setcomp><       z!find_item_type.<locals>.<setcomp>Nc                 S   s   h | ]}t |qS r   )find_item_typer   r   r   r   r!   @   r"   r   )
isinstancenpndarraydtypekindr   check_string_dtypecheck_vlen_dtypeflatlisttupler   lenpop)dataZ
item_typesr   r   r   r#   )   s    


r#   c                 C   s   t  t| tjr&tjW  d   S t| tjrFtjW  d   S t| }|t	u rptj
ddW  d   S |tu rt
 W  d   S W d   dS 1 s0    Y  dS )z Attempt to guess an appropriate dtype for the object, returning None
    if nothing is appropriate (or if it should be left up the the array
    constructor to figure out)
    Nascii)encoding)r   r$   r   RegionReferencer   regionref_dtype	Reference	ref_dtyper#   bytesstring_dtypestr)r0   	item_typer   r   r   guess_dtypeI   s    r;   c                 C   s*   | d u rdS t | } | jdko(| jdkS )NFfr   )r%   r'   r(   itemsize)dtr   r   r   is_float16_dtype^   s    
r?   c                 C   sX   t |r|}n"t| tjs(|dur(|}nt| }tj| d|d} |durT| j|d} | S )zDPrepare an array from data used to create a new dataset or attributeNC)orderr'   )r'   )r?   r$   r%   r&   r;   asarrayview)r0   Zspecified_dtypeas_dtyper   r   r   array_for_new_objectf   s    rE   c                  C   s2   t t j} t t j}|tj | | | S )z# Default link access property list )r   createLINK_ACCESSFILE_ACCESSset_fclose_degreer   CLOSE_STRONGset_elink_fapl)laplfaplr   r   r   default_lapl   s
    
rN   c                  C   s   t t j} | d | S )z% Default link creation property list T)r   rF   LINK_CREATEset_create_intermediate_group)lcplr   r   r   default_lcpl   s    
rR   c                 C   s   |    tjkrdS dS )z) Check if an object's dataspace is empty TF)	get_spaceget_simple_extent_typer   NULL)objr   r   r   is_empty_dataspace   s    rW   c                   @   s:   e Zd ZdZedd Zedd ZdddZd	d
 ZdS )CommonStateObjecta  
        Mixin class that allows sharing information between objects which
        reside in the same HDF5 file.  Requires that the host class have
        a ".id" attribute which returns a low-level ObjectID subclass.

        Also implements Unicode operations.
    c                 C   s   t S )zI Fetch the link access property list appropriate for this object
        )dlaplselfr   r   r   _lapl   s    zCommonStateObject._laplc                 C   s   t S )zK Fetch the link creation property list appropriate for this object
        )dlcplrZ   r   r   r   _lcpl   s    zCommonStateObject._lcplNc                    s~    fdd}|du r |rdS dS t |tr2tj}n8z|d}tj}W n" tyh   |d}tj}Y n0 |rz|||fS |S )aG   Encode a name according to the current file settings.

        Returns name, or 2-tuple (name, lcpl) if lcpl is True

        - Binary strings are always passed as-is, h5t.CSET_ASCII
        - Unicode strings are encoded utf8, h5t.CSET_UTF8

        If name is None, returns either None or (None, None) appropriately.
        c                    s    j  }||  |S )z3 Create an appropriate link creation property list )r^   copyset_char_encoding)codingrQ   rZ   r   r   get_lcpl   s    

z&CommonStateObject._e.<locals>.get_lcplN)NNr1   utf8)r$   r7   r   
CSET_ASCIIencodeUnicodeEncodeError	CSET_UTF8)r[   namerQ   rb   ra   r   rZ   r   _e   s    




zCommonStateObject._ec                 C   s0   |du rdS z| dW S  ty*   Y n0 |S )z Decode a name according to the current file settings.

        - Try to decode utf8
        - Failing that, return the byte string

        If name is None, returns None.
        Nrc   )decodeUnicodeDecodeError)r[   rh   r   r   r   _d   s    zCommonStateObject._d)N)	__name__
__module____qualname____doc__propertyr\   r^   ri   rl   r   r   r   r   rX      s   


!rX   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )_RegionProxya	  
        Proxy object which handles region references.

        To create a new region reference (datasets only), use slicing syntax:

            >>> newref = obj.regionref[0:10:2]

        To determine the target dataset shape from an existing reference:

            >>> shape = obj.regionref.shape(existingref)

        where <obj> may be any object in the file. To determine the shape of
        the selection in use on the target dataset:

            >>> selection_shape = obj.regionref.selection(existingref)
    c                 C   s   || _ |j| _d S N)rV   id)r[   rV   r   r   r   __init__   s    z_RegionProxy.__init__c                 C   sv   t | jtjstdddlm} t< |j| jj	|| j
d}t| jdtj|jW  d    S 1 sh0    Y  d S )Nz.Region references can only be made to datasetsr   
selections)dataset   .)r$   rt   r
   	DatasetID	TypeError rw   r   selectshaperV   r   rF   DATASET_REGION)r[   argsrw   	selectionr   r   r   __getitem__   s    z_RegionProxy.__getitem__c                 C   s<   t $ t|| j}|jW  d   S 1 s.0    Y  dS )z= Get the shape of the target dataspace referred to by *ref*. N)r   r   
get_regionrt   r~   )r[   refsidr   r   r   r~     s    z_RegionProxy.shapec                 C   sL   ddl m} t( t|| j}||W  d   S 1 s>0    Y  dS )zN Get the shape of the target dataspace selection referred to by *ref*
        r   rv   N)r|   rw   r   r   r   rt   Zguess_shape)r[   r   rw   r   r   r   r   r   	  s    z_RegionProxy.selectionN)rm   rn   ro   rp   ru   r   r~   r   r   r   r   r   rr      s
   rr   c                   @   s   e Zd ZdZedd Zeedd Zeedd Zeedd	 Z	eed
d Z
eedd Zedd Zedd Zedd Zedd Zdd ZeZdd Zdd ZdS )HLObjectz:
        Base class for high-level interface objects.
    c                 C   s@   ddl m} t || jW  d   S 1 s20    Y  dS )z4 Return a File instance associated with this object r   )filesN)r|   r   r   Filert   )r[   r   r   r   r   file  s    zHLObject.filec                 C   s   |  t| jS )z: Return the full name of this object.  None if anonymous. )rl   r   get_namert   rZ   r   r   r   rh     s    zHLObject.namec                 C   s$   | j du rtd| jt| j  S )zReturn the parent group of this object.

        This is always equivalent to obj.file[posixpath.dirname(obj.name)].
        ValueError if this object is anonymous.
        Nz*Parent of an anonymous object is undefined)rh   
ValueErrorr   	posixpathdirnamerZ   r   r   r   parent%  s    
zHLObject.parentc                 C   s   | j S )z2 Low-level identifier appropriate for this object _idrZ   r   r   r   rt   1  s    zHLObject.idc                 C   s   t | jdt jS )z+ An (opaque) HDF5 reference to this object ry   )r   rF   rt   OBJECTrZ   r   r   r   r   7  s    zHLObject.refc                 C   s   t | S )az  Create a region reference (Datasets only).

        The syntax is regionref[<slices>]. For example, dset.regionref[...]
        creates a region reference in which the whole dataset is selected.

        Can also be used to determine the shape of the referenced dataset
        (via .shape property), or the shape of the selection (via the
        .selection property).
        )rr   rZ   r   r   r   	regionref=  s    zHLObject.regionrefc                 C   s>   ddl m} t || W  d   S 1 s00    Y  dS )z$ Attributes attached to this object r   )attrsN)r|   r   r   AttributeManager)r[   r   r   r   r   r   K  s    zHLObject.attrsc                 C   s
   || _ dS )z3 Setup this object, given its low-level identifier Nr   )r[   oidr   r   r   ru   R  s    zHLObject.__init__c                 C   s
   t | jS rs   )hashrt   rZ   r   r   r   __hash__W  s    zHLObject.__hash__c                 C   s   t |dr| j|jkS tS )Nrt   )hasattrrt   NotImplementedr[   otherr   r   r   __eq__[  s    
zHLObject.__eq__c                 C   s2   t  t| jW  d    S 1 s$0    Y  d S rs   )r   boolrt   rZ   r   r   r   __bool__a  s    zHLObject.__bool__c                 C   s   t ddS )aI  Disable pickle.

        Handles for HDF5 objects can't be reliably deserialised, because the
        recipient may not have access to the same files. So we do this to
        fail early.

        If you really want to pickle h5py objects and can live with some
        limitations, look at the h5pickle project on PyPI.
        h5py objects cannot be pickledNr{   rZ   r   r   r   __getnewargs__f  s    
zHLObject.__getnewargs__c                 C   s   t dd S )Nr   r   rZ   r   r   r   __getstate__r  s    zHLObject.__getstate__N)rm   rn   ro   rp   rq   r   r	   rh   r   rt   r   r   r   ru   r   r   r   __nonzero__r   r   r   r   r   r   r     s<   





r   c                   @   s    e Zd Zdd Zdd ZeZdS )KeysViewHDF5c                 C   s   d t| S )Nz<KeysViewHDF5 {}>)formatr,   rZ   r   r   r   __str__  s    zKeysViewHDF5.__str__c                 c   s   t | jE d H  d S rs   )reversed_mappingrZ   r   r   r   __reversed__  s    zKeysViewHDF5.__reversed__N)rm   rn   ro   r   r   __repr__r   r   r   r   r     s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ValuesViewHDF5z
        Wraps e.g. a Group or AttributeManager to provide a value view.

        Note that __contains__ will have poor performance as it has
        to scan all the links or attributes.
    c                 C   sX   t @ | jD ]&}|| j|kr W d    dS qW d    dS 1 sJ0    Y  d S NTFr   r   get)r[   valuekeyr   r   r   __contains__  s
    
zValuesViewHDF5.__contains__c                 c   sB   t * | jD ]}| j|V  qW d    n1 s40    Y  d S rs   r   r[   r   r   r   r   __iter__  s    
zValuesViewHDF5.__iter__c                 c   sF   t . t| jD ]}| j|V  qW d    n1 s80    Y  d S rs   r   r   r   r   r   r   r   r   r     s    zValuesViewHDF5.__reversed__Nrm   rn   ro   rp   r   r   r   r   r   r   r   r     s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ItemsViewHDF5zN
        Wraps e.g. a Group or AttributeManager to provide an items view.
    c                 C   sZ   t B |\}}|| jv r6|| j|kW  d    S W d    dS 1 sL0    Y  d S )NFr   )r[   itemr   valr   r   r   r     s
    
zItemsViewHDF5.__contains__c                 c   sF   t . | jD ]}|| j|fV  qW d    n1 s80    Y  d S rs   r   r   r   r   r   r     s    
zItemsViewHDF5.__iter__c                 c   sJ   t 2 t| jD ]}|| j|fV  qW d    n1 s<0    Y  d S rs   r   r   r   r   r   r     s    zItemsViewHDF5.__reversed__Nr   r   r   r   r   r     s   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )MappingHDF5a  
        Wraps a Group, AttributeManager or DimensionManager object to provide
        an immutable mapping interface.

        We don't inherit directly from MutableMapping because certain
        subclasses, for example DimensionManager, are read-only.
    c                 C   s   t | S )z# Get a view object on member names )r   rZ   r   r   r   keys  s    zMappingHDF5.keysc                 C   s   t | S )z% Get a view object on member objects )r   rZ   r   r   r   values  s    zMappingHDF5.valuesc                 C   s   t | S )z# Get a view object on member items )r   rZ   r   r   r   items  s    zMappingHDF5.itemsc                 C   s   t |  S )z: Custom tab completions for __getitem__ in IPython >=5.0. )sortedr   rZ   r   r   r   _ipython_key_completions_  s    z%MappingHDF5._ipython_key_completions_N)rm   rn   ro   rp   r   r   r   r   r   r   r   r   r     s
   r   c                   @   s   e Zd ZdZdS )MutableMappingHDF5z
        Wraps a Group or AttributeManager object to provide a mutable
        mapping interface, in contrast to the read-only mapping of
        MappingHDF5.
    N)rm   rn   ro   rp   r   r   r   r   r     s   r   c                   @   s0   e Zd ZdZdZdZdd Zdd Zdd ZdS )	Emptyz
        Proxy object to represent empty/null dataspaces (a.k.a H5S_NULL).

        This can have an associated dtype, but has no shape or data. This is not
        the same as an array with shape (0,).
    Nc                 C   s   t || _d S rs   )r%   r'   )r[   r'   r   r   r   ru     s    zEmpty.__init__c                 C   s   t |tr| j|jkrdS dS r   )r$   r   r'   r   r   r   r   r     s    zEmpty.__eq__c                 C   s   d | jS )NzEmpty(dtype={0!r}))r   r'   rZ   r   r   r   r     s    zEmpty.__repr__)	rm   rn   ro   rp   r~   sizeru   r   r   r   r   r   r   r     s   r   c                 C   s   d}| D ]}||9 }q|S )zCalculate a numeric product

    For small amounts of data (e.g. shape tuples), this simple code is much
    faster than calling numpy.prod().
    r   r   )numsprodnr   r   r   product  s    
r   c                   @   s   e Zd Zdd Zdd ZdS )cached_propertyc                 C   s   t |d| _|| _d S )Nrp   )getattrrp   func)r[   r   r   r   r   ru     s    zcached_property.__init__c                 C   s(   |d u r| S |  | }|j| j j< |S rs   )r   __dict__rm   )r[   rV   clsr   r   r   r   __get__  s    zcached_property.__get__N)rm   rn   ro   ru   r   r   r   r   r   r     s   r   )N)/rp   collections.abcr   r   r   r   r   r   r   numpyr%   _objectsr   r	   r|   r
   r   r   r   r   r   r   compatr   r   r   r#   r;   r?   rE   rN   rR   rY   r]   rW   rX   rr   r   r   r   r   r   r   r   r   objectr   r   r   r   r   <module>
   s8   $
 
	I.n	