quantify_scheduler.json_utils
Module containing quantify JSON utilities.
Module Contents
Classes
A mixin that adds validation utilities to classes that have |
|
The Quantify Schedule JSONDecoder. |
|
Custom JSONEncoder which encodes the quantify Schedule into a JSON file format |
Functions
|
Validate schema using jsonschema-rs |
|
Load a JSON schema from file. Expects a 'schemas' directory in the same directory |
|
Load a JSON validator from file. Expects a 'schemas' directory in the same directory |
Attributes
- load_json_schema(relative_to: Union[str, pathlib.Path], filename: str)[source]
Load a JSON schema from file. Expects a ‘schemas’ directory in the same directory as relative_to.
Tip
Typical usage of the form schema = load_json_schema(__file__, ‘definition.json’)
- Parameters
relative_to – the file to begin searching from
filename – the JSON file to load
- Returns
the schema
- Return type
- load_json_validator(relative_to: Union[str, pathlib.Path], filename: str) Callable [source]
Load a JSON validator from file. Expects a ‘schemas’ directory in the same directory as relative_to.
- Parameters
relative_to – the file to begin searching from
filename – the JSON file to load
- Returns
The validator
- Return type
Callable
- class JSONSchemaValMixin[source]
A mixin that adds validation utilities to classes that have a data attribute like a
UserDict
based on JSONSchema.This requires the class to have a class variable “schema_filename”
- classmethod is_valid(object_to_be_validated) bool [source]
Checks if the object is valid according to its schema
- Raises
fastjsonschema.JsonSchemaException – if the data is invalid
- class ScheduleJSONDecoder(*args, **kwargs)[source]
Bases:
json.JSONDecoder
The Quantify Schedule JSONDecoder.
The ScheduleJSONDecoder is used to convert a string with JSON content into a
quantify_scheduler.schedules.schedule.Schedule
.To avoid the execution of malicious code ScheduleJSONDecoder uses
ast.literal_eval()
instead ofeval()
to convert the data to an instance of Schedule.- decode_dict(obj: Dict[str, Any]) Dict[str, Any] [source]
Returns the deserialized JSON dictionary.
- Parameters
obj – The dictionary to deserialize.
- Returns
The deserialized result.
- decode_quantify_type(obj: str) object [source]
Returns the deserialized result of a possible known type stored in the
ScheduleJSONDecoder
.classes property.For better security the usage of eval has been replaced in favour of
ast.literal_eval()
.- Parameters
obj – The value of dictionary pair to deserialize.
- Returns
The decoded result.
- class ScheduleJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Bases:
json.JSONEncoder
Custom JSONEncoder which encodes the quantify Schedule into a JSON file format string.