quantify_scheduler.json_utils

Module containing quantify JSON utilities.

Module Contents

Classes

JSONSchemaValMixin

A mixin that adds validation utilities to classes that have

ScheduleJSONDecoder

The Quantify Schedule JSONDecoder.

ScheduleJSONEncoder

Custom JSONEncoder which encodes the quantify Schedule into a JSON file format

Functions

validate_json(data, schema)

Validate schema using jsonschema-rs

load_json_schema(relative_to, filename)

Load a JSON schema from file. Expects a 'schemas' directory in the same directory

load_json_validator(→ Callable)

Load a JSON validator from file. Expects a 'schemas' directory in the same directory

Attributes

current_python_version

lru_cache

current_python_version[source]
lru_cache[source]
validate_json(data, schema)[source]

Validate schema using jsonschema-rs

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

dict

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 of eval() to convert the data to an instance of Schedule.

classes :Dict[str, Type[Any]][source]
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.

custom_object_hook(obj: object) object[source]

The object_hook hook will be called with the result of every JSON object decoded and its return value will be used in place of the given dict.

Parameters

obj – A pair of JSON objects.

Returns

The deserialized 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.

default(o)[source]

Overloads the json.JSONEncoder default method that returns a serializable object. It will try 3 different serialization methods which are, in order, check if the object is to be serialized to a string using repr. If not, try to use __getstate__. Finally, try to serialize the __dict__ property.