angelos.document.model

Model module.

Contains the document model. A document is made up of a number of fields. All fields are self-validating. Also all classes based on the BaseDocument can implement validation.

class angelos.document.model.BaseDocument(nd: dict = {}, strict: bool = True)

Bases: object

Field magic behind the scenes.

Implements basic field handling and some export and validation logic.

Parameters
  • nd (dict) – Dicrtionary of initial values.

  • strict (bool) – Strict validation of attributes, throws exception.

_fields

Internal holder of the Field classes used.

Type

dict

apply_rules() → bool

Apply all rules on BaseDocument level.

Returns

Result of validation.

Return type

bool

classmethod build(data: dict)angelos.document.model.DocumentMeta

Build document from dictionary, takes dict or list of dicts.

Parameters
  • cls (DocumentMeta) – class type to build.

  • data (dict) – data representation to be populated.

Returns

Polupated document.

Return type

type

export(c=<built-in function conv_dont>) → dict

Export a document as a dictionary.

Fields can be converted during export into String or Bytes.

Parameters

c (type) – Convertion activator to be used.

Returns

Dictionary representation with converted values.

Return type

dict

export_bytes()

Export values converted to bytes

Returns

Dictionary with bytes representation of values.

Return type

dict

export_str()

Export values converted to string.

Returns

Dictionary with string representation of values.

Return type

dict

export_yaml()

Export values converted to string in YAML format.

Returns

Dictionary with string representation of values as YAML.

Return type

dict

classmethod fields() → tuple

Tuple of all field names.

validate() → bool

Abstract document validator.

Should be implemented by all final document implementations.

Returns

Description of returned object.

Return type

bool

class angelos.document.model.BinaryField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None, limit: int = 1024)

Bases: angelos.document.model.Field

Binary or bytes field.

Parameters
  • value (Any) – Preconfigured value.

  • required (bool) – Whether the field is required or not.

  • multiple (bool) – Whether the field allows multiple values.

  • init (Callable) – Initializing method to be used.

  • limit (int) – Max bytes limit for field.

limit
TYPES = (<class 'bytes'>,)
bytes(v: Any)bytes

Abstract for converting value to bytes.

Parameters

v (Any) – Value to be converted.

Returns

Value in bytes representation.

Return type

bytes

from_bytes(v: bytes) → Any

Restore field from bytes.

Parameters

v (bytes) – Value representation in bytes.

Returns

Returns restored field.

Return type

Any

str(v: Any)str

Converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

yaml(v: Any)angelos.document.model.BinaryField.str

Converting value to YAML string.

Parameters

v (Any) – Value to be converted.

Returns

Value as YAML formatted string.

Return type

str

class angelos.document.model.ChoiceField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None, choices: list = [])

Bases: angelos.document.model.StringField

Choice field.

Parameters
  • value (Any) – Preconfigured value.

  • required (bool) – Whether the field is required or not.

  • multiple (bool) – Whether the field allows multiple values.

  • init (Callable) – Initializing method to be used.

  • choices (list) – List of available choices.

choices
validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

class angelos.document.model.DateField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None)

Bases: angelos.document.model.Field

Date field.

TYPES = (<class 'datetime.date'>,)
bytes(v: Any)bytes

Abstract for converting value to bytes.

Parameters

v (Any) – Value to be converted.

Returns

Value in bytes representation.

Return type

bytes

from_bytes(v: bytes) → Any

Restore field from bytes.

Parameters

v (bytes) – Value representation in bytes.

Returns

Returns restored field.

Return type

Any

str(v: Any)str

Converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

yaml(v: Any)angelos.document.model.DateField.str

Converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

class angelos.document.model.DateTimeField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None)

Bases: angelos.document.model.Field

Date and time field.

TYPES = (<class 'datetime.datetime'>,)
bytes(v: Any)bytes

Abstract for converting value to bytes.

Parameters

v (Any) – Value to be converted.

Returns

Value in bytes representation.

Return type

bytes

from_bytes(v: bytes) → Any

Restore field from bytes.

Parameters

v (bytes) – Value representation in bytes.

Returns

Returns restored field.

Return type

Any

str(v: Any)str

Converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

yaml(v: Any)angelos.document.model.DateTimeField.str

Converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

class angelos.document.model.DocumentField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None, doc_class: Type[angelos.document.model.BaseDocument] = <class 'angelos.document.model.BaseDocument'>)

Bases: angelos.document.model.Field

Field that holds one or several Documents as field.

Parameters
  • value (Any) – Preconfigured value.

  • required (bool) – Whether the field is required or not.

  • multiple (bool) – Whether the field allows multiple values.

  • init (Callable) – Initializing method to be used.

  • doc_class (Type[BaseDocument]) – Set a type to be accepted in particular.

type

Document type allowed.

Type

Any

TYPES = ()
from_bytes(v: Union[bytes, dict]) → Any

Restore field from bytes.

Parameters

v (bytes) – Value representation in bytes.

Returns

Returns restored field.

Return type

Any

validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

class angelos.document.model.DocumentMeta(name: unicode, bases: tuple, namespace: dict)

Bases: type

Meta implementation of Document.

Implements accumulation of all field into one namespace.

class angelos.document.model.EmailField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None)

Bases: angelos.document.model.RegexField

Email field.

Parameters
  • value (Any) – Preconfigured value.

  • required (bool) – Whether the field is required or not.

  • multiple (bool) – Whether the field allows multiple values.

  • init (Callable) – Initializing method to be used.

REGEX

Regular expression for validating email.

Type

tuple(str)

REGEX = ('^(?:[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*|"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$',)
validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

class angelos.document.model.Field(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None)

Bases: abc.ABC

Base class for all fields.

Implements basic functionality for fields such as support for init value or function, multiple values, whether required and validation checks thereof.

Parameters
  • value (Any) – Preconfigured value.

  • required (bool) – Whether the field is required or not.

  • multiple (bool) – Whether the field allows multiple values.

  • init (Callable) – Initializing method to be used.

value

Same as parameter.

required

Same as parameter.

multiple

Same as parameter.

init

Same as parameter.

TYPES = ()
bytes(v: Any)bytes

Abstract for converting value to bytes.

Parameters

v (Any) – Value to be converted.

Returns

Value in bytes representation.

Return type

bytes

from_bytes(v: bytes) → Any

Abstract to restore field from bytes.

Parameters

v (bytes) – Value representation in bytes.

Returns

Returns restored field.

Return type

Any

str(v: Any)str

Abstract for converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

yaml(v: Any)angelos.document.model.Field.str

Converting value to YAML string.

Parameters

v (Any) – Value to be converted.

Returns

Value as YAML formatted string.

Return type

str

exception angelos.document.model.FieldError

Bases: angelos.common.policy.PolicyException

Exception class for errors with fields.

FIELDS_ARE_REQUIRED = ('Fields are required.', 615)
FIELD_BEYOND_LIMIT = ('Given data to large', 608)
FIELD_INVALID_CHOICE = ('Value not among acceptable choices', 603)
FIELD_INVALID_DATA = ('Invalid data', 617)
FIELD_INVALID_REGEX = ('Given email not a regular email address', 607)
FIELD_INVALID_TYPE = ('Value type is invalid', 602)
FIELD_IS_MULTIPLE = ('Value is not list, but set to multiple', 609)
FIELD_NOT_MULTIPLE = ('Value is list, but not set to multiple', 601)
FIELD_NOT_SET = ('Required value is not set', 600)
FIELD_UNKNOWN = ('Named field is unknown', 616)
class angelos.document.model.IPField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None)

Bases: angelos.document.model.Field

IP address field.

TYPES = (<class 'ipaddress.IPv4Address'>, <class 'ipaddress.IPv6Address'>)
bytes(v: Any)bytes

Abstract for converting value to bytes.

Parameters

v (Any) – Value to be converted.

Returns

Value in bytes representation.

Return type

bytes

from_bytes(v: bytes) → Any

Restore field from bytes.

Parameters

v (bytes) – Value representation in bytes.

Returns

Returns restored field.

Return type

Any

str(v: Any)str

Converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

yaml(v: Any)angelos.document.model.IPField.str

Converting value to YAML string.

Parameters

v (Any) – Value to be converted.

Returns

Value as YAML formatted string.

Return type

str

class angelos.document.model.RegexField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None)

Bases: angelos.document.model.StringField

Email field.

Parameters
  • value (Any) – Preconfigured value.

  • required (bool) – Whether the field is required or not.

  • multiple (bool) – Whether the field allows multiple values.

  • init (Callable) – Initializing method to be used.

REGEX

Regular expression for validating email.

Type

str

REGEX = ('^(.*)$',)
validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

class angelos.document.model.SignatureField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None, limit: int = 1024)

Bases: angelos.document.model.BinaryField

Signature field.

Parameters
  • value (Any) – Preconfigured value.

  • required (bool) – Whether the field is required or not.

  • multiple (bool) – Whether the field allows multiple values.

  • init (Callable) – Initializing method to be used.

  • limit (int) – Max bytes limit for field.

redo

Description of attribute redo.

Type

type

limit
validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

class angelos.document.model.StringField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None)

Bases: angelos.document.model.Field

String field.

TYPES = (<class 'str'>,)
bytes(v: Any)bytes

Abstract for converting value to bytes.

Parameters

v (Any) – Value to be converted.

Returns

Value in bytes representation.

Return type

bytes

from_bytes(v: bytes) → Any

Restore field from bytes.

Parameters

v (bytes) – Value representation in bytes.

Returns

Returns restored field.

Return type

Any

str(v: Any)str

Converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

yaml(v: Any)angelos.document.model.StringField.str

Converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

class angelos.document.model.TypeField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None)

Bases: angelos.document.model.Field

Document type field

TYPES = (<class 'int'>,)
bytes(v: Any)bytes

Abstract for converting value to bytes.

Parameters

v (Any) – Value to be converted.

Returns

Value in bytes representation.

Return type

bytes

from_bytes(v: bytes) → Any

Restore field from bytes.

Parameters

v (bytes) – Value representation in bytes.

Returns

Returns restored field.

Return type

Any

str(v: Any)str

Converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

yaml(v: Any)angelos.document.model.TypeField.str

Converting value to YAML string.

Parameters

v (Any) – Value to be converted.

Returns

Value as YAML formatted string.

Return type

str

class angelos.document.model.UuidField(value: Any = None, required: bool = True, multiple: bool = False, init: Callable = None)

Bases: angelos.document.model.Field

UUID field.

TYPES = (<class 'uuid.UUID'>,)
bytes(v: Any)bytes

Converting value to bytes.

Parameters

v (Any) – Value to be converted.

Returns

Value in bytes representation.

Return type

bytes

from_bytes(v: bytes) → Any

Restore field from bytes.

Parameters

v (bytes) – Value representation in bytes.

Returns

Returns restored field.

Return type

Any

str(v: Any)str

Converting value to string.

Parameters

v (Any) – Value to be converted.

Returns

Value in string representation.

Return type

str

validate(*args, **kwargs)

Wrapping the callable.

Parameters
  • self (class) – Method owner

  • *args – Any arguments

  • **kwargs – Any keyword arguments

Returns

The result from the callable

yaml(v: Any)angelos.document.model.UuidField.str

Converting value to YAML string.

Parameters

v (Any) – Value to be converted.

Returns

Value as YAML formatted string.

Return type

str

angelos.document.model.conv_bytes()

Bytes conversion activator.

Parameters
  • f (Field) – Field type for conversion.

  • v (Any) – Value to be converted.

Returns

Bytes representation of value.

Return type

bytes

angelos.document.model.conv_dont()

None conversion activator.

Parameters
  • f (Field) – Dummy argument for compatibility.

  • v (any) – Value not to be converted.

Returns

Returns the value unaltered.

Return type

Any

angelos.document.model.conv_str()

Str conversion activator.

Parameters
  • f (Field) – Field type for conversion.

  • v (Any) – Value to be converted.

Returns

String representation of value.

Return type

str

angelos.document.model.conv_yaml()

YAML conversion activator.

Parameters
  • f (Field) – Field type for conversion.

  • v (Any) – Value to be converted.

Returns

YAML formatted string representation of value or None.

Return type

str