hdf5storage.pathesc

Module for handling paths.

escape_path(pth)

Hex/unicode escapes a path.

process_path(pth)

Processes paths.

unescape_path(pth)

Hex/unicode unescapes a path.

escape_path

hdf5storage.pathesc.escape_path(pth)[source]

Hex/unicode escapes a path.

Escapes a path so that it can be represented faithfully in an HDF5 file without changing directories. This means that leading '.' must be escaped. '/' and null must be escaped to. Backslashes are escaped as double backslashes. Other escaped characters are replaced with '\xYY', '\uYYYY', or ``'\UYYYYYYYY' where Y are hex digits depending on the unicode numerical value of the character. for '.', both slashes, and null; this will be the former ('\xYY').

New in version 0.2.

Parameters

pth (str or bytes) – The path to escape.

Returns

epth – The escaped path.

Return type

str

Raises

TypeError – If pth is not the right type.

See also

unescape_path()

process_path

hdf5storage.pathesc.process_path(pth)[source]

Processes paths.

Processes the provided path and breaks it into it Group part (groupname) and target part (targetname). bytes paths are converted to str. Separated paths are given as an iterable of str and bytes. Each part of a separated path is escaped using escape_path. Otherwise, the path is assumed to be already escaped. Escaping is done so that targets with a part that starts with one or more periods, contain slashes, and/or contain nulls can be used without causing the wrong Group to be looked in or the wrong target to be looked at. It essentially allows one to make a Dataset named '..' or 'a/a' instead of moving around in the Dataset hierarchy.

All paths are POSIX style.

New in version 0.2.

Parameters

pth (str or bytes or pathlib.PurePath or Iterable) – The POSIX style path as a str or bytes or the separated path in an Iterable with the elements being str, bytes, and pathlib.PurePath. For separated paths, escaping will be done on each part.

Returns

  • groupname (str) – The path to the Group containing the target pth was pointing to.

  • targetname (str) – The name of the target pointed to by pth in the Group groupname.

Raises

TypeError – If pth is not of the right type.

See also

escape_path()

unescape_path

hdf5storage.pathesc.unescape_path(pth)[source]

Hex/unicode unescapes a path.

Unescapes a path. Valid escapeds are '\xYY', '\uYYYY', or ``'\UYYYYYYYY' where Y are hex digits giving the character’s unicode numerical value and double backslashes which are the escape for single backslashes.

New in version 0.2.

Parameters

pth (str or bytes) – The path to unescape.

Returns

unpth – The unescaped path.

Return type

str

Raises

See also

escape_path()