org.converters

Module Contents

Classes

HasKeywords

Base class for protocol classes.

Functions

keywords_encode(→ str)

Takes a dictionary of keywords and encodes them into a somewhat

keywords_decode(→ dict[str, list[str]] | None)

Decodes keywords creaged by keywords_encode().

Attributes

keywords_converter

class org.converters.HasKeywords[source]

Bases: Protocol

Base class for protocol classes.

Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
property keywords: collections.abc.Mapping[str, collections.abc.Sequence[str]][source]
org.converters.keywords_encode(keywords: HasKeywords | Mapping[str, Sequence[str]]) str[source]

Takes a dictionary of keywords and encodes them into a somewhat readable url query format.

For example:

{

‘color’: [‘blue’, ‘red’], ‘weight’: [‘normal’]

}

Results in

‘+color:blue+color:red+weight:normal’

Instead of a dictionary we can also use any kind of object which has a ‘keywords’ property returning the expected dictionary.

Note that that object won’t be recreated during decode however.

org.converters.keywords_decode(text: str) dict[str, list[str]] | None[source]

Decodes keywords creaged by keywords_encode().

org.converters.keywords_converter[source]