Elektra  0.9.3
Classes | Functions
keynames Namespace Reference

Classes

class  Namespace
 

Functions

Tuple[bool, Optional[str]] check_array_part (str part)
 
str canonicalize (str name, str prefix="", bool verbose=False)
 
Tuple[Namespace, Iterator[str]] unescape (str canonical, bool verbose=False)
 

Detailed Description

This file contains a reference implementation of Elektra's Key Name processing.

It contains commented functions for:
  - Checking, whether a string is a valid Key Name and if so turning it into its canonical form.
  - Splitting (canonical) Key Names into a Namespace and a list of (unescaped) Key Name Parts.

In addition, we provide a command line interface to experiment with the implementation.
Execute the file with the argument '--help' to find out more about the CLI.

Function Documentation

◆ canonicalize()

str keynames.canonicalize ( str  name,
str   prefix = "",
bool   verbose = False 
)
Returns the canonical version of the Key Name `name`.
If `name` is not a valid Key Name, a `KeyNameException` will be raised.

If `prefix` is not empty, `name` is canonicalized under the assumption that it is being appended to the existing Key Name `prefix`.
It is similar to (but not necessarily the same as) calling `canonicalize (name + "/" + prefix)`.

If `verbose` is set to `True`, additional information about the procedure is printed to `sys.stderr`.

◆ check_array_part()

Tuple[bool, Optional[str]] keynames.check_array_part ( str  part)
Checks whether `part` is a valid Array Part.

If so, the tuple `(True, digits)` is returned where `digits` is a string
containing the digits part of the Array Part, i.e. the part after the `#` and any `_`.
Otherwise the tuple `(False, None)` is returned.

◆ unescape()

Tuple[Namespace, Iterator[str]] keynames.unescape ( str  canonical,
bool   verbose = False 
)
Returns the Namespace enum value and list of Key Name Parts for a given canonical Key Name.

`canonical` MUST be a canonical Key Name. If you are not sure about this, call `canonicalize` first.