Welcome to jcon’s documentation!¶
jcon package¶
Submodules¶
jcon.func_decorator module¶
-
jcon.func_decorator.configurable(_func: Optional[Callable] = None, mode: Optional[OpenTextMode] = 'r', buffering: Optional[int] = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, closefd: Optional[bool] = True, opener: Optional[Callable] = None)[source]¶ Make your function configurable by
.jsonpath.- Parameters
func (Callable) – Your arbitrary function.
mode (Optional[OpenTextMode], optional) – An argument same as open in stdlib. Defaults to ‘r’.
buffering (Optional[int], optional) – An argument same as open in stdlib. Defaults to -1.
encoding (Optional[str], optional) – An argument same as open in stdlib. Defaults to None.
errors (Optional[str], optional) – An argument same as open in stdlib. Defaults to None.
newline (Optional[str], optional) – An argument same as open in stdlib. Defaults to None.
closefd (Optional[bool], optional) – An argument same as open in stdlib. Defaults to True.
opener (Optional[Callable], optional) – An argument same as open in stdlib. Defaults to None.
- Returns
Wrapped function which is input from
.jsonpath.- Return type
Callable[[str], Callable]
jcon.json_context module¶
-
jcon.json_context.json_read(jsonpath: str, *args, **kwargs)[source]¶ Context manager to yield
dictfrom path in which .json is.- Parameters
jsonpath (
str) –path/to/file.jsonmode (Optional[OpenTextMode], optional) – An argument same as open in stdlib. Defaults to ‘r’.
buffering (Optional[int], optional) – An argument same as open in stdlib. Defaults to -1.
encoding (Optional[str], optional) – An argument same as open in stdlib. Defaults to None.
errors (Optional[str], optional) – An argument same as open in stdlib. Defaults to None.
newline (Optional[str], optional) – An argument same as open in stdlib. Defaults to None.
closefd (Optional[bool], optional) – An argument same as open in stdlib. Defaults to True.
opener (Optional[Callable], optional) – An argument same as open in stdlib. Defaults to None.
- Yields
dict– returndictread fromjsonpath
jcon.registrable module¶
-
class
jcon.registrable.Registrable[source]¶ Bases:
objectModified from
https://github.com/epwalsh/python-registrableunder its licence Apache 2.0.-
classmethod
by_name(name: str) → Type[T][source]¶ Get a subclass by its registered name, or its fully qualified class name.
- Parameters
cls (Type[T]) – class to register
name (str) – registration name
- Raises
- Returns
The subclass registered under
name.- Return type
Type[T]
-
default_implementation: Optional[str] = None[source]¶ Optional name of default implementation. If specified, the default will be listed first in
registrable.Registrable.list_available().
-
classmethod
from_dict(json_dict: Dict, *args, **kwargs) → Type[Instance][source]¶ Get instance with
dictionaryinitialization.- Parameters
cls (Type[T]) – subclass which is registered.
json_dict (Dict) – the dictionary which have the argument value with its name as key.
- Returns
incetance of subclass
- Return type
Type[T]
-
classmethod
from_json(json_path: str, mode: Optional[OpenTextMode] = 'r', buffering: Optional[int] = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, closefd: Optional[bool] = True, opener: Optional[Callable] = None, *args, **kwargs) → Type[Instance][source]¶ Get instance with
jsoninitialization.- Parameters
cls (Type[T]) – subclass which is registered.
json_path (str) –
path/to/json. The keytypeshould be assigned injsonand the value should be registered by its name.mode (Optional[OpenTextMode], optional) – An argument same as open in stdlib. Defaults to ‘r’.
buffering (Optional[int], optional) – An argument same as open in stdlib. Defaults to -1.
encoding (Optional[str], optional) – An argument same as open in stdlib. Defaults to None.
errors (Optional[str], optional) – An argument same as open in stdlib. Defaults to None.
newline (Optional[str], optional) – An argument same as open in stdlib. Defaults to None.
closefd (Optional[bool], optional) – An argument same as open in stdlib. Defaults to True.
opener (Optional[Callable], optional) – An argument same as open in stdlib. Defaults to None.
- Returns
incetance of subclass
- Return type
Type[Instance]
-
classmethod
hook(hook: Callable[[Type[T], str], None])[source]¶ Function decorator for adding a default hook to a registrable base class.
-
classmethod
iter_registered() → Iterable[Tuple[str, Type[T]]][source]¶ Iterate through the registered names and subclasses.
-
classmethod
list_available() → List[str][source]¶ List all registered subclasses. If
cls.default_implementationis specified, it will be first in the list.
-
classmethod
register(name: str, override: bool = False, hooks: Optional[List[Callable[[Type[T], str], None]]] = None)[source]¶ Class decorator for registering a subclass.
- Parameters
cls (Type[T]) – register class
name (str) – The name to register the subclass under.
override (bool, optional) – If
nameis already registered aregistrable.exceptions.RegistrationErrorwill be raisedthis is set to True. Defaults to False. (unless) –
hooks (Optional[List[HookType]], optional) – Hooks to run when the subclass is registered.. Defaults to None.
- Raises
-
classmethod
-
exception
jcon.registrable.RegistrationError[source]¶ Bases:
jcon.registrable.Error