MCPcopy Create free account
hub / github.com/PyTables/PyTables / ExternalLink

Class ExternalLink

tables/link.py:357–464  ·  view source on GitHub ↗

Represents an external link. An external link is a reference to a node in *another* file. Getting access to the pointed node (this action is called *dereferencing*) is done via the :meth:`__call__` special method (see below). .. rubric:: ExternalLink attributes .. attribut

Source from the content-addressed store, hash-verified

355
356
357class ExternalLink(linkextension.ExternalLink, Link):
358 """Represents an external link.
359
360 An external link is a reference to a node in *another* file.
361 Getting access to the pointed node (this action is called
362 *dereferencing*) is done via the :meth:`__call__` special method
363 (see below).
364
365 .. rubric:: ExternalLink attributes
366
367 .. attribute:: extfile
368
369 The external file handler, if the link has been dereferenced.
370 In case the link has not been dereferenced yet, its value is
371 None.
372
373 """
374
375 # Class identifier.
376 _c_classid = "EXTERNALLINK"
377
378 def __init__(
379 self,
380 parentnode: Group,
381 name: str,
382 target: str | None = None,
383 _log: bool = False,
384 ) -> None:
385 self.extfile = None
386 """The external file handler, if the link has been dereferenced.
387 In case the link has not been dereferenced yet, its value is
388 None."""
389 super().__init__(parentnode, name, target, _log)
390
391 def _get_filename_node(self) -> tuple[str, str]:
392 """Return the external filename and nodepath from `self.target`."""
393 # This is needed for avoiding the 'C:\\file.h5' filepath notation
394 filename, target = self.target.split(":/")
395 return filename, "/" + target
396
397 def __call__(self, **kwargs) -> Node:
398 """Dereference self.target and return the object.
399
400 You can pass all the arguments supported by the :func:`open_file`
401 function (except filename, of course) so as to open the referenced
402 external file.
403
404 Examples
405 --------
406 ::
407
408 >>> f = tb.open_file('tables/tests/elink.h5')
409 >>> f.root.pep.pep2
410 /pep/pep2 (ExternalLink) -> elink2.h5:/pep
411 >>> pep2 = f.root.pep.pep2(mode='r') # open in 'r'ead mode
412 >>> print(pep2)
413 /pep (Group) ''
414 >>> pep2._v_file.filename # belongs to referenced file

Callers 2

_g_load_childMethod · 0.85
create_external_linkMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected