cis_interface.metaschema package

Subpackages

Submodules

cis_interface.metaschema.encoder module

class cis_interface.metaschema.encoder.JSONReadableEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: json.encoder.JSONEncoder

Encoder class for CiS messages.

default(o)[source]

Encoder that allows for expansion types.

cis_interface.metaschema.encoder.decode_json(msg, **kwargs)[source]

Decode a Python object from a JSON serialization.

Parameters:
  • msg (str) – JSON serialization to decode.
  • **kwargs – Additional keyword arguments are passed to json.loads.
Returns:

Deserialized Python object.

Return type:

object

cis_interface.metaschema.encoder.encode_json(obj, fd=None, indent=None, sort_keys=True, **kwargs)[source]

Encode a Python object in JSON format.

Parameters:
  • obj (object) – Python object to encode.
  • fd (file, optional) – File descriptor for file that encoded object should be written to. Defaults to None and string is returned.
  • indent (int, str, optional) – Indentation for new lines in encoded string. Defaults to None.
  • sort_keys (bool, optional) – If True, the keys will be output in sorted order. Defaults to True.
  • **kwargs – Additional keyword arguments are passed to json.dumps.
Returns:

Encoded object.

Return type:

str, bytes

cis_interface.metaschema.encoder.indent_char2int(indent)[source]

Convert a character indent into a number of spaces that should be used. Tabs are set to be equivalent to 4 spaces.

Parameters:indent (str) – String indent.
Returns:Number of whitespaces that is equivalent to the provided string.
Return type:int

cis_interface.metaschema.normalizer module

class cis_interface.metaschema.normalizer.UndefinedProperty[source]

Bases: object

Class to be used as a flag for undefined properties.

class cis_interface.metaschema.normalizer.UninitializedNormalized[source]

Bases: object

Class to be used as a flag for uninitialized normalized value.

cis_interface.metaschema.normalizer.create(*args, **kwargs)[source]

Dynamically create a validation/normalization class that subclasses the jsonschema validation class.

Parameters:
  • normalizers (dict, optional) – Keys are tuples representing paths that exist within the schema at which the normalization functions stored in lists as their value counterparts should be executed. Defaults to empty dictionary.
  • no_defaults (bool, optional) – If True, defaults will not be set during normalization. Defaults to False.
  • required_defaults (bool, optional) – If True, defaults will be set for required properties, even if no_defaults is True. Defaults to False.
  • *args – Additional arguments are passed to jsonschema.validators.create.
  • **kwargs – Additional keyword arguments are passed to jsonschema.validators.create.

Module contents

cis_interface.metaschema.create_metaschema(overwrite=False)[source]

Create the meta schema for validating cis schema.

Parameters:overwrite (bool, optional) – If True, the existing meta schema will be overwritten. If False and the metaschema exists, an error will be raised. Defaults to False.
Returns:
Meta schema specifying rules for cis type schema. This includes
all original JSON schema rules with the addition of types and property definitions.
Return type:dict
Raises:RuntimeError – If the file already exists and overwrite is False.
cis_interface.metaschema.get_metaschema()[source]

Return the meta schema for validating cis schema.

Returns:
Meta schema specifying rules for cis type schema. This includes
all original JSON schema rules with the addition of types and property definitions.
Return type:dict

Note

This function should not be called at the module level as it can cause the metaschema (if it dosn’t exist) to be generated before all of the necessary modules have been loaded.

cis_interface.metaschema.get_validator(overwrite=False, normalizers=None, **kwargs)[source]

Return the validator that includes cis expansion types.

Parameters:
  • overwrite (bool, optional) – If True, the existing validator will be overwritten. Defaults to False.
  • normalizers (dict, optional) – Additional normalizers to add.
  • **kwargs – Additional keyword arguments are passed to normalizer.create.
Returns:

JSON schema validator.

Return type:

jsonschema.IValidator

cis_interface.metaschema.import_all_classes()[source]

Import all metaschema classes (types and properties).

cis_interface.metaschema.normalize_instance(obj, schema, **kwargs)[source]

Normalize an object using the provided schema.

Parameters:
  • obj (object) – Object to be normalized using the provided schema.
  • schema (dict) – Schema to use to normalize the provided object.
  • **kwargs – Additional keyword arguments are passed to normalize.
Returns:

Normalized instance.

Return type:

object

cis_interface.metaschema.validate_instance(obj, schema, **kwargs)[source]

Validate an instance against a schema.

Parameters:
  • obj (object) – Object to be validated using the provided schema.
  • schema (dict) – Schema to use to validate the provided object.
  • **kwargs – Additional keyword arguments are passed to validate.
Raises:

ValidationError – If the object is not valid.

cis_interface.metaschema.validate_schema(obj)[source]

Validate a schema against the metaschema.

Parameters:obj (dict) – Schema to be validated.
Raises:ValidationError – If the schema is not valid.