
    d?                    $   d Z ddlZddlZddlZddlZddlZddlZddlm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mZmZmZmZmZmZmZ dd
lm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& ddl'm(Z( ddl)m*Z*m+Z+ ddl,m-Z-m.Z. ddl,m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddlm>Z> ddl?m@Z@ ddlmAZA ddlBmCZCmDZD ddlEmFZF ddlGmHZHmIZI dZJg ZK G d d           ZL eL            ZMddd!d"d#d$d%ZNg d%ZOd&ZPd'ZQd(ZR eeQeR          ZSeSZTd)ZU eeTeU          ZVeSZWd*ZX eeWeX          ZYeYZZd+Z[ eeZe[          Z\e\Z]d,Z^ ee]e^          Z_d- Z`d@d/Za ejb                    Zc ed eeefecg                    d0          d         g                    d1                              Zhehd2k     rd3nd4ZidAd7Zj G d8 d9          Zk G d: d;el          Zm G d< d=          Zn G d> d?ejo                  Zo ejp        eMjq                   dS )BaJ  Create PyTables files and the object tree.

This module support importing generic HDF5 files, on top of which
PyTables files are created, read or extended. If a file exists, an
object tree mirroring their hierarchical structure is created in memory.
File class offer methods to traverse the tree, as well as to create new
nodes.

    N)defaultdict)Path   )hdf5extension)utilsextension)
parameters)ClosedFileErrorFileModeError	NodeErrorNoSuchNodeErrorUndoRedoErrorClosedNodeErrorPerformanceWarning)get_class_by_name)	join_path
split_path)undoredo)IsDescriptionUInt8Col	StringColdescr_from_dtypedtype_from_descr)Filters)NodeNotLoggedMixin)Group	RootGroup)TransactionGroupGTransactionGMarkG)Leaf)Array)CArray)EArray)VLArray)Table)linkextension)detect_number_of_cores)lrucacheextension)	flavor_ofarray_as_internal)Atom)SoftLinkExternalLinkz2.1c                   d    e Zd Zd Zed             Zed             Zd Zd Zd Z	d Z
d Zd	 Zd
S )_FileRegistryc                 ^    t          t                    | _        t                      | _        d S N)r   set_name_mapping	_handlersselfs    +lib/python3.11/site-packages/tables/file.py__init__z_FileRegistry.__init__K   s!    (--    c                 *    t          | j                  S r2   )listr4   r6   s    r8   	filenamesz_FileRegistry.filenamesO   s    D&'''r:   c                     | j         S r2   )r5   r6   s    r8   handlersz_FileRegistry.handlersS   s     ~r:   c                 *    t          | j                  S r2   )lenr5   r6   s    r8   __len__z_FileRegistry.__len__X   s    4>"""r:   c                     || j         v S r2   )r=   r7   filenames     r8   __contains__z_FileRegistry.__contains__[   s    4>))r:   c                     | j         |j                                     |           | j                            |           d S r2   )r4   rE   addr5   )r7   handlers     r8   rH   z_FileRegistry.add^   s=    7+,009997#####r:   c                     |j         }| j        |                             |           | j        |         s| j        |= | j                            |           d S r2   )rE   r4   remover5   )r7   rI   rE   s      r8   rK   z_FileRegistry.removeb   s]    #8$++G444!(+ 	-"8,g&&&&&r:   c                     | j         |         S r2   )r4   rD   s     r8   get_handlers_by_namez"_FileRegistry.get_handlers_by_namej   s    !(++r:   c                    t          | j                  dk    }|rt          j                            d           t          | j                  }|D ]\}t          j                            d|j        z             |                                 t          j                            d           ]|r!t          j                            d           d S d S )Nr   zClosing remaining open files:z%s...done
)rA   r5   sysstderrwriter<   rE   close)r7   are_open_filesr?   filehs       r8   	close_allz_FileRegistry.close_alln   s    T^,,q0 	>J<==='' 	% 	%EJWu~5666KKMMMJV$$$$ 	#JT"""""	# 	#r:   N)__name__
__module____qualname__r9   propertyr=   r?   rB   rF   rH   rK   rM   rW    r:   r8   r0   r0   J   s           ( ( X(   X# # #* * *$ $ $' ' ', , ,
# 
# 
# 
# 
#r:   r0               )MARKCREATEREMOVEMOVEADDATTRDELATTRz1.0/_p_transactions	actionlogzt%dzm%dza%dc                 v    | 4t          | t                    s!t          dt          |           z            d S d S )NzQfilter parameter has to be None or a Filter instance and the passed type is: '%s')
isinstancer   	TypeErrortypefilterss    r8   _checkfiltersrp      sJ    Ow((  @W& ' ' 	' OOOr:   Fc                     t          | d          }	  |j        |fd|i| |                                 dS # |                                 w xY w)ai  An easy way of copying one PyTables file to another.

    This function allows you to copy an existing PyTables file named
    srcfilename to another file called dstfilename. The source file
    must exist and be readable. The destination file can be
    overwritten in place if existing by asserting the overwrite
    argument.

    This function is a shorthand for the :meth:`File.copy_file` method,
    which acts on an already opened file. kwargs takes keyword
    arguments used to customize the copying process. See the
    documentation of :meth:`File.copy_file` for a description of those
    arguments.

    rmode	overwriteN)	open_file	copy_filerT   )srcfilenamedstfilenameru   kwargssrcfilehs        r8   rw   rw      si    $ 3///H;FF)FvFFF 	s	   9 A-.)r         strictdefaultrr    c           	         t          j        |           } t          dk    r9| t          v r/t	          d| dt          j                    dt          d          nvt                              |           D ][}|j        }|dk    r|dk    rt	          d| z            |dv r|dk    rt	          d	| z            |d
k    rt	          d| z            \t          | ||||fi |S )a	  Open a PyTables (or generic HDF5) file and return a File object.

    Parameters
    ----------
    filename : str
        The name of the file (supports environment variable expansion).
        It is suggested that file names have any of the .h5, .hdf or
        .hdf5 extensions, although this is not mandatory.
    mode : str
        The mode to open the file. It can be one of the
        following:

            * *'r'*: Read-only; no data can be modified.
            * *'w'*: Write; a new file is created (an existing file
              with the same name would be deleted).
            * *'a'*: Append; an existing file is opened for reading and
              writing, and if the file does not exist it is created.
            * *'r+'*: It is similar to 'a', but the file must already
              exist.

    title : str
        If the file is to be created, a TITLE string attribute will be
        set on the root group with the given value. Otherwise, the
        title will be read from disk, and this will not have any effect.
    root_uep : str
        The root User Entry Point. This is a group in the HDF5 hierarchy
        which will be taken as the starting point to create the object
        tree. It can be whatever existing group in the file, named by
        its HDF5 path. If it does not exist, an HDF5ExtError is issued.
        Use this if you do not want to build the *entire* object tree,
        but rather only a *subtree* of it.

        .. versionchanged:: 3.0
           The *rootUEP* parameter has been renamed into *root_uep*.

    filters : Filters
        An instance of the Filters (see :ref:`FiltersClassDescr`) class
        that provides information about the desired I/O filters
        applicable to the leaves that hang directly from the *root group*,
        unless other filter properties are specified for these leaves.
        Besides, if you do not specify filter properties for child groups,
        they will inherit these ones, which will in turn propagate to
        child nodes.

    Notes
    -----
    In addition, it recognizes the (lowercase) names of parameters
    present in :file:`tables/parameters.py` as additional keyword
    arguments.
    See :ref:`parameter_files` for a detailed info on the supported
    parameters.

    .. note::

        If you need to deal with a large number of nodes in an
        efficient way, please see :ref:`LRUOptim` for more info and
        advices about the integrated node cache engine.

    r   z
The file 'z@' is already opened.  Please close it before reopening.  HDF5 v.z, FILE_OPEN_POLICY = ''rr   zJThe file '%s' is already opened, but not in read-only mode (as requested).)ar+ziThe file '%s' is already opened, but in read-only mode.  Please close it before reopening in append mode.wzQThe file '%s' is already opened.  Please close it before reopening in write mode.)
osfspath_FILE_OPEN_POLICY_open_files
ValueErrorr   get_hdf5_versionrM   rt   File)rE   rt   titleroot_uepro   rz   
filehandleomodes           r8   rv   rv      sR   z y""H H$$ {""* HHn=????%%%	'( ( ( # &::8DD 	K 	KJOEs{{u|| <>FGH H H $$# 02:;< < <
  ?AIJK K K  $xCCFCCCr:   c                   D    e Zd Zd Zd Zd Zd Z e            ZefdZ	dS )_NoCachec                     dS Nr   r\   r6   s    r8   rB   z_NoCache.__len__1  s    qr:   c                     dS NFr\   )r7   keys     r8   rF   z_NoCache.__contains__4  s    ur:   c                      t          g           S r2   )iterr6   s    r8   __iter__z_NoCache.__iter__7  s    Bxxr:   c                     d S r2   r\   )r7   r   values      r8   __setitem__z_NoCache.__setitem__:  s    r:   c                 6    || j         ur|S t          |          r2   )_NoCache__markerKeyError)r7   r   ds      r8   popz_NoCache.pop?  s     DM!!Hsmmr:   N)
rX   rY   rZ   rB   rF   r   r   objectr   r   r\   r:   r8   r   r   0  st                 vxxH!      r:   r   c                   (     e Zd Z fdZ fdZ xZS )
_DictCachec                     |dk     rt          d|z            || _        t                                                       d S )Nr   zInvalid number of slots: %d)r   nslotssuperr9   )r7   r   	__class__s     r8   r9   z_DictCache.__init__F  sC    A:::VCDDDr:   c                     t          |           | j        k    r"t          j        d| j        z  t                     t                                          ||           d S )Nzthe dictionary of node cache is exceeding the recommended maximum number (%d); be ready to see PyTables asking for *lots* of memory and possibly slow I/O.)rA   r   warningswarnr   r   r   )r7   r   r   r   s      r8   r   z_DictCache.__setitem__L  sb    t99t{""M: K! #5	6 6 6
 	C'''''r:   )rX   rY   rZ   r9   r   __classcell__r   s   @r8   r   r   E  sQ            ( ( ( ( ( ( ( ( (r:   r   c                   r     e Zd Zd fd	Zd ZddZd Zd Zd Zdd
Z	d Z
ed             ZddZd Z xZS )NodeManager@   Nc                    t                                                       t          j                    | _        |dk    rt          j        |          }n%|dk    rt                      }nt          |           }|| _	        || _
        d S r   )r   r9   weakrefWeakValueDictionaryregistryr)   	NodeCacher   r   cachenode_factory)r7   r   r   r   r   s       r8   r9   zNodeManager.__init__X  s    355A::%/77EEq[[JJEE w''E
 )r:   c                     ||j         }|| j        v rI| j        |         j        s| j        |= || j        |<   d S | j        |         |urt          d|z            d S || j        |<   d S )Nz6trying to register a node with an existing key: ``%s``)_v_pathnamer   	_v_isopenRuntimeError)r7   noder   s      r8   register_nodezNodeManager.register_nodej  s    ;"C$-=%/ AM#&%)c"""s#4//" $:<?$@ A A A 0/ "&DM#r:   c                     ||j         }|                     ||           || j        v r7| j                            |          }||ur|j        rt          d|z            || j        |<   d S )Nz3trying to cache a node with an existing key: ``%s``)r   r   r   r   r   r   )r7   r   r   oldnodes       r8   
cache_nodezNodeManager.cache_nodex  s    ;"C4%%%$*jnnS))Gd""w'8"" $:<?$@ A A A 
3r:   c                    | j                             |d           }|6|j        r|                     ||           |S t	          j        d|z             || j        v rg| j        |         }|t	          j        d|z             n@|j        r|                     ||           |S t	          j        d|z             | j        |= d }| j        r+|                     |          }|                     ||           |S )Nz(a closed node found in the cache: ``%s``z.None is stored in the registry for key: ``%s``z+a closed node found in the registry: ``%s``)r   r   r   r   r   r   r   r   )r7   r   r   s      r8   get_nodezNodeManager.get_node  s+   z~~c4((~ Pc*** H3NOOO$-=%D|  '),- . . . . c***  '),- . . .M#& 	'$$S))DOOD#&&&r:   c                 d    | j         | j        fD ] }||v r|                    |          }|||<   !d S r2   )r   r   r   )r7   oldkeynewkeyr   r   s        r8   rename_nodezNodeManager.rename_node  sH    j$-0 	% 	%Eyy(( $f	% 	%r:   c                 <    | j                             |d           dS )zRemove the node from cacheN)r   r   )r7   nodepaths     r8   drop_from_cachezNodeManager.drop_from_cache  s      	
x&&&&&r:   Tc                    |j         }|                     |           || j        v r|j        s
| j        |= dS dS |rH|j        rCt	          j        d|z             |                                 |                                 dS dS dS )zwDrop the `node`.

        Remove the node from the cache and, if it has no more references,
        close it.

        z3dropping a node that is not in the registry: ``%s``N)r   r   r   r   r   r   _g_pre_kill_hook_f_close)r7   r   check_unregisteredr   s       r8   	drop_nodezNodeManager.drop_node  s     #X&&&t}$$> ,M(+++, , 
	 
 ~   ')12 3 3 3 %%'''
	  
	 
   r:   c                    g }t          | j                                                  D ]O\  }}|j        s|                    |           "d|vr)t          |t                    r|                                 P|D ]W}|| j        v r2t          j
        d|z             | j                            |d            | j                            |           Xd S )N/_i_zclosed node the cache: ``%s``)r<   r   itemsr   appendrk   r!   flushr   r   r   r   )r7   closed_keyspathr   s       r8   flush_nodeszNodeManager.flush_nodes  s     t}224455 	! 	!JD$> !""4((((t##dD)) !JJLLL 	$ 	$Dtz!!=DEEE
tT***Md####	$ 	$r:   c                     | D ]x}	  ||          }|j         r|j        r	 t          |d          r|                                 n|                                 ~Y# t
          $ r Y ew xY w# t          $ r Y uw xY wd S )N_f_get_child)r   _v__deletinghasattr_g_closer   r   r   )	nodepathsr   r   r   s       r8   _close_nodeszNodeManager._close_nodes  s    ! 	 	Hx)) ~ ):  t^44 (& 	 	 	 D	    	 	s"   A,:A
A)(A),
A98A9rg   c                                         d          sdz   | j        }| j        }fd|D             }|                     ||j                   fd|D             }|                     ||j                   fd|D             }|                     ||j                   fd|D             }|                     ||j                   d S )Nrg   c                 F    g | ]}|                               rd |v|S r   
startswith.0r   prefixs     r8   
<listcomp>z-NodeManager.close_subtree.<locals>.<listcomp>  B     
 
 
v&&
+1+=+= +=+=+=r:   c                 >    g | ]}|                               |S r\   r   r   s     r8   r   z-NodeManager.close_subtree.<locals>.<listcomp>  s*    CCC$4??6+B+BCCCCr:   c                 F    g | ]}|                               rd |v|S r   r   r   s     r8   r   z-NodeManager.close_subtree.<locals>.<listcomp>  r   r:   c                 >    g | ]}|                               |S r\   r   r   s     r8   r   z-NodeManager.close_subtree.<locals>.<listcomp>  s*    FFF$doof.E.EFFFFr:   )endswithr   r   r   r   )r7   r   r   r   pathss    `   r8   close_subtreezNodeManager.close_subtree  s    s## 	"c\F
=
 
 
 
"
 
 
 	%+++ DCCC%CCC%+++
 
 
 
%
 
 
 	%... GFFF(FFF%.....r:   c                 P   | j         }| j        }t          |          }|D ]M}|                    |          }|j        r/|                    |j        d            |                                 N|r6|                                \  }}|j        r|                                 |4d S d S r2   )r   r   r<   r   r   r   r   popitem)r7   r   r   keysr   r   s         r8   shutdownzNodeManager.shutdown  s    =
 E{{ 	  	 C99S>>D~  T-t444 	  ((**IC~    	  	  	  	  	 r:   )r   Nr2   )Trg   )rX   rY   rZ   r9   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   s   @r8   r   r   W  s        ) ) ) ) ) )$& & &     B% % %' ' '       8$ $ $$   \</ / / /:             r:   r   c                      e Zd ZdZdZed             Zej        d             Zej        d             Zed             Z	e	j        d             Z	e	j        d             Z		 	 dOdZ
d Zd Zd Z	 	 dPdZ	 	 	 	 dQdZ	 	 	 dRdZ	 	 	 	 dSdZ	 	 	 	 dTdZ	 	 	 	 	 dUdZdVdZdVdZdVdZd ZdWdZd  ZdXd!Z	 	 dYd"Z	 	 dZd#ZdXd$Zd[d%Zd[d&Zd[d'Z d[d(Z!	 	 d\d)Z"dVd*Z#d[d+Z$d[d,Z%d- Z&d. Z'd]d/Z(d^d0Z)d1 Z*d2 Z+d3 Z,d4 Z-d5 Z.d6 Z/d7 Z0d8 Z1d9 Z2 e3d:;          fd<Z4d= Z5d[d>Z6d? Z7d@ Z8dA Z9dB Z:d[dCZ;d[dDZ<dE Z=dF Z>dG Z?dH Z@dI ZAdJ ZBdK ZCdL ZDdM ZEdN ZFdS )_r   aO  The in-memory representation of a PyTables file.

    An instance of this class is returned when a PyTables file is
    opened with the :func:`tables.open_file` function. It offers methods
    to manipulate (create, rename, delete...) nodes and handle their
    attributes, as well as methods to traverse the object tree.
    The *user entry point* to the object tree attached to the HDF5 file
    is represented in the root_uep attribute.
    Other attributes are available.

    File objects support an *Undo/Redo mechanism* which can be enabled
    with the :meth:`File.enable_undo` method. Once the Undo/Redo
    mechanism is enabled, explicit *marks* (with an optional unique
    name) can be set on the state of the database using the
    :meth:`File.mark`
    method. There are two implicit marks which are always available:
    the initial mark (0) and the final mark (-1).  Both the identifier
    of a mark and its name can be used in *undo* and *redo* operations.

    Hierarchy manipulation operations (node creation, movement and
    removal) and attribute handling operations (setting and deleting)
    made after a mark can be undone by using the :meth:`File.undo`
    method, which returns the database to the state of a past mark.
    If undo() is not followed by operations that modify the hierarchy
    or attributes, the :meth:`File.redo` method can be used to return
    the database to the state of a future mark. Else, future states of
    the database are forgotten.

    Note that data handling operations can not be undone nor redone by
    now. Also, hierarchy manipulation operations on nodes that do not
    support the Undo/Redo mechanism issue an UndoRedoWarning *before*
    changing the database.

    The Undo/Redo mechanism is persistent between sessions and can
    only be disabled by calling the :meth:`File.disable_undo` method.

    File objects can also act as context managers when using the with
    statement introduced in Python 2.5.  When exiting a context, the
    file is automatically closed.

    Parameters
    ----------
    filename : str
        The name of the file (supports environment variable expansion).
        It is suggested that file names have any of the .h5, .hdf or
        .hdf5 extensions, although this is not mandatory.

    mode : str
        The mode to open the file. It can be one of the
        following:

            * *'r'*: Read-only; no data can be modified.
            * *'w'*: Write; a new file is created (an existing file
              with the same name would be deleted).
            * *'a'*: Append; an existing file is opened for reading
              and writing, and if the file does not exist it is created.
            * *'r+'*: It is similar to 'a', but the file must already
              exist.

    title : str
        If the file is to be created, a TITLE string attribute will be
        set on the root group with the given value. Otherwise, the
        title will be read from disk, and this will not have any effect.

    root_uep : str
        The root User Entry Point. This is a group in the HDF5 hierarchy
        which will be taken as the starting point to create the object
        tree. It can be whatever existing group in the file, named by
        its HDF5 path. If it does not exist, an HDF5ExtError is issued.
        Use this if you do not want to build the *entire* object tree,
        but rather only a *subtree* of it.

        .. versionchanged:: 3.0
           The *rootUEP* parameter has been renamed into *root_uep*.

    filters : Filters
        An instance of the Filters (see :ref:`FiltersClassDescr`) class that
        provides information about the desired I/O filters applicable to the
        leaves that hang directly from the *root group*, unless other filter
        properties are specified for these leaves. Besides, if you do not
        specify filter properties for child groups, they will inherit these
        ones, which will in turn propagate to child nodes.

    Notes
    -----
    In addition, it recognizes the (lowercase) names of parameters
    present in :file:`tables/parameters.py` as additional keyword
    arguments.
    See :ref:`parameter_files` for a detailed info on the supported
    parameters.


    .. rubric:: File attributes

    .. attribute:: filename

        The name of the opened file.

    .. attribute:: format_version

        The PyTables version number of this file.

    .. attribute:: isopen

        True if the underlying file is open, false otherwise.

    .. attribute:: mode

        The mode in which the file was opened.

    .. attribute:: root

        The *root* of the object tree hierarchy (a Group instance).

    .. attribute:: root_uep

        The UEP (user entry point) group name in the file (see
        the :func:`open_file` function).

        .. versionchanged:: 3.0
           The *rootUEP* attribute has been renamed into *root_uep*.

    )r   r!   LinkUnknownc                     | j         j        S )z(The title of the root group in the file.root_v_titler6   s    r8   r   z
File.title  s     y!!r:   c                     || j         _        d S r2   r   )r7   r   s     r8   r   z
File.title  s    "	r:   c                     | j         `d S r2   r   r6   s    r8   r   z
File.title  s    Ir:   c                     | j         j        S )zTDefault filter properties for the root group
        (see :ref:`FiltersClassDescr`).r   
_v_filtersr6   s    r8   ro   zFile.filters  s     y##r:   c                     || j         _        d S r2   r  )r7   ro   s     r8   ro   zFile.filters  s    &	r:   c                     | j         `d S r2   r  r6   s    r8   ro   zFile.filters  s    I   r:   rr   r   rg   Nc                 Z   t          j        |          | _        	 || _        	 |dvrt	          d|z            d t
          j                                        D             }d |D             rt          j	        dt                     d |                                D             }|                    |           |d         t                      |d<   |d         t                      |d<   || _         | j        ||fi | | j        }|rt!          |           t"          | _        	 |d	         }	t%          |	
          | _        d| _        d| _        	 t,                              |            d| _        |                     |||          x| _        }
	 |
                                 | j        j        | j        _        |r(|d         r |
j                            dt"                     |s(| j        dk    rt@          | v r| !                                 tE          j#        |d                    d S )N)rr   r   r   r   zEinvalid mode string ``%s``. Allowed modes are: 'r', 'r+', 'a' and 'w'c                 l    i | ]1\  }}|                                 |                    d           .||2S )_)isupperr   r   kvs      r8   
<dictcomp>z!File.__init__.<locals>.<dictcomp>  sN     < < <41aYY[[<)*c):):<!Q < < <r:   c                 :    g | ]}|                                 |S r\   )r  )r   r
  s     r8   r   z!File.__init__.<locals>.<listcomp>  s%    ---!-A---r:   z5The use of uppercase keyword parameters is deprecatedc                 >    i | ]\  }}|                                 |S r\   )upperr	  s      r8   r  z!File.__init__.<locals>.<dictcomp>  s&    :::41a!''))Q:::r:   MAX_NUMEXPR_THREADSMAX_BLOSC_THREADSNODE_CACHE_SLOTS)r   Fr   PYTABLES_SYS_ATTRSPYTABLES_FORMAT_VERSIONrr   )$r   r   rE   rt   r   r   __dict__r   r   r   DeprecationWarningupdater(   params_g_new_v_newrp   format_versionr   _node_manager_undoEnabledisopenr   rH   _open_count_File__get_root_groupr   _g_post_init_hook_g_load_childr   _v_attrs_g__setattr_trans_group_pathenable_undoneset_vml_num_threads)r7   rE   rt   r   r   ro   rz   r  newnode_cache_slotsr   s              r8   r9   zFile.__init__  s    	(++*	4,,, 68<= > > >< <:#6#<#<#>#> < < < .-v--- 	<M '(:< < < ;:6<<>>:::f
 '(0,B,D,DF()%&.*@*B*BF&' 	Hd--f--- k 	<'""""0D;
 ""45(0@AAA "
 C 	   005'JJJ	DI 	   *.)*A'  	?*+ ?))-~? ? ?
  	tyC'',=,E,E 	v&;<=====r:   c                 d   |                                  | _        |dv rd}|| _        | j        }|snt	          j        | j        d          | _        | j        sd| _        d| _        n9t          | j        t                    s| j        
                    d          | _        t          | ||||          S )a$  Returns a Group instance which will act as the root group in the
        hierarchical tree.

        If file is opened in "r", "r+" or "a" mode, and the file already
        exists, this method dynamically builds a python object tree
        emulating the structure present on file.

        )Nr   rg   r  unknownFutf-8r   r)  ro   )_get_file_id_v_objectidr   r  r   read_f_attrr  	_isPTFilerk   strdecoder   )r7   r   r   ro   r)  s        r8   __get_root_groupzFile.__get_root_group#  s      ,,..z!!H k  
	J"0"< ";#= #=D& J&/#!& 3S99 J&*&9&@&@&I&I# xu#wOOOOr:   c                 Z    |r|                      |          S |                     |          S )zGet the given `path` or create it if `create` is true.

        If `create` is true, `path` *must* be a string path and not a
        node, otherwise a `TypeError`will be raised.

        )_create_pathr   )r7   r   creates      r8   _get_or_create_pathzFile._get_or_create_pathG  s2      	'$$T***==&&&r:   c                 $   t          |d          st          d          |dk    r| j        S | j        | j        }}|                    d          dd         D ]7}	 |                    |          }n# t          $ r  |||          }Y nw xY w|}8|S )z|Create the groups needed for the `path` to exist.

        The group associated with the given `path` is returned.

        splitz,when creating parents, parent must be a pathrg   r   N)r   rl   r   create_groupr;  r   r   )r7   r   parentr<  pcompchilds         r8   r7  zFile._create_pathT  s     tW%% 	LJKKK3;;9#y$*;ZZ__QRR( 	 	E4++E22" 4 4 4$VU334FFs   A11B
	B
Fc                 t    |                      ||          }t          |           t          |||d|          S )az  Create a new group.

        Parameters
        ----------
        where : str or Group
            The parent group from which the new group will hang. It can be a
            path string (for example '/level1/leaf5'), or a Group instance
            (see :ref:`GroupClassDescr`).
        name : str
            The name of the new group.
        title : str, optional
            A description for this node (it sets the TITLE HDF5 attribute on
            disk).
        filters : Filters
            An instance of the Filters class (see :ref:`FiltersClassDescr`)
            that provides information about the desired I/O filters applicable
            to the leaves that hang directly from this new group (unless other
            filter properties are specified for these leaves). Besides, if you
            do not specify filter properties for its child groups, they will
            inherit these ones.
        createparents : bool
            Whether to create the needed groups for the parent
            path to exist (not done by default).

        See Also
        --------
        Group : for more information on groups

        Tr.  )r9  rp   r   )r7   wherenamer   ro   createparents
parentnodes          r8   r<  zFile.create_groupj  sJ    @ --e]CC
gZ dG= = = 	=r:   '  Tc                    |
~t          |
t          j                  st          d|
z            t	          |
j        | j                  \  }}|.t          || j                  |
j        k    rt          d          ||}|                     ||	          }|t          d          t          |           t          |||||||||	  	        }|
|                    |
           |S )ac  Create a new table with the given name in where location.

        Parameters
        ----------
        where : str or Group
            The parent group from which the new table will hang. It can be a
            path string (for example '/level1/leaf5'), or a Group instance
            (see :ref:`GroupClassDescr`).
        name : str
            The name of the new table.
        description : Description
            This is an object that describes the table, i.e. how
            many columns it has, their names, types, shapes, etc.  It
            can be any of the following:

                * *A user-defined class*: This should inherit from the
                  IsDescription class (see :ref:`IsDescriptionClassDescr`)
                  where table fields are specified.
                * *A dictionary*: For example, when you do not know
                  beforehand which structure your table will have).
                * *A Description instance*: You can use the description
                  attribute of another table to create a new one with the
                  same structure.
                * *A NumPy dtype*: A completely general structured NumPy
                  dtype.
                * *A NumPy (structured) array instance*: The dtype of
                  this structured array will be used as the description.
                  Also, in case the array has actual data, it will be
                  injected into the newly created table.

            .. versionchanged:: 3.0
               The *description* parameter can be None (default) if *obj* is
               provided.  In that case the structure of the table is deduced
               by *obj*.

        title : str
            A description for this node (it sets the TITLE HDF5 attribute
            on disk).
        filters : Filters
            An instance of the Filters class (see :ref:`FiltersClassDescr`)
            that provides information about the desired I/O filters to be
            applied during the life of this object.
        expectedrows : int
            A user estimate of the number of records that will be in the table.
            If not provided, the default value is EXPECTED_ROWS_TABLE (see
            :file:`tables/parameters.py`). If you plan to create a bigger
            table try providing a guess; this will optimize the HDF5 B-Tree
            creation and management process time and memory used.
        chunkshape
            The shape of the data chunk to be read or written in a
            single HDF5 I/O operation. Filters are applied to those
            chunks of data. The rank of the chunkshape for tables must
            be 1. If None, a sensible value is calculated based on the
            expectedrows parameter (which is recommended).
        byteorder : str
            The byteorder of data *on disk*, specified as 'little' or 'big'.
            If this is not specified, the byteorder is that of the platform,
            unless you passed an array as the description, in which case
            its byteorder will be used.
        createparents : bool
            Whether to create the needed groups for the parent path to exist
            (not done by default).
        obj : python object
            The recarray to be saved.  Accepted types are NumPy record
            arrays.

            The *obj* parameter is optional and it can be provided in
            alternative to the *description* parameter.
            If both *obj* and *description* are provided they must
            be consistent with each other.

            .. versionadded:: 3.0

        track_times
            Whether time data associated with the leaf are recorded (object
            access time, raw data modification time, metadata change time,
            object birth time); default True.  Semantics of these times
            depend on their implementation in the HDF5 library: refer to
            documentation of the H5O_info_t data structure.  As of HDF5
            1.8.15, only ctime (metadata change time) is implemented.

            .. versionadded:: 3.4.3

        See Also
        --------
        Table : for more information on tables

        Nzinvalid obj parameter %r)ptparamszSthe desctiption parameter is not consistent with the data type of the obj parameterzinvalid table description: None)descriptionr   ro   expectedrows
chunkshape	byteordertrack_times)rk   npndarrayrl   r   dtyper  r   r9  r   rp   r&   r   )r7   rA  rB  rH  r   ro   rI  rJ  rK  rC  objrL  descrr  rD  ptobjs                   r8   create_tablezFile.create_table  s#   z ?c2:.. B :S @AAA'	DKHHHHE1'$[.2k; ; ;>AiH H !J K K K$#--e]CC
>???gj$"-U%L!+y"-	/ / / ?LLr:   c
           	         |\||t          d          t          j        d|j                  }
t          j        ||j        |
dt          |          z            }n\t          |          }t          ||          }|||j        k    rt          d          ||j        |j        k    rt          d          | 	                    ||          }t          ||||||		          S )
a	  Create a new array.

        Parameters
        ----------
        where : str or Group
            The parent group from which the new array will hang. It can be a
            path string (for example '/level1/leaf5'), or a Group instance
            (see :ref:`GroupClassDescr`).
        name : str
            The name of the new array
        obj : python object
            The array or scalar to be saved.  Accepted types are NumPy
            arrays and scalars, as well as native Python sequences and
            scalars, provided that values are regular (i.e. they are
            not like ``[[1,2],2]``) and homogeneous (i.e. all the
            elements are of the same type).

            Also, objects that have some of their dimensions equal to 0
            are not supported (use an EArray node (see
            :ref:`EArrayClassDescr`) if you want to store an array with
            one of its dimensions equal to 0).

            .. versionchanged:: 3.0
               The *Object parameter has been renamed into *obj*.*

        title : str
            A description for this node (it sets the TITLE HDF5 attribute on
            disk).
        byteorder : str
            The byteorder of the data *on disk*, specified as 'little' or
            'big'.  If this is not specified, the byteorder is that of the
            given object.
        createparents : bool, optional
            Whether to create the needed groups for the parent path to exist
            (not done by default).
        atom : Atom
            An Atom (see :ref:`AtomClassDescr`) instance representing
            the *type* and *shape* of the atomic objects to be saved.

            .. versionadded:: 3.0

        shape : tuple of ints
            The shape of the stored array.

            .. versionadded:: 3.0

        track_times
            Whether time data associated with the leaf are recorded (object
            access time, raw data modification time, metadata change time,
            object birth time); default True.  Semantics of these times
            depend on their implementation in the HDF5 library: refer to
            documentation of the H5O_info_t data structure.  As of HDF5
            1.8.15, only ctime (metadata change time) is implemented.

            .. versionadded:: 3.4.3

        See Also
        --------
        Array : for more information on arrays
        create_table : for more information on the rest of parameters

        Nzjif the obj parameter is not specified (or None) then both the atom and shape parametes should be provided.r\   )rO  r   )rO  bufferstrides*the shape parameter do not match obj.shapeLthe atom parameter is not consistent with the data type of the obj parameter)rP  r   rK  rL  )rl   rM  zerosrO  rN  rA   r*   r+   shaper9  r"   )r7   rA  rB  rP  r   rK  rC  atomr[  rL  dfltflavor_objrD  s                 r8   create_arrayzFile.create_array	  s   D ;|u} !@ A A A x$*555jdj)-c%jj: : : s^^F %S&11D Udj%8%8 LMMMDJ$*$<$< !E F F F --e]CC
ZEY!,. . . 	.r:   c                    |
t          |
          }t          |
|          }
|||
j        k    rt          d          |
j        }||j        |
j        k    rt          d          |t          j        |
j                  }n||t          d          |                     ||	          }t          |           t          |||||||||	  	        }|
|
|d<   |S )a]  Create a new chunked array.

        Parameters
        ----------
        where : str or Group
            The parent group from which the new array will hang. It can
            be a path string (for example '/level1/leaf5'), or a Group
            instance (see :ref:`GroupClassDescr`).
        name : str
            The name of the new array
        atom : Atom
            An Atom (see :ref:`AtomClassDescr`) instance representing
            the *type* and *shape* of the atomic objects to be saved.

            .. versionchanged:: 3.0
               The *atom* parameter can be None (default) if *obj* is
               provided.

        shape : tuple
            The shape of the new array.

            .. versionchanged:: 3.0
               The *shape* parameter can be None (default) if *obj* is
               provided.

        title : str, optional
            A description for this node (it sets the TITLE HDF5 attribute
            on disk).
        filters : Filters, optional
            An instance of the Filters class (see :ref:`FiltersClassDescr`)
            that provides information about the desired I/O filters to
            be applied during the life of this object.
        chunkshape : tuple or number or None, optional
            The shape of the data chunk to be read or written in a
            single HDF5 I/O operation.  Filters are applied to those
            chunks of data.  The dimensionality of chunkshape must be
            the same as that of shape.  If None, a sensible value is
            calculated (which is recommended).
        byteorder : str, optional
            The byteorder of the data *on disk*, specified as 'little'
            or 'big'.  If this is not specified, the byteorder is that
            of the given object.
        createparents : bool, optional
            Whether to create the needed groups for the parent path to
            exist (not done by default).
        obj : python object
            The array or scalar to be saved.  Accepted types are NumPy
            arrays and scalars, as well as native Python sequences and
            scalars, provided that values are regular (i.e. they are
            not like ``[[1,2],2]``) and homogeneous (i.e. all the
            elements are of the same type).

            Also, objects that have some of their dimensions equal to 0
            are not supported. Please use an EArray node (see
            :ref:`EArrayClassDescr`) if you want to store an array with
            one of its dimensions equal to 0.

            The *obj* parameter is optional and it can be provided in
            alternative to the *atom* and *shape* parameters.
            If both *obj* and *atom* and/or *shape* are provided they must
            be consistent with each other.

            .. versionadded:: 3.0

        track_times
            Whether time data associated with the leaf are recorded (object
            access time, raw data modification time, metadata change time,
            object birth time); default True.  Semantics of these times
            depend on their implementation in the HDF5 library: refer to
            documentation of the H5O_info_t data structure.  As of HDF5
            1.8.15, only ctime (metadata change time) is implemented.

            .. versionadded:: 3.4.3

        See Also
        --------
        CArray : for more information on chunked arrays

        NrX  zPthe 'atom' parameter is not consistent with the data type of the 'obj' parameterzIthe 'atom' and 'shape' parameters or the 'obj' parameter must be provided)r\  r[  r   ro   rJ  rK  rL  .)
r*   r+   r[  rl   rO  r,   
from_dtyper9  rp   r#   )r7   rA  rB  r\  r[  r   ro   rJ  rK  rC  rP  rL  r^  rD  rR  s                  r8   create_carrayzFile.create_carrayi  s   h ?s^^F#C00C Uci%7%7 LMMM	DJ#)$;$; !G H H Hsy11|'( ( ( --e]CC
gz4 UG",	#.0 0 0
 ?E#Jr:     c                    |t          |          }t          ||          }d|j        dd         z   }|||k    rt          d          |}||j        |j        k    rt          d          |t          j        |j                  }|                     ||
          }t          |           t          |||||||||	|
  
        }||
                    |           |S )a  Create a new enlargeable array.

        Parameters
        ----------
        where : str or Group
            The parent group from which the new array will hang. It can be a
            path string (for example '/level1/leaf5'), or a Group instance
            (see :ref:`GroupClassDescr`).
        name : str
            The name of the new array
        atom : Atom
            An Atom (see :ref:`AtomClassDescr`) instance representing the
            *type* and *shape* of the atomic objects to be saved.

            .. versionchanged:: 3.0
               The *atom* parameter can be None (default) if *obj* is
               provided.

        shape : tuple
            The shape of the new array.  One (and only one) of the shape
            dimensions *must* be 0.  The dimension being 0 means that the
            resulting EArray object can be extended along it.  Multiple
            enlargeable dimensions are not supported right now.

            .. versionchanged:: 3.0
               The *shape* parameter can be None (default) if *obj* is
               provided.

        title : str, optional
            A description for this node (it sets the TITLE HDF5 attribute on
            disk).
        expectedrows : int, optional
            A user estimate about the number of row elements that will be added
            to the growable dimension in the EArray node.  If not provided, the
            default value is EXPECTED_ROWS_EARRAY (see tables/parameters.py).
            If you plan to create either a much smaller or a much bigger array
            try providing a guess; this will optimize the HDF5 B-Tree creation
            and management process time and the amount of memory used.
        chunkshape : tuple, numeric, or None, optional
            The shape of the data chunk to be read or written in a single HDF5
            I/O operation.  Filters are applied to those chunks of data.  The
            dimensionality of chunkshape must be the same as that of shape
            (beware: no dimension should be 0 this time!).  If None, a sensible
            value is calculated based on the expectedrows parameter (which is
            recommended).
        byteorder : str, optional
            The byteorder of the data *on disk*, specified as 'little' or
            'big'. If this is not specified, the byteorder is that of the
            platform.
        createparents : bool, optional
            Whether to create the needed groups for the parent path to exist
            (not done by default).
        obj : python object
            The array or scalar to be saved.  Accepted types are NumPy
            arrays and scalars, as well as native Python sequences and
            scalars, provided that values are regular (i.e. they are
            not like ``[[1,2],2]``) and homogeneous (i.e. all the
            elements are of the same type).

            The *obj* parameter is optional and it can be provided in
            alternative to the *atom* and *shape* parameters.
            If both *obj* and *atom* and/or *shape* are provided they must
            be consistent with each other.

            .. versionadded:: 3.0

        track_times
            Whether time data associated with the leaf are recorded (object
            access time, raw data modification time, metadata change time,
            object birth time); default True.  Semantics of these times
            depend on their implementation in the HDF5 library: refer to
            documentation of the H5O_info_t data structure.  As of HDF5
            1.8.15, only ctime (metadata change time) is implemented.

            .. versionadded:: 3.4.3

        See Also
        --------
        EArray : for more information on enlargeable arrays

        NrU  r   z5the shape parameter is not compatible with obj.shape.rY  )r\  r[  r   ro   rI  rJ  rK  rL  )r*   r+   r[  rl   rO  r,   rb  r9  rp   r$   r   )r7   rA  rB  r\  r[  r   ro   rI  rJ  rK  rC  rP  rL  r^  earray_shaperD  rR  s                    r8   create_earrayzFile.create_earray  s   l ?s^^F#C00C#)ABB-/L Ul%:%: !2 3 3 3 %DJ#)$;$; !E F F Fsy11--e]CC
gz4 U&\",	#.	0 0 0 ?LLr:   c                    |
\t          |
          }t          |
|          }
||j        |
j        k    rt          d          |t	          j        |
j                  }n|t          d          |                     ||	          }t          |           t          |||||||||	  	        }|
|
                    |
           |S )a  Create a new variable-length array.

        Parameters
        ----------
        where : str or Group
            The parent group from which the new array will hang. It can
            be a path string (for example '/level1/leaf5'), or a Group
            instance (see :ref:`GroupClassDescr`).
        name : str
            The name of the new array
        atom : Atom
            An Atom (see :ref:`AtomClassDescr`) instance representing
            the *type* and *shape* of the atomic objects to be saved.

            .. versionchanged:: 3.0
               The *atom* parameter can be None (default) if *obj* is
               provided.

        title : str, optional
            A description for this node (it sets the TITLE HDF5 attribute
            on disk).
        filters : Filters
            An instance of the Filters class (see :ref:`FiltersClassDescr`)
            that provides information about the desired I/O filters to
            be applied during the life of this object.
        expectedrows : int, optional
            A user estimate about the number of row elements that will
            be added to the growable dimension in the `VLArray` node.
            If not provided, the default value is ``EXPECTED_ROWS_VLARRAY``
            (see ``tables/parameters.py``).  If you plan to create either
            a much smaller or a much bigger `VLArray` try providing a guess;
            this will optimize the HDF5 B-Tree creation and management
            process time and the amount of memory used.

            .. versionadded:: 3.0

        chunkshape : int or tuple of int, optional
            The shape of the data chunk to be read or written in a
            single HDF5 I/O operation. Filters are applied to those
            chunks of data. The dimensionality of chunkshape must be 1.
            If None, a sensible value is calculated (which is recommended).
        byteorder : str, optional
            The byteorder of the data *on disk*, specified as 'little' or
            'big'. If this is not specified, the byteorder is that of the
            platform.
        createparents : bool, optional
            Whether to create the needed groups for the parent path to
            exist (not done by default).
        obj : python object
            The array or scalar to be saved.  Accepted types are NumPy
            arrays and scalars, as well as native Python sequences and
            scalars, provided that values are regular (i.e. they are
            not like ``[[1,2],2]``) and homogeneous (i.e. all the
            elements are of the same type).

            The *obj* parameter is optional and it can be provided in
            alternative to the *atom* parameter.
            If both *obj* and *atom* and are provided they must
            be consistent with each other.

            .. versionadded:: 3.0

        track_times
            Whether time data associated with the leaf are recorded (object
            access time, raw data modification time, metadata change time,
            object birth time); default True.  Semantics of these times
            depend on their implementation in the HDF5 library: refer to
            documentation of the H5O_info_t data structure.  As of HDF5
            1.8.15, only ctime (metadata change time) is implemented.

            .. versionadded:: 3.4.3

        See Also
        --------
        VLArray : for more informationon variable-length arrays

        .. versionchanged:: 3.0
           The *expectedsizeinMB* parameter has been replaced by
           *expectedrows*.

        NrY  zatom parameter cannot be None)r\  r   ro   rI  rJ  rK  rL  )r*   r+   rO  rl   r,   rb  r   r9  rp   r%   r   )r7   rA  rB  r\  r   ro   rI  rJ  rK  rC  rP  rL  r^  rD  rR  s                  r8   create_vlarrayzFile.create_vlarrayR  s    n ?s^^F#C00CDJ#)$;$; !E F F F|sy11\<===--e]CC
g
D!%1#-$/	1 1 1 ?LLr:   c                     |                      |          }|                     ||          }t          j        |||           |                                 |                      ||          S )a  Create a hard link.

        Create a hard link to a `target` node with the given `name` in
        `where` location.  `target` can be a node object or a path
        string.  If `createparents` is true, the intermediate groups
        required for reaching `where` are created (the default is not
        doing so).

        The returned node is a regular `Group` or `Leaf` instance.

        )r   r9  r'   _g_create_hard_link_g_add_children_names)r7   rA  rB  targetrC  
targetnoderD  s          r8   create_hard_linkzFile.create_hard_link  se     ]]6**
--e]CC
)*dJGGG((***}}Z...r:   c                     t          |t                    s't          |d          r|j        }nt	          d          |                     ||          }t          |||          }|                                 |S )a   Create a soft link (aka symbolic link) to a `target` node.

        Create a soft link (aka symbolic link) to a `target` nodewith
        the given `name` in `where` location.  `target` can be a node
        object or a path string.  If `createparents` is true, the
        intermediate groups required for reaching `where` are created.

        (the default is not doing so).

        The returned node is a SoftLink instance.  See the SoftLink
        class (in :ref:`SoftLinkClassDescr`) for more information on
        soft links.

        r   ,`target` has to be a string or a node object)rk   r3  r   r   r   r9  r-   rl  )r7   rA  rB  rm  rC  rD  slinks          r8   create_soft_linkzFile.create_soft_link  s      &#&& 	Dv}-- D+ BD D D--e]CC
T622((***r:   c                 d   t          |t                    s7t          |d          r|j        j        dz   |j        z   }n7t          d          |                    d          dk    rt          d          |                     ||          }t          |||          }|
                                 |S )a  Create an external link.

        Create an external link to a *target* node with the given *name*
        in *where* location.  *target* can be a node object in another
        file or a path string in the form 'file:/path/to/node'.  If
        *createparents* is true, the intermediate groups required for
        reaching *where* are created (the default is not doing so).

        The returned node is an :class:`ExternalLink` instance.

        r   :rq  z:/z/`target` must expressed as 'file:/path/to/node')rk   r3  r   _v_filerE   r   r   findr9  r.   rl  )r7   rA  rB  rm  rC  rD  elinks          r8   create_external_linkzFile.create_external_link  s     &#&& 	Cv}-- D0369KK BD D D[["$$AC C C--e]CC
Zv66((***r:   c                 r    |dk    r| j         S | j                            |          }|J d|z              |S )Nrg   z!unable to instantiate node ``%s``)r   r  r   )r7   r   r   s      r8   	_get_nodezFile._get_node  sH    s??9!**844!Dx!Or:   c           	         |                                   t          |t                    rJ|                                 |j        }t          ||pd          pd}|j                            |          }nt          |t          t          j
        f          rP|                    d          st          d          |}t          ||pd          pd}|                     |          }nt          d|          |rKt          |          }t          ||          s,|j        }|j        j        }	t#          d|d|d|	d          |S )	a  Get the node under where with the given name.

        Parameters
        ----------
        where : str or Node
            This can be a path string leading to a node or a Node instance (see
            :ref:`NodeClassDescr`). If no name is specified, that node is
            returned.

            .. note::

                If where is a Node instance from a different file than the one
                on which this function is called, the returned node will also
                be from that other file.

        name : str, optional
            If a name is specified, this must be a string with the name of
            a node under where.  In this case the where argument can only
            lead to a Group (see :ref:`GroupClassDescr`) instance (else a
            TypeError is raised). The node called name under the group
            where is returned.
        classname : str, optional
            If the classname argument is specified, it must be the name of
            a class derived from Node (e.g. Table). If the node is found but it
            is not an instance of that class, a NoSuchNodeError is also raised.

        If the node to be returned does not exist, a NoSuchNodeError is
        raised. Please note that hidden nodes are also considered.

        r   rg   z'``where`` must start with a slash ('/')z&``where`` must be a string or a node: zcould not find a ``z`` node at ``z``; instead, a ``z`` node has been found there)_check_openrk   r   _g_check_openr   r   rw  r|  r3  rM  str_r   	NameErrorrl   r   r   rX   r   )
r7   rA  rB  	classnamebasepathr   r   class_	npathname
nclassnames
             r8   r   zFile.get_node  st   @ 	eT"" 	D!!!(H 4:266=#H=**844DDRW~.. 		D##C(( K IJJJH 4:266=#H>>(++DDBBBD D D
  
	:&y11FdF++ : ,	!^4
 &o !yy)))ZZZ9: : :
 r:   c                 P    |                      |                                          S )zmIs the node under `path` visible?

        If the node does not exist, a NoSuchNodeError is raised.

        )r   _f_isvisibler7   r   s     r8   is_visible_nodezFile.is_visible_node\  s"     }}T""//111r:   c                 `    |                      ||          }|                    ||           dS )a  Change the name of the node specified by where and name to newname.

        Parameters
        ----------
        where, name
            These arguments work as in
            :meth:`File.get_node`, referencing the node to be acted upon.
        newname : str
            The new name to be assigned to the node (a string).
        overwrite : bool
            Whether to recursively remove a node with the same
            newname if it already exists (not done by default).

        rB  N)r   	_f_rename)r7   rA  newnamerB  ru   rP  s         r8   r   zFile.rename_nodef  s3      mmEm--gy)))))r:   c                 d    |                      ||          }|                    ||||           dS )a  Move the node specified by where and name to newparent/newname.

        Parameters
        ----------
        where, name : path
            These arguments work as in
            :meth:`File.get_node`, referencing the node to be acted upon.
        newparent
            The destination group the node will be moved into (a
            path name or a Group instance). If it is
            not specified or None, the current parent
            group is chosen as the new parent.
        newname
            The new name to be assigned to the node in its
            destination (a string). If it is not specified or
            None, the current name is chosen as the
            new name.

        Notes
        -----
        The other arguments work as in :meth:`Node._f_move`.

        r  N)r   _f_move)r7   rA  	newparentr  rB  ru   rC  rP  s           r8   	move_nodezFile.move_nodey  s7    4 mmEm--Iw	=AAAAAr:   c                    |                      ||          }	|	j        dk    rN|rL|sJ|                      |          }
|	j        |
j        ur | j        j        |
f||d| |
S t          d           |	j        |||||fi |S )a  Copy the node specified by where and name to newparent/newname.

        Parameters
        ----------
        where : str
            These arguments work as in
            :meth:`File.get_node`, referencing the node to be acted
            upon.
        newparent : str or Group
            The destination group that the node will be copied
            into (a path name or a Group
            instance). If not specified or None, the
            current parent group is chosen as the new parent.
        newname : str
            The name to be assigned to the new copy in its
            destination (a string).  If it is not specified or
            None, the current name is chosen as the
            new name.
        name : str
            These arguments work as in
            :meth:`File.get_node`, referencing the node to be acted
            upon.
        overwrite : bool, optional
            If True, the destination group will be overwritten if it already
            exists.  Defaults to False.
        recursive : bool, optional
            If True, all descendant nodes of srcgroup are recursively copied.
            Defaults to False.
        createparents : bool, optional
            If True, any necessary parents of dstgroup will be created.
            Defaults to False.
        kwargs
           Additional keyword arguments can be used to customize the copying
           process.  See the documentation of :meth:`Group._f_copy`
           for a description of those arguments.

        Returns
        -------
        node : Node
            The newly created copy of the source node (i.e. the destination
            node).  See :meth:`.Node._f_copy` for further details on the
            semantics of copying nodes.

        r  r   )ru   	recursivez/You cannot copy a root group over the same file)r   _v_depthrw  r   _f_copy_childrenOSError_f_copy)r7   rA  r  r  rB  ru   r  rC  rz   rP  npobjs              r8   	copy_nodezFile.copy_node  s    ` mmEm--<17MM),,E{%-//*	*5 JI5>J JBHJ J JEG G Gs{9g$iJ JBHJ J 	Jr:   c                 ^    |                      ||          }|                    |           dS )a  Remove the object node *name* under *where* location.

        Parameters
        ----------
        where, name
            These arguments work as in
            :meth:`File.get_node`, referencing the node to be acted upon.
        recursive : bool
            If not supplied or false, the node will be removed
            only if it has no children; if it does, a
            NodeError will be raised. If supplied
            with a true value, the node and all its descendants will be
            completely removed.

        r  N)r   	_f_remove)r7   rA  rB  r  rP  s        r8   remove_nodezFile.remove_node  s1    " mmEm--i     r:   c                 Z    |                      ||          }|                    |          S )ax  Get a PyTables attribute from the given node.

        Parameters
        ----------
        where, name
            These arguments work as in :meth:`File.get_node`, referencing the
            node to be acted upon.
        attrname
            The name of the attribute to retrieve.  If the named
            attribute does not exist, an AttributeError is raised.

        r  )r   
_f_getattrr7   rA  attrnamerB  rP  s        r8   get_node_attrzFile.get_node_attr  s+     mmEm--~~h'''r:   c                 `    |                      ||          }|                    ||           dS )aC  Set a PyTables attribute for the given node.

        Parameters
        ----------
        where, name
            These arguments work as in
            :meth:`File.get_node`, referencing the node to be acted upon.
        attrname
            The name of the attribute to set.
        attrvalue
            The value of the attribute to set. Any kind of Python
            object (like strings, ints, floats, lists, tuples, dicts,
            small NumPy objects ...) can be stored as an attribute.
            However, if necessary, pickle is automatically used so as
            to serialize objects that you might want to save.
            See the :class:`AttributeSet` class for details.

        Notes
        -----
        If the node already has a large number of attributes, a
        PerformanceWarning is issued.

        r  N)r   
_f_setattr)r7   rA  r  	attrvaluerB  rP  s         r8   set_node_attrzFile.set_node_attr  s3    2 mmEm--x+++++r:   c                 ^    |                      ||          }|                    |           dS )ay  Delete a PyTables attribute from the given node.

        Parameters
        ----------
        where, name
            These arguments work as in :meth:`File.get_node`, referencing the
            node to be acted upon.
        attrname
            The name of the attribute to delete.  If the named
            attribute does not exist, an AttributeError is raised.

        r  N)r   
_f_delattrr  s        r8   del_node_attrzFile.del_node_attr  s1     mmEm--x     r:   c                     |                      ||          }|                      |          }|j                            |           dS )a  Copy PyTables attributes from one node to another.

        Parameters
        ----------
        where, name
            These arguments work as in :meth:`File.get_node`, referencing the
            node to be acted upon.
        dstnode
            The destination node where the attributes will be copied to. It can
            be a path string or a Node instance (see :ref:`NodeClassDescr`).

        r  N)r   r#  r  )r7   rA  dstnoderB  	srcobject	dstobjects         r8   copy_node_attrszFile.copy_node_attrs&  sG     MM%dM33	MM'**	""9-----r:   c                 |    |                      |          }|                     |            |j        ||||fi | dS )am  Copy the children of a group into another group.

        Parameters
        ----------
        srcgroup : str
            The group to copy from.
        dstgroup : str
            The destination group.
        overwrite : bool, optional
            If True, the destination group will be overwritten if it already
            exists.  Defaults to False.
        recursive : bool, optional
            If True, all descendant nodes of srcgroup are recursively copied.
            Defaults to False.
        createparents : bool, optional
            If True, any necessary parents of dstgroup will be created.
            Defaults to False.
        kwargs : dict
           Additional keyword arguments can be used to customize the copying
           process.  See the documentation of :meth:`Group._f_copy_children`
           for a description of those arguments.

        N)r   _check_groupr  )r7   srcgroupdstgroupru   r  rC  rz   s          r8   copy_childrenzFile.copy_children8  sg    6 ==**(###!!iM	E 	E=C	E 	E 	E 	E 	Er:   c                    |                                   t          | j                                                  t          |                                          k    rt	          d          |                    dd          }|t          | j        j        dd          }|	                    dd          }|                    d| j
                  }t          |                                          r|st	          d| d	          t          |fd
||d|}	 |r$| j        j                            |j                    | j        j        |j        fddi| |                                 dS # |                                 w xY w)a  Copy the contents of this file to dstfilename.

        Parameters
        ----------
        dstfilename : str
            A path string indicating the name of the destination file. If
            it already exists, the copy will fail with an IOError, unless
            the overwrite argument is true.
        overwrite : bool, optional
            If true, the destination file will be overwritten if it already
            exists.  In this case, the destination file must be closed, or
            errors will occur.  Defaults to False.
        kwargs
            Additional keyword arguments discussed below.

        Notes
        -----
        Additional keyword arguments may be passed to customize the
        copying process. For instance, title and filters may be changed,
        user attributes may be or may not be copied, data may be
        sub-sampled, stats may be collected, etc. Arguments unknown to
        nodes are simply ignored. Check the documentation for copying
        operations of nodes to see which options they support.

        In addition, it recognizes the names of parameters present in
        :file:`tables/parameters.py` as additional keyword arguments.
        See :ref:`parameter_files` for a detailed info on the supported
        parameters.

        Copying a file usually has the beneficial side effect of
        creating a more compact and cleaner version of the original
        file.

        z"You cannot copy a file over itselfro   NFILTERScopyuserattrsTr   zfile ``zA`` already exists; you may want to use the ``overwrite`` argumentr   )rt   r   ro   r  )r~  r   rE   resolver  r   getattrr   r#  getr   is_filerv   r  r  rT   )r7   ry   ru   rz   ro   r  r   dstfilehs           r8   rw   zFile.copy_fileY  s   H 	 &&((D,=,=,E,E,G,GGG>??? **Y--?
 di0)TBBG

?D99

7DJ//$$&& 	y 	2+ 2 2 2   K!K KCIK K	 :	"**8=999 'DI&x}OOOOOONNHNNs   A E/ /Fc                     |                      |          }|                     |           |                    |          S )zReturn a *list* with children nodes hanging from where.

        This is a list-returning version of :meth:`File.iter_nodes`.

        )r   r  _f_list_nodesr7   rA  r  groups       r8   
list_nodeszFile.list_nodes  s=     e$$%   ""9---r:   c                     |                      |          }|                     |           |                    |          S )aN  Iterate over children nodes hanging from where.

        Parameters
        ----------
        where
            This argument works as in :meth:`File.get_node`, referencing the
            node to be acted upon.
        classname
            If the name of a class derived from
            Node (see :ref:`NodeClassDescr`) is supplied, only instances of
            that class (or subclasses of it) will be returned.

        Notes
        -----
        The returned nodes are alphanumerically sorted by their name.
        This is an iterator version of :meth:`File.list_nodes`.

        )r   r  _f_iter_nodesr  s       r8   
iter_nodeszFile.iter_nodes  s=    ( e$$%   ""9---r:   c                 T    	 |                      |           dS # t          $ r Y dS w xY w)zIs there a node with that path?

        Returns True if the file has a node with the given path (a
        string), False otherwise.

        TF)r   r   r  s     r8   rF   zFile.__contains__  sD    	MM$ 4  	 	 	55	s    
''c                 ,    |                      d          S )a  Recursively iterate over the nodes in the tree.

        This is equivalent to calling :meth:`File.walk_nodes` with no
        arguments.

        Examples
        --------

        ::

            # Recursively list all the nodes in the object tree.
            h5file = tables.open_file('vlarray1.h5')
            print("All nodes in the object tree:")
            for node in h5file:
                print(node)

        rg   )
walk_nodesr6   s    r8   r   zFile.__iter__  s    & s###r:   c              #     K   t          |          }|t          u r|                     |          E d{V  dS |t          u rL|                     |          V  |                     |          D ]}|                     |          E d{V  dS |                     |          D ]}|                     ||          E d{V  dS )a  Recursively iterate over nodes hanging from where.

        Parameters
        ----------
        where : str or Group, optional
            If supplied, the iteration starts from (and includes)
            this group. It can be a path string or a
            Group instance (see :ref:`GroupClassDescr`).
        classname
            If the name of a class derived from
            Node (see :ref:`GroupClassDescr`) is supplied, only instances of
            that class (or subclasses of it) will be returned.

        Notes
        -----
        This version iterates over the leaves in the same group in order
        to avoid having a list referencing to them and thus, preventing
        the LRU cache to remove them after their use.

        Examples
        --------

        ::

            # Recursively print all the nodes hanging from '/detector'.
            print("Nodes hanging from group '/detector':")
            for node in h5file.walk_nodes('/detector', classname='EArray'):
                print(node)

        N)r   r   walk_groupsr   r   r  )r7   rA  r  r  r  s        r8   r  zFile.walk_nodes  s     @ #9--U??''...........t^^--&&&&&))%00 2 2??511111111112 2 ))%00 = =??5)<<<<<<<<<<= =r:   c                 ~    |                      |          }|                     |           |                                S )a  Recursively iterate over groups (not leaves) hanging from where.

        The where group itself is listed first (preorder), then each of its
        child groups (following an alphanumerical order) is also traversed,
        following the same procedure.  If where is not supplied, the root
        group is used.

        The where argument can be a path string
        or a Group instance (see :ref:`GroupClassDescr`).

        )r   r  _f_walk_groups)r7   rA  r  s      r8   r  zFile.walk_groups  s;     e$$%   ##%%%r:   c                 2    | j         st          d          dS )zeCheck the state of the file.

        If the file is closed, a `ClosedFileError` is raised.

        zthe file object is closedN)r  r	   r6   s    r8   r~  zFile._check_open)  s'     { 	?!"=>>>	? 	?r:   c                     | j         dv S )zIs this file writable?)r   r   r   rs   r6   s    r8   _iswritablezFile._iswritable3  s     y,,,r:   c                 L    |                                  st          d          dS )zpCheck whether the file is writable.

        If the file is not writable, a `FileModeError` is raised.

        zthe file is not writableN)r  r
   r6   s    r8   _check_writablezFile._check_writable8  s1     !! 	< :;;;	< 	<r:   c                 `    t          |t                    st          d|j         d          d S )Nznode ``z`` is not a group)rk   r   rl   r   )r7   r   s     r8   r  zFile._check_groupB  s>    $&& 	KId&6IIIJJJ	K 	Kr:   c                 8    |                                   | j        S )a"  Is the Undo/Redo mechanism enabled?

        Returns True if the Undo/Redo mechanism has been enabled for
        this file, False otherwise. Please note that this mechanism is
        persistent, so a newly opened PyTables file may already have
        Undo/Redo support enabled.

        )r~  r  r6   s    r8   is_undo_enabledzFile.is_undo_enabledG  s     	  r:   c                 2    | j         st          d          d S )Nz(Undo/Redo feature is currently disabled!)r  r   r6   s    r8   _check_undo_enabledzFile._check_undo_enabledT  s)      	L JKKK	L 	Lr:   c                     t          | j        t          dd          }|j                            dt
                     |S )Nz!Transaction information containerTr)  FORMATVERSION)r   r   _trans_group_namer#  r$  _trans_version)r7   tgroups     r8   _create_transaction_groupzFile._create_transaction_groupX  sB    "I(/T; ; ; 	##O^DDDr:   c                 >    t          |t          |z  d|z  d          S )NzTransaction number %dTr  )r   _trans_name)r7   troottids      r8   _create_transactionzFile._create_transaction`  s-    ;$#c)t5 5 5 	5r:   c                 >    t          |t          |z  d|z  d          S )NzMark number %dTr  )r    	_markName)r7   transmids      r8   _create_markzFile._create_marke  s,    9s?s". . . 	.r:   r   )	complevelc                    | j         d          G d dt          t                    } G fddt                    }|                                  |                                 rt          d          i | _        g | _        d| _	        d| _
        d| _        	 |                     t                    }|                    t          | j
        z            | _        |j        | _        | j        D ]r}|d	         t&          d
         k    rY|d                             d          }| j	        | j        |<   | j                            |j                   | xj	        dz  c_	        st/          | j        j        j                  | _        | j        j        j        | _        n# t8          $ r |                                  |                                 }|                     || j
                  | _         ||t@          |d|          | _        | j                            t&          d
         tC          d          dfg           | xj	        dz  c_	        | j                            d           | "                    | j        d           t/          | j	        dz
            | _        | j        j#        dz
  | _        Y nw xY wd| _$        dS )a  Enable the Undo/Redo mechanism.

        This operation prepares the database for undoing and redoing
        modifications in the node hierarchy. This
        allows :meth:`File.mark`, :meth:`File.undo`, :meth:`File.redo` and
        other methods to be called.

        The filters argument, when specified,
        must be an instance of class Filters (see :ref:`FiltersClassDescr`) and
        is meant for setting the compression values for the action log. The
        default is having compression enabled, as the gains in terms of
        space can be considerable. You may want to disable compression if
        you want maximum speed for Undo/Redo operations.

        Calling this method when the Undo/Redo mechanism is already
        enabled raises an UndoRedoError.

        MAX_UNDO_PATH_LENGTHc                       e Zd ZdS )#File.enable_undo.<locals>.ActionLogN)rX   rY   rZ   r\   r:   r8   	ActionLogr    s        Dr:   r  c                   `    e Zd Z ed          Z e dd          Z e dd          ZdS )'File.enable_undo.<locals>.ActionLogDescr   )posr   r:   )r  r]  r]   N)rX   rY   rZ   r   opcoder   arg1arg2)maxundos   r8   ActionLogDescr    sJ        X!___F9W!#666D9W!#666DDDr:   r  z%Undo/Redo feature is already enabled!r   rv  r  ra   r  r-  r   z
Action logrn   r   TN)%r  r   r&   r   r~  r  r   _markers_seqmarkers_nmarks_curtransaction_curmarkr   r%  r   r  _transri   
_actionlog_op_to_coder4  r   nrowintattrsCURMARK	CURACTION
_curactionr   r  r  r  _action_log_namer3  r  nrowsr  )r7   ro   r  r  r  rowrB  r  s          @r8   r&  zFile.enable_undoj  s   ( +45	 	 	 	 	 	 	 		7 	7 	7 	7 	7 	7 	7M 	7 	7 	7
 	 !! 	I GHHH ,	>]]#455F> !--d224 4DK %.DO & &x=K$777v;--g66D*.,DM$'$++CH555LLA%LL 5 =>>DM"o3=DOOU  	8 	8 	8  """ 3355F 22,. .DK (i(-! ! !DO
 O""[%8#a&&"$E#FGGGLLALL##A&&& dk1---q 011DM"o3a7DOOO5	8Z !s   F DJ54J5c                 &   |                                   |                                 st          d          |                                  | `| `| `| `| `| `	| `
|                     t                    }|                    d           d| _        dS )a  Disable the Undo/Redo mechanism.

        Disabling the Undo/Redo mechanism leaves the database in the
        current state and forgets past and future database states. This
        makes :meth:`File.mark`, :meth:`File.undo`, :meth:`File.redo` and other
        methods fail with an UndoRedoError.

        Calling this method when the Undo/Redo mechanism is already
        disabled raises an UndoRedoError.

        z&Undo/Redo feature is already disabled!r   r  FN)r~  r  r   r  r  r  r  r  r  r  r  r   r%  	_g_remover  )r7   tnodes     r8   disable_undozFile.disable_undo  s     	##%% 	J HIII 	MMO LO/00!$$$ "r:   c                 N   |                                   |                                  |d}nht          |t                    st	          d|z            || j        v rt          d|z            |                                  | j        dz   | j        |<   | 	                    dt          | j        dz             |           | xj        dz  c_        | j        dz   | _
        | j                            | j                   |                     | j        | j                   | j        S )aM  Mark the state of the database.

        Creates a mark for the current state of the database. A unique (and
        immutable) identifier for the mark is returned. An optional name (a
        string) can be assigned to the mark. Both the identifier of a mark and
        its name can be used in :meth:`File.undo` and :meth:`File.redo`
        operations. When the name has already been used for another mark,
        an UndoRedoError is raised.

        This method can only be called when the Undo/Redo mechanism has been
        enabled. Otherwise, an UndoRedoError is raised.

        Nr   z?Only strings are allowed as mark names. You passed object: '%s'z<Name '%s' is already used as a marker name. Try another one.r   ra   )r~  r  rk   r3  rl   r  r   r  r  _logr  r  r   r  r  r  )r7   rB  s     r8   markz	File.mark  sA    	  """<DDdC(( B !:<@!A B B Bt}$$# %=?C%D E E E   """"&-!"3DM$ 			&#dma/00$777}q(000$+t}555}r:   c                    |                                  sJ | j        d         }| j        | j        j        dz
  k    r| j                            | j        dz   | j        j                   |                     t          | j        | j	        fz            }|
                                 t          | j	        dz   | j                  D ]<}|                     t          | j        |fz            }|                    d           =| j	        dz   | _        | j        d| j                 | _        |t          vrt!          d|dt                    d}d}t#          |          dk    r	|d         }nFt#          |          d	k    r|d         }|d         }n"t!          d
                              |          t#          |          |k    st#          |          |k    rt!          d|d|d          | j                            t          |         |                    d          |                    d          fg           | xj        dz  c_        dS )aY  Log an action.

        The `action` must be an all-uppercase string identifying it.
        Arguments must also be strings.

        This method should be called once the action has been completed.

        This method can only be called when the Undo/Redo mechanism has
        been enabled.  Otherwise, an `UndoRedoError` is raised.

        r  r   r  Nz	Action ``z&`` not in ``_op_to_code`` dictionary: r   r   r]   z&Too many parameters for action log: %rz%Parameter arg1 or arg2 is too long: (z, )r-  )r  r  r  r  r  remove_rowsr   	_markPathr  r  _g_resetranger  r  r  r  r   rA   with_tracebackr   encode)r7   actionargsr  mnoder  r  r  s           r8   r  z	File._log	  sj    ##%%%%%+45?do3a777O''!(;(,(=? ? ? MM)t/C/3}/> #> ? ?ENNdma/>> - -i43G2N&NOO!,,,,=1,DL#/>D$$-4:FFKK!I J J J t99>>7DDYY!^^7D7DD !% & &&4nT&:&:;IIt99w&&-.2ddDDD!: ; ; ; 	V!4!%W!5!5!%W!5!5!7  8 	9 	9 	9 	1r:   c                    t          |t                    r|}nqt          |t                    r=|| j        vr&t	          | j                  }t          d|z            | j        |         }nt          dt          |          z            |S )z:Get an integer markid from a mark sequence number or name.zSThe mark that you have specified has not been found in the internal marker list: %rzMParameter mark can only be an integer or a string, and you passed a type <%s>)rk   r  r3  r  sortedr   rl   rm   )r7   r  markidlmarkerss       r8   _get_mark_idzFile._get_mark_idP	  s     dC   	OFFc"" 		O4=((!$-00# %)+3%4 5 5 5 ]4(FF ACG::N O O O r:   c                 `    || j         dz
  k    r| j        j        S |dk    rdS | j        |         S )zVGet the action to go.

        It does not touch the self private attributes

        r   r   )r  r  r  r  )r7   r  s     r8   _get_final_actionzFile._get_final_actionb	  sA     DL1$$$ ?((q[[ 1''r:   c           	         |dk     r$| j         |dz   | j        dz            ddd         }n| j         | j        |         }t          t          |                    D ]}|d         |         t          d         k    r|dk    rzt          j        | t          t          |d         |                            |d         |         	                    d          |d	         |         	                    d                     nt          j
        | t          t          |d         |                            |d         |         	                    d          |d	         |         	                    d                     n\|dk    r!t          |d         |                   | _        n5t          |d         |                   dz
  | _        | j        dk     rd| _        | xj        |z  c_        dS )
zAUndo/Redo actions up to final action in the specificed direction.r   r   Nrv  r  ra   r  utf8r  )r  r  r  rA   r  r   redo_code_to_opr  r4  undor  )r7   finalaction	directionri   is        r8   _doundozFile._doundot	  s    q==a!0C CDTTrTJ I (CDI
 s9~~&& #	) #	)A"1%V)<<<q== M$ #.c)H2Ea2H.I.I"J"+F"3A"6"="=f"E"E"+F"3A"6"="=f"E"EG G G G M$ #.c)H2Ea2H.I.I"J"+F"3A"6"="=f"E"E"+F"3A"6"="=f"E"EG G G G q==$'	&(9!(<$=$=DMM$'	&(9!(<$=$=$ADM}q((()OOy(OOOG#	) #	)r:   c                 d   |                                   |                                  |:| j        }| j        j        j        }|| j                 t          d         k    r|dz  }n|                     |          }| 	                    |          }|| j        k    rt          d|d          |                                  |                     |dz
  d           | j        | j        j        dz
  k     r| xj        dz  c_        t          | j        j        j        | j                           | _        dS )a
  Go to a past state of the database.

        Returns the database to the state associated with the specified mark.
        Both the identifier of a mark and its name can be used. If the mark is
        omitted, the last created mark is used. If there are no past
        marks, or the specified mark is not older than the current one, an
        UndoRedoError is raised.

        This method can only be called when the Undo/Redo mechanism
        has been enabled. Otherwise, an UndoRedoError
        is raised.

        Nra   r   Mark ``zD`` is newer than the current mark. Use `redo()` or `goto()` instead.rv  )r~  r  r  r  colsr  r  r  r  r  r   r  r'  r  r  r  )r7   r  r  r  r$  s        r8   r#  z	File.undo	  s4    	  """ <]F_)0Fdo&+f*===! &&t,,F,,V44((-GKtt!N O O O 	 	[1_b)))?T_2Q666OOq OODO05doFGGr:   c                    |                                   |                                  | j        | j        j        dz
  k    rdS || j        dz   }n|dk    rt          | j                  }|                     |          }| 	                    |          }|| j        dz   k     rt          d|d          |                                  | xj        dz  c_        |                     |d           | j        | j        dz
  k     r| xj        dz  c_        | j        | j        j        dz
  k    r| j        j        dz
  | _        dS dS )a  Go to a future state of the database.

        Returns the database to the state associated with the specified
        mark.  Both the identifier of a mark and its name can be used.
        If the `mark` is omitted, the next created mark is used.  If
        there are no future marks, or the specified mark is not newer
        than the current one, an UndoRedoError is raised.

        This method can only be called when the Undo/Redo mechanism has
        been enabled.  Otherwise, an UndoRedoError is raised.

        r   Nrv  r)  zD`` is older than the current mark. Use `redo()` or `goto()` instead.)r~  r  r  r  r  r  r  r  r  r  r   r  r'  r7   r  r  r$  s       r8   r!  z	File.redo	  sa    	  """ ?do3a777F<=1$DDRZZt|$$D""4((,,V441,,,-GKtt!N O O O 	 	1 	[!$$$=4<!+++MMQMM?T_2Q666"o3a7DOOO 76r:   c                 2   |                                   |                                  |dk    r| j        }|                     |          }|                     |          }|| j        k     r|                     |           dS |                     |           dS )aE  Go to a specific mark of the database.

        Returns the database to the state associated with the specified mark.
        Both the identifier of a mark and its name can be used.

        This method can only be called when the Undo/Redo mechanism has been
        enabled. Otherwise, an UndoRedoError is raised.

        rv  N)r~  r  r  r  r  r  r#  r!  r,  s       r8   gotoz	File.goto
  s     	  """2::<D""4((,,V44((IIdOOOOOIIdOOOOOr:   c                 `    |                                   |                                  | j        S )a  Get the identifier of the current mark.

        Returns the identifier of the current mark. This can be used
        to know the state of a database after an application crash, or to
        get the identifier of the initial implicit mark after a call
        to :meth:`File.enable_undo`.

        This method can only be called when the Undo/Redo mechanism
        has been enabled. Otherwise, an UndoRedoError
        is raised.

        )r~  r  r  r6   s    r8   get_current_markzFile.get_current_mark
  s0     	  """}r:   c                 |    |                      t          | j        | j        fz            }t          | j        fz  }||fS )zCompute and return a shadow name.

        Computes the current shadow name according to the current
        transaction, mark and action.  It returns a tuple with the
        shadow parent node and the name of the shadow in it.

        )r   _shadow_parentr  r  _shadow_namer  )r7   r=  rB  s      r8   r3  zFile._shadow_name/
  sD     d2DMBBD Dt00~r:   c                     |                                   | j                                         |                     d           dS )z.Flush all the alive leaves in the object tree.r   N)r~  r  r   _flush_filer6   s    r8   r   z
File.flush>
  sG     	 	&&(((r:   c                 <   | j         sdS | j        dk    r| xj        dz  c_        dS | j        }| j        r^|                                 rJ| j        j                            d| j                   | j        j                            d| j	                   | j
                                         | j                                         t          | j        j                  dk    s$J dt!          | j        j                  z              t          | j        j                  dk    s$J dt!          | j        j                  z              |                                  | j                                         d| _         || _        t*                              |            dS )z=Flush all the alive leaves in object tree and close the file.Nr   r  r   r   z%cached nodes remain after closing: %sz$alive nodes remain after closing: %s)r  r  rE   r  r  r  r  r$  r  r  r   r   r  r   rA   r   r<   r   _close_filer  clearr   rK   rD   s     r8   rT   z
File.closeG
  s    { 	F a!F= 	L!1!1!3!3 	LO!--iGGGO!--k4?KKK 		##%%% 4%+,,1114t)/001 211
 4%.//14443t)2334 544
 	
 	  ! 	4     r:   c                     | S )z)Enter a context and return the same file.r\   r6   s    r8   	__enter__zFile.__enter__{
  s	     r:   c                 .    |                                   dS )z"Exit a context and close the file.F)rT   )r7   exc_infos     r8   __exit__zFile.__exit__
  s     	

ur:   c                 P   | j         sdS 	 t          j                            t          | j                                                  j        t          j        j                  	                    d          }n# t          $ r d}Y nw xY w| j         d| j        d|dg}|                     d          D ]Y}|                    |            | j        d	d
         D ]1}|                     ||          D ]}|                    |            2Zd                    |          dz   S )a  Return a short string representation of the object tree.

        Examples
        --------

        ::

            >>> import tables
            >>> f = tables.open_file('tables/tests/Tables_lzo2.h5')
            >>> print(f)
            tables/tests/Tables_lzo2.h5 (File) 'Table Benchmark'
            Last modif.: '...'
            Object Tree:
            / (RootGroup) 'Table Benchmark'
            /tuple0 (Table(100,)lzo(1)) 'This is the table title'
            /group0 (Group) ''
            /group0/tuple1 (Table(100,)lzo(1)) 'This is the table title'
            /group0/group1 (Group) ''
            /group0/group1/tuple2 (Table(100,)lzo(1)) 'This is the table title'
            /group0/group1/group2 (Group) ''
            >>> f.close()

        <closed File>seconds)timespecz<in-memory file>z (File) zLast modif.: zObject Tree: rg   r   NrP   )r  datetimefromtimestampr   rE   statst_mtimetimezoneutc	isoformatr  r   r  r   _node_kindsr  join)r7   datelinesr  kindr   s         r8   __str__zFile.__str__
  s_   0 { 	#"?	&$22T]##((**3X5F5J ii++ D  	& 	& 	&%DDD	& M994:99))) " %%c** 	, 	,ELLE$$$(, , , OOE488 , ,DLLD++++,, yy$&&s   A,A8 8BBc                 z   | j         sdS d| j        d| j        d| j        d| j        d| j        dg}|                     d          D ]Y}|                    |            | j        d	d
         D ]1}| 	                    ||          D ]}|                    |           2Zd
                    |          dz   S )z;Return a detailed string representation of the object tree.r?  zFile(filename=z, title=z, mode=z, root_uep=z
, filters=r  rg   r   NrP   )r  rE   r   rt   r   ro   r  r   rI  r  rJ  )r7   rL  r  rM  r   s        r8   __repr__zFile.__repr__
  s    { 	#"?)T] ) )dj ) )I) ),0M) )|) ) )* %%c** 	. 	.ELLE$$$(, . . OOE488 . .DLLD----.. yy$&&r:   c                 p   |dz   }t          |          }| j        j        | j        j        fD ]}t	          |          D ]v}|                    |          r_||k    rY||d         }t          ||          }t          |          d         }	|                     |          }
|
	                    |	           wdS )zrUpdate location information of nodes under `oldpath`.

        This only affects *already loaded* nodes.

        rg   Nr   )
rA   r  r   r   r<   r   r   r   r|  _g_update_location)r7   oldpathnewpath	oldprefixoldprefix_lenr   r   
nodesuffixnewnodepathnewnodeppathdescendent_nodes              r8   _update_node_locationszFile._update_node_locations
  s     cM	I (.0B0KL 	E 	EE KK E E&&y11 Eh)6K6K!)-..!9J"+GZ"@"@K#-k#:#:1#=L&*nnX&>&>O#66|DDDE	E 	Er:   rr   r   rg   N)r   NF)	Nr   NrE  NNFNT)Nr   NFNNT)	NNr   NNNFNT)
NNr   Nrd  NNFNT)	Nr   NNNNFNTF)NNr   )NNNFF)NNNFFFr2   )FFF)rg   Nr   )GrX   rY   rZ   __doc__rI  r[   r   setterdeleterro   r9   r   r9  r7  r<  rS  r`  rc  rg  ri  ro  rs  rz  r|  r   r  r   r  r  r  r  r  r  r  r  rw   r  r  rF   r   r  r  r~  r  r  r  r  r  r  r  r  r   r&  r	  r  r  r  r  r'  r#  r!  r.  r0  r3  r   rT   r:  r=  rN  rP  r[  r\   r:   r8   r   r   /  s       z zz 7K" " X" \# # \# ]  ] $ $ X$
 ^' ' ^' _! ! _! 24'+W> W> W> W>r"P "P "PH' ' '  , ;?#(#= #= #= #=J AC0604@Dx x x xt 9;388<^. ^. ^. ^.@ GI/3?C"&r r r rh GI1515AEs s s sj <>262604#'	n n n n`/ / / /*   8   8  A A A AF2 2 2* * * *& CG16B B B B: CGBG<J <J <J <J|! ! ! !(( ( ( (", , , ,8! ! ! !". . . .& 27$)E E E EBH H H HT
. 
. 
. 
.. . . .2  $ $ $**= *= *= *=X& & & &"? ? ?- - -
< < <K K K
! ! !L L L  5 5 5
. . .
 #*'A"6"6"6 ]! ]! ]! ]!~!" !" !"F) ) ) )V7 7 7r  $( ( ($/) /) /)b*H *H *H *H\.8 .8 .8 .8d  0  $    2! 2! 2!h  
  ,' ,' ,'\' ' '$E E E E Er:   r   r]  r\  )rr^  atexitrB  r   rQ   r   r   collectionsr   pathlibr   numexprr'  numpyrM  r   r   r   r   
exceptionsr	   r
   r   r   r   r   r   r   r   r   r   r   r   rH  r   r   r   r   r   ro   r   r   r   r   r  r   r   r   r   r    leafr!   arrayr"   carrayr#   earrayr$   vlarrayr%   tabler&   r'   utilsr(   r)   r^  r*   r+   r\  r,   linkr-   r.   r  compatible_formatsr0   r   r  r"  r  _trans_group_parentr  r%  _action_log_parentr  _action_log_path_trans_parentr  _trans_path_markParentr  r  r2  r3  _shadow_pathrp   rw   r   hdf5_version_strtuplemapr  r;  hdf5_version_tupr   rv   r   dictr   r   r   registerrW   r\   r:   r8   <module>r}     sh      				 



   # # # # # #                                - - - - - - - - - - - - - - - - - - ( ' ' ' ' ' ' ' ' ' ' ' ' '      > > > > > > > > > > > > > >       & & & & & & & & # # # # # # # # 9 9 9 9 9 9 9 9 9 9                                           ) ) ) ) ) )       0 0 0 0 0 0 0 0       ( ( ( ( ( ( ( ($  .# .# .# .# .# .# .# .#d moo   IHH  % I13DEE &  9/1ABB !i{33	Ik9--	y66' ' '   8 3>244 5S"2"8"8"="=a"@"F"Fs"K"KLLMM  09 < <HH) `D `D `D `DH       *( ( ( ( ( ( ( ($U  U  U  U  U  U  U  U pi"E i"E i"E i"E i"E= i"E i"E i"E\E % & & & & &r:   