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
.json
path.- 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
.json
path.- Return type
Callable[[str], Callable]
jcon.json_context module¶
-
jcon.json_context.
json_read
(jsonpath: str, *args, **kwargs)[source]¶ Context manager to yield
dict
from path in which .json is.- Parameters
jsonpath (
str
) –path/to/file.json
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.
- Yields
dict
– returndict
read fromjsonpath
jcon.registrable module¶
-
class
jcon.registrable.
Registrable
[source]¶ Bases:
object
Modified from
https://github.com/epwalsh/python-registrable
under 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
dictionary
initialization.- 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
json
initialization.- Parameters
cls (Type[T]) – subclass which is registered.
json_path (str) –
path/to/json
. The keytype
should be assigned injson
and 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_implementation
is 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
name
is already registered aregistrable.exceptions.RegistrationError
will 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