iotile.core.utilities.schema_verify

Package Contents

class DictionaryVerifier(desc=None, fixed_length=None)

Bases:iotile.core.utilities.schema_verify.verifier.Verifier

Verify the keys and values in a Dictionary

Args:

desc (string): A description of what this dictionary should contain fixed_length (int): An optional restriction on exactly how many keys

can be included in the dict.
add_required(self, key, verifier)

Add a required key by name

Args:
key (string): The key name to match verifier (Verifier): The verification rule
add_optional(self, key, verifier)

Add an optional key by name

Args:
key (string): The key name to match verifier (Verifier): The verification rule
key_rule(self, regex, verifier)

Add a rule with a pattern that should apply to all keys.

Any key not explicitly listed in an add_required or add_optional rule must match ONE OF the rules given in a call to key_rule(). So these rules are all OR’ed together.

In this case you should pass a raw string specifying a regex that is used to determine if the rule is used to check a given key.

Args:
regex (str): The regular expression used to match the rule or None
if this should apply to all

verifier (Verifier): The verification rule

verify(self, obj)

Verify that the object conforms to this verifier’s schema

Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
class ListVerifier(verifier, min_length=None, max_length=None, desc=None)

Bases:iotile.core.utilities.schema_verify.verifier.Verifier

Verify the values in a List

Args:

desc (string): A description of what this list should contain verifier (Verifier): A verifier for what the list should contain.

each entry in the list must match the same verifier.

min_length (int): An optional minimum length for the list max_length (int): An optional maximum length for the list

verify(self, obj)

Verify that the object conforms to this verifier’s schema

Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
class StringVerifier(desc=None)

Bases:iotile.core.utilities.schema_verify.verifier.Verifier

Verify that an object is a string

Args:
desc (string): A description of the verifier
verify(self, obj)

Verify that the object conforms to this verifier’s schema

Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
format(self, indent_level, indent_size=4)

Format this verifier

Returns:
string: A formatted string
class IntVerifier(desc=None)

Bases:iotile.core.utilities.schema_verify.verifier.Verifier

Verify that an object is a integer

Args:
desc (string): A description of the verifier
verify(self, obj)

Verify that the object conforms to this verifier’s schema

Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
format(self, indent_level, indent_size=4)

Format this verifier

Returns:
string: A formatted string
class FloatVerifier(desc=None)

Bases:iotile.core.utilities.schema_verify.verifier.Verifier

Verify that an object is a float.

Args:
desc (string): A description of the verifier
verify(self, obj)

Verify that the object conforms to this verifier’s schema.

Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
format(self, indent_level, indent_size=4)

Format this verifier.

Returns:
string: A formatted string
class BooleanVerifier(require_value=None, desc=None)

Bases:iotile.core.utilities.schema_verify.verifier.Verifier

Verify that an object is a boolean

Args:
desc (string): A description of the verifier require_value (bool): Require a specific True or False value
verify(self, obj)

Verify that the object conforms to this verifier’s schema

Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
format(self, indent_level, indent_size=4)

Format this verifier

Returns:
string: A formatted string
class LiteralVerifier(literal, desc=None)

Bases:iotile.core.utilities.schema_verify.verifier.Verifier

Verify that an object is equal to a literal

Args:
literal (object): A literal value to be checked desc (string): A description of the verifier
verify(self, obj)

Verify that the object conforms to this verifier’s schema

Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
format(self, indent_level, indent_size=4)

Format this verifier

Returns:
string: A formatted string
class OptionsVerifier(*args, **kwargs)

Bases:iotile.core.utilities.schema_verify.verifier.Verifier

Verify that an object is one of a set of options

Args:
*args (Verifier): A set of possible values to compare desc (string): A description of the verifier
verify(self, obj)

Verify that the object conforms to this verifier’s schema

Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
class EnumVerifier(options, desc=None)

Bases:iotile.core.utilities.schema_verify.verifier.Verifier

Verify that an object is one of a list of literal options.

Args:
desc (string): A description of the verifier
verify(self, obj)

Verify that the object conforms to this verifier’s schema.

Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the object, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
format(self, indent_level, indent_size=4)

Format this verifier.

Returns:
string: A formatted string
class BytesVerifier(encoding='none', desc=None)

Bases:iotile.core.utilities.schema_verify.verifier.Verifier

Verify that an object is a (possibly encoded) buffer of octets

Args:

desc (string): A description of the verifier encoding (string): A supported encoding of the bytes, currently must be

one of base64, hex or none. If None is given, the object must be a bytearray type object
verify(self, obj)

Verify that the object conforms to this verifier’s schema

Args:
obj (object): A python object to verify
Returns:
bytes or byterray: The decoded byte buffer
Raises:
ValidationError: If there is a problem verifying the object, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
format(self, indent_level, indent_size=4)

Format this verifier

Returns:
string: A formatted string
class Verifier(desc=None)

A base class for verifying that an object conforms to a schema

Subclasses should override the verify function to actually verify the object that is passed in.

Args:
desc (string): An optional block description of what this verifier is
checking.
clone(self)

Clone this verifier.

This function is useful for implementing hierarch among verifiers where one or more of the verification steps is shared.

For example, a dict that always has key1 and key2 can be pulled into a single DictVerifier and cloned for each variant of the dict.

set_description(self, desc)
matches(self, obj)

Return True if object matches this verifier.

verify(self, obj)

Verify that the object conforms to this verifier’s schema.

Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating the reason for the lack of validation.
_get_short_description(self)

Return the first line of a multiline description

Returns:
string: The short description, otherwise None
_get_long_description(self)

Return the subsequent lines of a multiline description

Returns:
string: The long description, otherwise None
wrap_lines(self, text, indent_level, indent_size=4)

Indent a multiline string

Args:

text (string): The string to indent indent_level (int): The number of indent_size spaces to prepend

to each line
indent_size (int): The number of spaces to prepend for each indent
level
Returns:
string: The indented block of text
format_name(self, name, indent_size=4)

Format the name of this verifier

The name will be formatted as:
<name>: <short description>

long description if one is given followed by

otherwise no long description

Args:

name (string): A name for this validator indent_size (int): The number of spaces to indent the

description
Returns:
string: The formatted name block with a short and or long
description appended.
trim_whitespace(self, text)

Remove leading whitespace from each line of a multiline string

Args:
text (string): The text to be unindented
Returns:
string: The unindented block of text