scitacean.util.formatter.DatasetPathFormatter#
- class scitacean.util.formatter.DatasetPathFormatter[source]#
Formatter that inserts dataset fields and escapes paths.
This formatter automatically modifies format strings such that the following two are equivalent (up to escaping, see below).
formatter = DatasetPathFormatter() formatter.format("{owner}-{pid.pid}-{uid}", dset=dset, uid=uid) # is equivalent to (up to escaping) "{dset.owner}-{dset.pid.pid}-{uid}".format(dset=dset, uid=uid)
This means that all format fields are transformed to access attributes of the keyword argument
dset. Except for"uid"which is preserved to allow for a dedicateduidkeyword.In addition, all field values are escaped as filesystem paths using
scitacean.filesystem.escape_path():formatter = DatasetPathFormatter() formatter.format("a string {owner}", dset=dset) # is equivalent to "a string {}".format(escape_path("{dset.owner}".format(dset=dset)))
Note that only formatted fields are escaped, not the result as a whole.
Fields that are used by the formatter must not be
None. Otherwise, aValueErrorwill be raised.- __init__()#
Methods
__init__()check_unused_args(used_args, args, kwargs)convert_field(value, conversion)format(format_string, /, *args, **kwargs)format_field(value, format_spec)Format a field with the given spec.
get_field(field_name, args, kwargs)get_value(key, args, kwargs)parse(format_string)Parse a format string.
vformat(format_string, args, kwargs)