def _g_updateLocation(self, newParentPath): """ Update location-dependent attributes. Updates location data when an ancestor node has changed its location in the hierarchy to `newParentPath`. In fact, this method is expected to be called by an ancestor of this node. This also triggers the update of file references to this node. If the maximum recommended node depth is exceeded, a `PerformanceWarning` is issued. This warning is assured to be unique. """ oldPath = self._v_pathname newPath = joinPath(newParentPath, self._v_name) newDepth = newPath.count('/') self._v_pathname = newPath self._v_depth = newDepth # Check if the node is too deep in the tree. if newDepth > self._v_maxTreeDepth: warnings.warn("""\ moved descendent node is exceeding the recommended maximum depth (%d);\ be ready to see PyTables asking for *lots* of memory and possibly slow I/O""" % (self._v_maxTreeDepth,), PerformanceWarning) file_ = self._v_file file_._unrefNode(oldPath) file_._refNode(self, newPath) # Tell dependent objects about the new location of this node. self._g_updateDependent()
def _g_updateLocation(self, newParentPath): """ Update location-dependent attributes. Updates location data when an ancestor node has changed its location in the hierarchy to `newParentPath`. In fact, this method is expected to be called by an ancestor of this node. This also triggers the update of file references to this node. If the maximum recommended node depth is exceeded, a `PerformanceWarning` is issued. This warning is assured to be unique. """ oldPath = self._v_pathname newPath = joinPath(newParentPath, self._v_name) newDepth = newPath.count('/') self._v_pathname = newPath self._v_depth = newDepth # Check if the node is too deep in the tree. if newDepth > self._v_maxTreeDepth: warnings.warn( """\ moved descendent node is exceeding the recommended maximum depth (%d);\ be ready to see PyTables asking for *lots* of memory and possibly slow I/O""" % (self._v_maxTreeDepth, ), PerformanceWarning) file_ = self._v_file file_._unrefNode(oldPath) file_._refNode(self, newPath) # Tell dependent objects about the new location of this node. self._g_updateDependent()
def _g_join(self, name): """Helper method to correctly concatenate a name child object with the pathname of this group.""" if name == "/": # This case can happen when doing copies return self._v_pathname return joinPath(self._v_pathname, name)
def _f_getChild(self, childname): """Get the child called childname of this group. If the child exists (be it visible or not), it is returned. Else, a NoSuchNodeError is raised. Using this method is recommended over getattr() when doing programmatic accesses to children if childname is unknown beforehand or when its name is not a valid Python identifier. """ self._g_checkOpen() self._g_checkHasChild(childname) childPath = joinPath(self._v_pathname, childname) return self._v_file._getNode(childPath)
def _g_setLocation(self, parentNode, name): """ Set location-dependent attributes. Sets the location-dependent attributes of this node to reflect that it is placed under the specified `parentNode`, with the specified `name`. This also triggers the insertion of file references to this node. If the maximum recommended tree depth is exceeded, a `PerformanceWarning` is issued. """ file_ = parentNode._v_file parentDepth = parentNode._v_depth self._v_file = file_ self._v_isopen = True rootUEP = file_.rootUEP if name.startswith(rootUEP): # This has been called from File._getNode() assert parentDepth == 0 if rootUEP == "/": self._v_pathname = name else: self._v_pathname = name[len(rootUEP):] _, self._v_name = splitPath(name) self._v_depth = name.count("/") - rootUEP.count("/") + 1 else: # If we enter here is because this has been called elsewhere self._v_name = name self._v_pathname = joinPath(parentNode._v_pathname, name) self._v_depth = parentDepth + 1 # Check if the node is too deep in the tree. if parentDepth >= self._v_maxTreeDepth: warnings.warn("""\ node ``%s`` is exceeding the recommended maximum depth (%d);\ be ready to see PyTables asking for *lots* of memory and possibly slow I/O""" % (self._v_pathname, self._v_maxTreeDepth), PerformanceWarning) file_._refNode(self, self._v_pathname)
def _g_setLocation(self, parentNode, name): """ Set location-dependent attributes. Sets the location-dependent attributes of this node to reflect that it is placed under the specified `parentNode`, with the specified `name`. This also triggers the insertion of file references to this node. If the maximum recommended tree depth is exceeded, a `PerformanceWarning` is issued. """ file_ = parentNode._v_file parentDepth = parentNode._v_depth self._v_file = file_ self._v_isopen = True rootUEP = file_.rootUEP if name.startswith(rootUEP): # This has been called from File._getNode() assert parentDepth == 0 if rootUEP == "/": self._v_pathname = name else: self._v_pathname = name[len(rootUEP):] _, self._v_name = splitPath(name) self._v_depth = name.count("/") - rootUEP.count("/") + 1 else: # If we enter here is because this has been called elsewhere self._v_name = name self._v_pathname = joinPath(parentNode._v_pathname, name) self._v_depth = parentDepth + 1 # Check if the node is too deep in the tree. if parentDepth >= self._v_maxTreeDepth: warnings.warn( """\ node ``%s`` is exceeding the recommended maximum depth (%d);\ be ready to see PyTables asking for *lots* of memory and possibly slow I/O""" % (self._v_pathname, self._v_maxTreeDepth), PerformanceWarning) file_._refNode(self, self._v_pathname)
def _g_loadChild(self, childName): """ Load a child node from disk. The child node `childName` is loaded from disk and an adequate `Node` object is created and returned. If there is no such child, a `NoSuchNodeError` is raised. """ if self._v_file.rootUEP != "/": childName = joinPath(self._v_file.rootUEP, childName) # Is the node a group or a leaf? node_type = self._g_checkHasChild(childName) # Nodes that HDF5 report as H5G_UNKNOWN if node_type == 'Unknown': return Unknown(self, childName) # Guess the PyTables class suited to the node, # build a PyTables node and return it. if node_type == "Group": if self._v_file.params['PYTABLES_SYS_ATTRS']: childClass = self._g_getChildGroupClass(childName) else: # Default is a Group class childClass = Group return childClass(self, childName, new=False) elif node_type == "Leaf": childClass = self._g_getChildLeafClass(childName, warn=True) # Building a leaf may still fail because of unsupported types # and other causes. ###return childClass(self, childName) # uncomment for debugging try: return childClass(self, childName) except Exception, exc: #XXX warnings.warn( "problems loading leaf ``%s``::\n\n" " %s\n\n" "The leaf will become an ``UnImplemented`` node." % (self._g_join(childName), exc)) # If not, associate an UnImplemented object to it return UnImplemented(self, childName)
def _indexPathnameOfColumn_(tablePath, colpathname): return joinPath(_indexPathnameOf_(tablePath), colpathname)
def _indexPathnameOf_(nodePath): nodeParentPath, nodeName = splitPath(nodePath) return joinPath(nodeParentPath, _indexNameOf_(nodeName))
def _indexPathnameOfColumn(table, colpathname): return joinPath(_indexPathnameOf(table), colpathname)
def _indexPathnameOf(node): nodeParentPath = splitPath(node._v_pathname)[0] return joinPath(nodeParentPath, _indexNameOf(node))