selector

NUC selectors.

class SelectorTarget(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

The target for a selector.

TOKEN = 0

The target is the token itself.

CONTEXT = 1

The target is the provided context.

class Selector(path: List[str], target: SelectorTarget)[source]

Bases: object

A selector that specifies a path within a JSON object to be matched.

path: List[str]
target: SelectorTarget
static parse(selector: str) Selector[source]

Parse a selector from a string.

Parameters:

selector – The selector to be parsed.

Example

from nuc.selector import Selector

selector = Selector.parse(".foo.bar")
apply(value: Dict[str, Any], context: SelectorContext) Any[source]

Apply a selector on a value and return the matched value, if any.

Parameters:

value – The dict that this selector should be applied to.

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

__str__() str[source]

Return str(self).

exception MalformedSelectorException[source]

Bases: Exception

An exception that indicates a selector is malformed.