Skip to content

utils

get_key_path(obj, key)

Gets a key from dict or value from list with dotted key path. It can also read attributes of object if object is wrapped in the ScopedObject.

It raises KeyError if key starts with or ends with underscore to prevent unwanted access in runtime.

Parameters:

Name Type Description Default
obj Union[dict, list, pyconduit.other.ScopedObject, str]

A dictionary, list or ScopedObject.

required
key str

List of keys joined with "." (dots).

required

Returns:

Type Description
Any

The final value.

parse_display_name(name)

Splits the display name into two item tuple which represents category and block name.

Parameters:

Name Type Description Default
name str

Any string that represents the block display name.

required

Returns:

Type Description
Tuple[Optional[str], str]

A two item tuple: first item is for category and second one is for block name. Category can be None if name doesn't contain any "." (dot) character.

parse_slice(value)

Parses a slice() from string, like start:stop:step.

Parameters:

Name Type Description Default
value str

A string value that contains the slice string. For example: start:stop:step.

required

Returns:

Type Description
Optional[slice]

A slice object or None if string is not valid.

pattern_match(item, pattern, strict=True)

Check if item matches with the pattern that contains "*" wildcards and "?" question marks.

Parameters:

Name Type Description Default
item str

The string that pattern will be applied to.

required
pattern str

A wildcard (glob) pattern.

required
strict bool

If True, then it will check if matched string equals with the item parameter. So applying "foo?" pattern on "foobar" will result in False. Default is True.

True

Returns:

Type Description
bool

A boolean value.

validate_annotations(annotations, data, config=None)

Validates annotations with pydantic library and returns a ValidationError if data is not valid, otherwise it returns None.