aria Package

This is the core ARIA API.

aria

aria.install_aria_extensions()

Iterates all Python packages with names beginning with aria_extension_ and calls their install_aria_extension function if they have it.

class aria.Issue(message=None, exception=None, location=None, line=None, column=None, locator=None, snippet=None, level=0)

Bases: object

ALL = 100
BETWEEN_FIELDS = 3
BETWEEN_INSTANCES = 5
BETWEEN_TYPES = 4
EXTERNAL = 6
FIELD = 2
PLATFORM = 0
SYNTAX = 1
as_raw
details_as_str
heading_as_str
locator_as_str
exception aria.AriaError(message=None, cause=None, cause_tb=None)

Bases: exceptions.Exception

Base class for ARIA errors.

exception aria.UnimplementedFunctionalityError(message=None, cause=None, cause_tb=None)

Bases: aria.exceptions.AriaError

ARIA error: functionality is unimplemented.

exception aria.InvalidValueError(message, cause=None, cause_tb=None, location=None, line=None, column=None, locator=None, snippet=None, level=2)

Bases: aria.exceptions.AriaError

ARIA error: value is invalid.

aria.dsl_specification(section, spec)

Decorator for TOSCA specification.

Used for documentation and standards compliance.

aria.iter_spec(spec)

aria.consumption

exception aria.consumption.ConsumerError(message=None, cause=None, cause_tb=None)

Bases: aria.exceptions.AriaError

ARIA consumer error.

class aria.consumption.ConsumptionContext

Bases: object

Properties:

class aria.consumption.Style(indentation=2)

Bases: object

indent
literal(value)
meta(value)
node(value)
property(value)
section(value)
type(value)
class aria.consumption.Consumer(context)

Bases: object

Base class for ARIA consumers.

Consumers provide useful functionality by consuming presentations.

consume()
dump()
class aria.consumption.ConsumerChain(context, consumer_classes=None, handle_exceptions=True)

Bases: aria.consumption.consumer.Consumer

ARIA consumer chain.

Calls consumers in order, handling exception by calling _handle_exception on them, and stops the chain if there are any validation issues.

append(*consumer_classes)
consume()
class aria.consumption.Presentation(context)

Bases: aria.consumption.consumer.Consumer

Generates the presentation.

It works by consuming a data source via appropriate aria.loader.Loader, aria.reader.Reader, and aria.presenter.Presenter instances.

It supports agnostic raw data composition for presenters that have _get_import_locations and _merge_import.

To improve performance, loaders are called asynchronously on separate threads.

Note that parsing may internally trigger more than one loading/reading/presentation cycle, for example if the agnostic raw data has dependencies that must also be parsed.

consume()
dump()
class aria.consumption.ValidationContext

Bases: object

dump_issues()
has_issues
issues
report(message=None, exception=None, location=None, line=None, column=None, locator=None, snippet=None, level=0, issue=None)
class aria.consumption.Validation(context)

Bases: aria.consumption.consumer.Consumer

Validates the presentation.

consume()
dump()
class aria.consumption.Yaml(context)

Bases: aria.consumption.consumer.Consumer

Emits the presentation’s raw data as YAML.

dump()
class aria.consumption.Template(context)

Bases: aria.consumption.consumer.ConsumerChain

Generates the deployment template by deriving it from the presentation.

dump()
class aria.consumption.Inputs(context)

Bases: aria.consumption.consumer.Consumer

Fills in the inputs if provided as arguments.

consume()
class aria.consumption.Plan(context)

Bases: aria.consumption.consumer.ConsumerChain

Generates the deployment plan by instantiating the deployment template.

dump()
class aria.consumption.Types(context)

Bases: aria.consumption.consumer.Consumer

Emits the type hierarchies, highlighting inheritance and overrides.

dump()

aria.deployment

exception aria.deployment.CannotEvaluateFunction(message=None, cause=None, cause_tb=None)

Bases: aria.exceptions.AriaError

ARIA could not evaluate the function at this time.

class aria.deployment.IdType

Bases: object

LOCAL_RANDOM = 1
LOCAL_SERIAL = 0
UNIVERSAL_RANDOM = 2
class aria.deployment.DeploymentContext

Bases: object

Properties:

  • id_type: Type of IDs to use for instances
  • id_max_length: Maximum allowed instance ID length
  • inputs: Dict of inputs values
  • template: The generated deployment template
  • plan: The generated deployment plan
  • node_types: The generated hierarchy of node types
  • capability_types: The generated hierarchy of capability types
  • relationship_types: The generated hierarchy of relationship types
dump_types(context)
generate_id()
get_plan_as_json(indent=None)
get_plan_as_yaml(indent=None)
plan_as_raw
class aria.deployment.Element

Bases: object

as_raw
coerce_values(context, container, report_issues)
dump(context)
validate(context)
class aria.deployment.Template

Bases: aria.deployment.elements.Element

instantiate(context, container)
class aria.deployment.Function

Bases: object

as_raw
class aria.deployment.Parameter(type_name, value, description)

Bases: aria.deployment.elements.Template

as_raw
coerce_values(context, container, report_issues)
instantiate(context, container)
class aria.deployment.Metadata

Bases: aria.deployment.elements.Template

as_raw
dump(context)
instantiate(context, container)
class aria.deployment.Interface(name)

Bases: aria.deployment.elements.Template

as_raw
coerce_values(context, container, report_issues)
dump(context)
instantiate(context, container)
validate(context)
class aria.deployment.Operation(name)

Bases: aria.deployment.elements.Template

as_raw
coerce_values(context, container, report_issues)
dump(context)
instantiate(context, container)
class aria.deployment.Artifact(name, type_name, source_path)

Bases: aria.deployment.elements.Template

as_raw
coerce_values(context, container, report_issues)
dump(context)
instantiate(context, container)
class aria.deployment.GroupPolicy(name)

Bases: aria.deployment.elements.Template

as_raw
coerce_values(context, container, report_issues)
dump(context)
instantiate(context, container)
class aria.deployment.GroupPolicyTrigger(name, source)

Bases: aria.deployment.elements.Template

as_raw
coerce_values(context, container, report_issues)
dump(context)
instantiate(context, container)
class aria.deployment.DeploymentPlan

Bases: aria.deployment.elements.Element

as_raw
coerce_values(context, container, report_issues)
dump(context)
dump_graph(context)
find_groups(group_template_name)
find_nodes(node_template_name)
get_group_ids(group_template_name)
get_node_ids(node_template_name)
is_node_a_target(context, target_node)
satisfy_requirements(context)
validate(context)
validate_capabilities(context)
class aria.deployment.Node(context, type_name, template_name)

Bases: aria.deployment.elements.Element

as_raw
coerce_values(context, container, report_issues)
dump(context)
satisfy_requirements(context)
validate(context)
validate_capabilities(context)
class aria.deployment.Capability(name, type_name)

Bases: aria.deployment.elements.Element

as_raw
coerce_values(context, container, report_issues)
dump(context)
has_enough_relationships
relate()
class aria.deployment.Relationship(type_name=None, template_name=None)

Bases: aria.deployment.elements.Element

as_raw
coerce_values(context, container, report_issues)
dump(context)
validate(context)
class aria.deployment.Group(context, type_name, template_name)

Bases: aria.deployment.elements.Element

as_raw
coerce_values(context, container, report_issues)
dump(context)
validate(context)
class aria.deployment.Policy(name, type_name)

Bases: aria.deployment.elements.Element

as_raw
dump(context)
class aria.deployment.Mapping(mapped_name, node_id, name)

Bases: aria.deployment.elements.Element

as_raw
dump(context)
class aria.deployment.Substitution(node_type_name)

Bases: aria.deployment.elements.Element

as_raw
dump(context)
class aria.deployment.DeploymentTemplate

Bases: aria.deployment.elements.Template

dump(context)
instantiate(context, container)
validate(context)
class aria.deployment.NodeTemplate(name, type_name)

Bases: aria.deployment.elements.Template

dump(context)
instantiate(context, container)
is_target_node_valid(target_node_template)
validate(context)
class aria.deployment.Requirement(name=None, target_node_type_name=None, target_node_template_name=None, target_capability_type_name=None, target_capability_name=None)

Bases: aria.deployment.elements.Element

dump(context)
find_target(context, source_node_template)
find_target_capability(context, source_node_template, target_node_template)
validate(context)
class aria.deployment.CapabilityTemplate(name, type_name)

Bases: aria.deployment.elements.Template

dump(context)
instantiate(context, container)
satisfies_requirement(context, source_node_template, requirement, target_node_template)
validate(context)
class aria.deployment.RelationshipTemplate(type_name=None, template_name=None)

Bases: aria.deployment.elements.Template

dump(context)
instantiate(context, container)
validate(context)
class aria.deployment.GroupTemplate(name, type_name=None)

Bases: aria.deployment.elements.Template

dump(context)
instantiate(context, container)
class aria.deployment.PolicyTemplate(name, type_name)

Bases: aria.deployment.elements.Template

dump(context)
instantiate(context, container)
class aria.deployment.MappingTemplate(mapped_name, node_template_name, name)

Bases: aria.deployment.elements.Template

dump(context)
instantiate(context, container)
validate(context)
class aria.deployment.SubstitutionTemplate(node_type_name)

Bases: aria.deployment.elements.Template

dump(context)
instantiate(context, container)
validate(context)
class aria.deployment.TypeHierarchy

Bases: aria.deployment.types.Type

class aria.deployment.Type(name)

Bases: object

dump(context)
get_descendant(name)
get_parent(name)
is_descendant(base_name, name)
iter_descendants()
class aria.deployment.RelationshipType(name)

Bases: aria.deployment.types.Type

aria.loading

exception aria.loading.LoaderError(message=None, cause=None, cause_tb=None)

Bases: aria.exceptions.AriaError

ARIA loader error.

exception aria.loading.LoaderNotFoundError(message=None, cause=None, cause_tb=None)

Bases: aria.loading.exceptions.LoaderError

ARIA loader error: loader not found for source.

exception aria.loading.DocumentNotFoundError(message=None, cause=None, cause_tb=None)

Bases: aria.loading.exceptions.LoaderError

ARIA loader error: document not found.

class aria.loading.LoadingContext

Bases: object

Properties:

  • loader_source: For finding loader instances
  • search_paths: List of additional search paths FileTextLoader
class aria.loading.Loader

Bases: object

Base class for ARIA loaders.

Loaders extract a document by consuming a document source.

Though the extracted document is often textual (a string or string-like data), loaders may provide any format.

close()
load()
open()
class aria.loading.LoaderSource

Bases: object

Base class for ARIA loader sources.

Loader sources provide appropriate Loader instances for locations.

A LiteralLocation is handled specially by wrapping the literal value in a LiteralLoader.

get_loader(context, location, origin_location)
class aria.loading.DefaultLoaderSource

Bases: aria.loading.source.LoaderSource

The default ARIA loader source will generate a UriTextLoader for locations that are non-file URIs, and a FileTextLoader for file URIs.

get_loader(context, location, origin_location)
class aria.loading.Location

Bases: object

is_equivalent(location)
search_path
class aria.loading.UriLocation(uri)

Bases: aria.loading.location.Location

as_file
is_equivalent(location)
search_path
class aria.loading.LiteralLocation(content)

Bases: aria.loading.location.Location

is_equivalent(location)
class aria.loading.LiteralLoader(location)

Bases: aria.loading.loader.Loader

ARIA literal loader.

This loader is a trivial holder for the provided value.

load()
class aria.loading.UriLoader(location, headers={})

Bases: aria.loading.loader.Loader

Base class for ARIA URI loaders.

Extracts a document from a URI.

Note that the “file:” schema is not supported: FileTextLoader should be used instead.

open()
class aria.loading.UriTextLoader(location, headers={})

Bases: aria.loading.uri.UriLoader

ARIA URI text loader.

load()
class aria.loading.FileTextLoader(context, location, origin_location, encoding='utf-8')

Bases: aria.loading.loader.Loader

ARIA file text loader.

Extracts a text document from a file. The default encoding is UTF-8, but other supported encoding can be specified instead.

Supports a list of search paths that are tried in order if the file cannot be found. They can be specified in the context, as well as globally in FILE_LOADER_SEARCH_PATHS.

If origin_location is provided, a base path will be extracted from it and prepended to the search paths.

close()
load()
open()

aria.presentation

exception aria.presentation.PresenterError(message=None, cause=None, cause_tb=None)

Bases: aria.exceptions.AriaError

ARIA presenter error.

exception aria.presentation.PresenterNotFoundError(message=None, cause=None, cause_tb=None)

Bases: aria.presentation.exceptions.PresenterError

ARIA presenter error: presenter not found for raw.

class aria.presentation.PresentationContext

Bases: object

Properties:

  • location: From where we will generate the presenter
  • presenter: The generated presenter instance
  • presenter_source: For finding presenter classes
  • presenter_class: Overrides presenter_source with a specific class
  • threads: Number of threads to use when reading data
  • timeout: Timeout in seconds for loading data
  • print_exceptions: Whether to print exceptions while reading data
class aria.presentation.Presenter(name=None, raw=None, container=None)

Bases: aria.presentation.presentation.Presentation

Base class for ARIA presenters.

Presenters provide a robust API over agnostic raw data.

artifact_types
capability_types
data_types
group_types
groups
inputs
interface_types
node_templates
node_types
outputs
policies
policy_triggers
policy_types
relationship_templates
relationship_types
repositories
workflows
class aria.presentation.Value(the_type, value)

Bases: object

class aria.presentation.PresentationBase(name=None, raw=None, container=None)

Bases: aria.utils.caching.HasCachedMethods

Base class for ARIA presentation classes.

class aria.presentation.Presentation(name=None, raw=None, container=None)

Bases: aria.presentation.presentation.PresentationBase

Base class for ARIA presentations. A presentation is a Pythonic wrapper around agnostic raw data, adding the ability to read and modify the data with proper validation.

ARIA presentation classes will often be decorated with @has_fields, as that mechanism automates a lot of field-specific validation. However, that is not a requirement.

Make sure that your utility property and method names begin with a “_”, because those names without a “_” prefix are normally reserved for fields.

class aria.presentation.AsIsPresentation(name=None, raw=None, container=None)

Bases: aria.presentation.presentation.PresentationBase

Base class for trivial ARIA presentations that provide the raw value as is.

value
class aria.presentation.FakePresentation(name=None, raw=None, container=None)

Bases: aria.presentation.presentation.PresentationBase

Instances of this class are useful as placeholders when a presentation is required but unavailable.

class aria.presentation.PresenterSource

Bases: object

Base class for ARIA presenter sources.

Presenter sources provide appropriate Presenter classes for agnostic raw data.

get_presenter(raw)
class aria.presentation.DefaultPresenterSource(classes=[])

Bases: aria.presentation.source.PresenterSource

The default ARIA presenter source supports TOSCA Simple Profile and Cloudify DSLs.

get_presenter(raw)
class aria.presentation.Field(field_variant, fn, cls=None, default=None, allowed=None, required=False)

Bases: object

dump(presentation, context)
fullclass
fullname
get(presentation)
get_locator(raw)
set(presentation, value)
validate(presentation, context)
aria.presentation.has_fields(cls)

Class decorator for validated field support.

  1. Adds a FIELDS class property that is a dict of all the fields. Will inherit and merge FIELDS properties from base classes if they have them.
  2. Generates automatic @property implementations for the fields with the help of a set of special function decorators.

The class also works with the Python dict protocol, so that fields can be accessed via dict semantics. The functionality is identical to that of using attribute access.

The class will also gain two utility methods, _iter_field_names and _iter_fields.

aria.presentation.short_form_field(name)

Class decorator for specifying the short form field.

The class must be decorated with has_fields().

aria.presentation.allow_unknown_fields(cls)

Class decorator specifying that the class allows unknown fields.

The class must be decorated with has_fields().

aria.presentation.primitive_field(cls=None, default=None, allowed=None, required=False)

Function decorator for primitive fields.

The function must be a method in a class decorated with has_fields().

aria.presentation.primitive_list_field(cls=None, default=None, allowed=None, required=False)

Function decorator for list of primitive fields.

The function must be a method in a class decorated with has_fields().

aria.presentation.primitive_dict_field(cls=None, default=None, allowed=None, required=False)

Function decorator for dict of primitive fields.

The function must be a method in a class decorated with has_fields().

aria.presentation.primitive_dict_unknown_fields(cls=None, default=None, allowed=None, required=False)

Function decorator for dict of primitive fields, for all the fields that are not already decorated.

The function must be a method in a class decorated with has_fields().

aria.presentation.object_field(cls, default=None, allowed=None, required=False)

Function decorator for object fields.

The function must be a method in a class decorated with has_fields().

aria.presentation.object_list_field(cls, default=None, allowed=None, required=False)

Function decorator for list of object fields.

The function must be a method in a class decorated with has_fields().

aria.presentation.object_dict_field(cls, default=None, allowed=None, required=False)

Function decorator for dict of object fields.

The function must be a method in a class decorated with has_fields().

aria.presentation.object_sequenced_list_field(cls, default=None, allowed=None, required=False)

Function decorator for sequenced list of object fields.

The function must be a method in a class decorated with has_fields().

aria.presentation.object_dict_unknown_fields(cls, default=None, allowed=None, required=False)

Function decorator for dict of object fields, for all the fields that are not already decorated.

The function must be a method in a class decorated with has_fields().

aria.presentation.field_getter(getter_fn)

Function decorator for overriding the getter function of a field.

The signature of the getter function must be: f(field, presentation). The default getter can be accessed as field._get(presentation).

The function must already be decorated with a field decorator.

aria.presentation.field_setter(setter_fn)

Function decorator for overriding the setter function of a field.

The signature of the setter function must be: f(field, presentation, value). The default setter can be accessed as field._set(presentation, value).

The function must already be decorated with a field decorator.

aria.presentation.field_validator(validator_fn)

Function decorator for overriding the validator function of a field.

The signature of the validator function must be: :code:f(field, presentation, context)`. The default validator can be accessed as field._validate(presentation, context).

The function must already be decorated with a field decorator.

aria.presentation.type_validator(type_name, types_dict_name)

Makes sure that the field refers to an existing type defined in the root presenter.

Can be used with the field_validator() decorator.

aria.presentation.list_type_validator(type_name, types_dict_name)

Makes sure that the field’s elements refer to existing types defined in the root presenter.

Assumes that the field is a list.

Can be used with the field_validator() decorator.

aria.presentation.list_length_validator(length)

Makes sure the field has exactly a specific number of elements.

Assumes that the field is a list.

Can be used with the field_validator() decorator.

aria.presentation.derived_from_validator(types_dict_name)

Makes sure that the field refers to a valid parent type defined in the root presenter.

Can be used with the field_validator() decorator.

aria.presentation.validate_no_short_form(presentation, context)

Makes sure that we can use short form definitions only if we allowed it.

aria.presentation.validate_no_unknown_fields(presentation, context)

Make sure that we can use unknown fields only if we allowed it.

aria.presentation.validate_known_fields(presentation, context)

Validates all known fields.

aria.presentation.report_issue_for_unknown_type(context, presentation, type_name, field_name, value=None)
aria.presentation.report_issue_for_parent_is_self(context, presentation, field_name)
aria.presentation.report_issue_for_circular_type_hierarchy(context, presentation, field_name)

aria.reading

exception aria.reading.ReaderError(message=None, cause=None, cause_tb=None)

Bases: aria.exceptions.AriaError

ARIA reader error.

exception aria.reading.ReaderNotFoundError(message=None, cause=None, cause_tb=None)

Bases: aria.reading.exceptions.ReaderError

ARIA reader error: reader not found for source.

exception aria.reading.ReaderSyntaxError(message, cause=None, cause_tb=None, location=None, line=None, column=None, locator=None, snippet=None, level=1)

Bases: aria.reading.exceptions.ReaderError

ARIA read format error.

exception aria.reading.AlreadyReadError(message=None, cause=None, cause_tb=None)

Bases: aria.reading.exceptions.ReaderError

ARIA reader error: already read.

class aria.reading.Reader(context, location, loader)

Bases: object

Base class for ARIA readers.

Readers provide agnostic raw data by consuming aria.loader.Loader instances.

load()
read()
class aria.reading.ReaderSource

Bases: object

Base class for ARIA reader sources.

Reader sources provide appropriate Reader instances for locations.

get_reader(context, location, loader)
class aria.reading.DefaultReaderSource(literal_reader_class=<class 'aria.reading.yaml.YamlReader'>)

Bases: aria.reading.source.ReaderSource

The default ARIA reader source will generate a YamlReader for locations that end in ”.yaml”, a JsonReader for locations that end in ”.json”, and a JinjaReader for locations that end in ”.jinja”.

get_reader(context, location, loader)
class aria.reading.ReadingContext

Bases: object

Properties:

  • reader_source: For finding reader instances
  • reader: Overrides reader_source with a specific class
class aria.reading.RawReader(context, location, loader)

Bases: aria.reading.reader.Reader

ARIA raw reader.

Expects to receive agnostic raw data from the loader, and so does nothing to it.

read()
aria.reading.init_yaml()
class aria.reading.Locator(location, line, column)

Bases: object

Stores location information (line and column numbers) for agnostic raw data.

dump(key=None)
get_child(name)
get_grandchild(name1, name2)
merge(locator)
class aria.reading.YamlReader(context, location, loader)

Bases: aria.reading.reader.Reader

ARIA YAML reader.

read()
class aria.reading.JsonReader(context, location, loader)

Bases: aria.reading.reader.Reader

ARIA JSON reader.

read()
class aria.reading.JinjaReader(context, location, loader)

Bases: aria.reading.reader.Reader

ARIA Jinja reader.

Forwards the rendered result to a new reader in the reader source.

read()

aria.utils

class aria.utils.OpenClose(wrapped)

Bases: object

Wraps an object that has open() and close() methods to support the “with” keyword.

class aria.utils.cachedmethod(fn)

Bases: object

Decorator for caching method return values.

The implementation is thread-safe.

Supports cache_info to be compatible with Python 3’s functools.lru_cache. Note that the statistics are combined for all instances of the class.

Won’t use the cache if not called when bound to an object, allowing you to override the cache.

Adapted from this solution.

cache_info()
reset_cache_info()
class aria.utils.HasCachedMethods

Bases: object

Provides convenience methods for working with cachedmethod.

class aria.utils.JsonAsRawEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)

Bases: json.encoder.JSONEncoder

A JSONEncoder that will use the as_raw property of objects if available.

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, long, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true (the default), all non-ASCII characters in the output are escaped with uXXXX sequences, and the results are str instances consisting of ASCII characters only. If ensure_ascii is False, a result may be a unicode instance. This usually happens if the input contains unicode strings or the encoding parameter is used.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. Since the default item separator is ‘, ‘, the output might include trailing whitespace when indent is specified. You can use separators=(‘,’, ‘: ‘) to avoid this.

If specified, separators should be a (item_separator, key_separator) tuple. The default is (‘, ‘, ‘: ‘). To get the most compact JSON representation you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

If encoding is not None, then all input strings will be transformed into unicode using that encoding prior to JSON-encoding. The default is UTF-8.

default(o)
aria.utils.classname(o)

The full class name of an object.

aria.utils.make_agnostic(value)

Converts subclasses of list and dict to standard lists and dicts, recursively.

Useful for creating human-readable output of structures.

class aria.utils.ReadOnlyList(*args, **kwargs)

Bases: list

An immutable list.

After initialization it will raise TypeError exceptions if modification is attempted.

Note that objects stored in the list may not be immutable.

append(value)
extend(values)
insert(index, value)
class aria.utils.ReadOnlyDict(*args, **kwargs)

Bases: collections.OrderedDict

An immutable ordered dict.

After initialization it will raise TypeError exceptions if modification is attempted.

Note that objects stored in the dict may not be immutable.

class aria.utils.StrictList(items=None, value_class=None, wrapper_fn=None, unwrapper_fn=None)

Bases: list

A list that raises TypeError exceptions when objects of the wrong type are inserted.

append(value)
extend(values)
insert(index, value)
class aria.utils.StrictDict(items=None, key_class=None, value_class=None, wrapper_fn=None, unwrapper_fn=None)

Bases: collections.OrderedDict

An ordered dict that raises TypeError exceptions when keys or values of the wrong type are used.

aria.utils.merge(a, b, path=[], strict=False)

Merges dicts, recursively.

aria.utils.prune(value, is_removable_fn=<function is_removable>)

Deletes nulls and empty lists and dicts, recursively.

aria.utils.deepcopy_with_locators(value)

Like deepcopy, but also copies over locators.

aria.utils.copy_locators(target, source)

Copies over _locator for all elements, recursively.

Assumes that target and source have exactly the same list/dict structure.

aria.utils.print_exception(e, full=True, cause=False, tb=None)

Prints the exception with nice colors and such.

aria.utils.print_traceback(tb=None)

Prints the traceback with nice colors and such.

aria.utils.import_fullname(name, paths=[])

Imports a variable or class based on a full name, optionally searching for it in the paths.

aria.utils.import_modules(name)

Imports a module and all its sub-modules, recursively. Relies on modules defining a ‘MODULES’ attribute listing their sub-module names.

exception aria.utils.ExecutorException

Bases: exceptions.Exception

class aria.utils.FixedThreadPoolExecutor(size=25, timeout=None, print_exceptions=False)

Bases: object

Executes tasks in a fixed thread pool.

Makes sure to gather all returned results and thrown exceptions in one place, in order of task submission.

Example:

def sum(arg1, arg2):
    return arg1 + arg2
    
executor = FixedThreadPoolExecutor(10)
try:
    for value in range(100):
        executor.submit(sum, value, value)
    executor.drain()
except:
    executor.close()
executor.raise_first()
print executor.returns

You can also use it with the Python “with” keyword, in which case you don’t need to call “close” explicitly:

with FixedThreadPoolExecutor(10) as executor:
    for value in range(100):
        executor.submit(sum, value, value)
    executor.drain()
    executor.raise_first()
    print executor.returns
Parameters:
  • size – Number of threads in the pool (fixed).
  • timeout – Timeout in seconds for all blocking operations. (Defaults to none, meaning no timeout)
  • print_exceptions – Set to true in order to print exceptions from tasks. (Defaults to false)
close()

Blocks until all current tasks finish execution and all worker threads are dead.

You cannot submit tasks anymore after calling this.

This is called automatically upon exit if you are using the “with” keyword.

drain()

Blocks until all current tasks finish execution, but leaves the worker threads alive.

exceptions

The raised exceptions from all tasks, in order of submission.

is_alive

True if any of the worker threads are alive.

raise_first()

If exceptions were thrown by any task, then the first one will be raised.

This is rather arbitrary: proper handling would involve iterating all the exceptions. However, if you want to use the “raise” mechanism, you are limited to raising only one of them.

returns

The returned values from all tasks, in order of submission.

submit(fn, *args, **kwargs)

Submit a task for execution.

The task will be called ASAP on the next available worker thread in the pool.

Will raise an ExecutorException exception if cannot be submitted.

class aria.utils.LockedList(*args, **kwargs)

Bases: list

A list that supports the “with” keyword with a built-in lock.

Though Python lists are thread-safe in that they will not raise exceptions during concurrent access, they do not guarantee atomicity. This class will let you gain atomicity when needed.

class aria.utils.ArgumentParser(prog=None, usage=None, description=None, epilog=None, version=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True)

Bases: argparse.ArgumentParser

Applied patch to fix this issue.

aria.utils.puts(s='', newline=True, stream=<built-in method write of file object>)
class aria.utils.colored
static black(string, always=False, bold=False)
static blue(string, always=False, bold=False)
static cyan(string, always=False, bold=False)
static green(string, always=False, bold=False)
static magenta(string, always=False, bold=False)
static red(string, always=False, bold=False)
static white(string, always=False, bold=False)
static yellow(string, always=False, bold=False)
aria.utils.indent(indent=4, quote='')

Indentation manager, return an indentation context manager.