hdf5storage.pathesc¶
Module for handling paths.
|
Hex/unicode escapes a path. |
|
Processes paths. |
|
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
- Returns
epth – The escaped path.
- Return type
- Raises
TypeError – If pth is not the right type.
See also
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 tostr
. Separated paths are given as an iterable ofstr
andbytes
. Each part of a separated path is escaped usingescape_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
orbytes
or the separated path in an Iterable with the elements beingstr
,bytes
, andpathlib.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
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
- Returns
unpth – The unescaped path.
- Return type
- Raises
TypeError – If pth is not the right type.
ValueError – If an invalid escape is found.
See also