spresso.model package

Submodules

spresso.model.base module

class Composition[source]

Bases: dict

Extension to dict, defining the base for all SPRESSO specific objects used by the system. Enables object-like access to dictionary instances, as well as import from JSON and export to JSON.

from_json(data)[source]

Unserialize an object from a string representation.

Parameters:data (str) – The serialized object.
to_json()[source]

Serialize an object to JSON. The keys are sorted, as some operations in the SPRESSO flow depend on a unique representation. json.dumps is used, because data is transmitted over the web.

Returns:The serialized object.
Return type:str
class JsonSchema[source]

Bases: object

Class to provide a schema validator.

file_path = ''
get_schema()[source]

Load a JSON schema from the resource folder.

Returns:The JSON schema.
Return type:str
resource_path = 'resources/'
validate(data_dict)[source]

Retrieve the schema and validate the obtained data.

Parameters:data_dict (dict) – The data dictionary.
class Origin(request_header, **kwargs)[source]

Bases: spresso.model.base.SettingsMixin

Class for validating the origin header of a HTTP Request.

expected

Retrieve the valid header.

Returns:The origin header.
Return type:str
valid

Compare the correct and the obtained header using urllib.parse.urlparse().

Returns:
bool: Validity of the obtained origin header.
class SettingsMixin(settings)[source]

Bases: object

Mixin class for assigning a configuration object.

class User(email, regexp='^[^#&]+@([a-zA-Z0-9-.]+)$')[source]

Bases: object

Basic user model.

basic_check()[source]

Match the email address against a regular expression and therefore check its validity.

Returns:Statement if the regex matched against the email address.
Return type:bool
is_valid

Test if the email is valid.

Returns:Validity of the email address.
Return type:bool
netloc

Check if the email is valid and get the domain part.

Returns:The domain of the email address or None.

spresso.model.cache module

class Cache(settings)[source]

Bases: spresso.model.base.SettingsMixin

Class to provide a central caching object. The object handles the caching settings and manages a dictionary of CacheEntry instances.

cache = {}
get(handle)[source]

Retrieve cached data.

Parameters:handle (str) – The unique identifier.
Returns:None or the cached data.
set(handle, settings, data)[source]

Create and store a CacheEntry.

Parameters:
  • handle (str) – The unique identifier.
  • settings (CachingSetting) – The caching configuration.
  • data (str) – The data to be cached.
class CacheEntry(lifetime, in_memory)[source]

Bases: object

A class to represent a cache entry. Provides methods to check its validity, set data and get data.

get_data()[source]

Retrieve data from a cache entry, if the cache entry is valid. The data is either loaded from memory or from the file system.

Returns:None or the cached data.
set_data(data)[source]

Set data on a cache entry. The data can be saved in memory or as a temporary file.

Parameters:data (str) – The data to be cached.
valid

Validate the lifetime of a cache entry.

Returns:The validity.
Return type:bool

spresso.model.request module

class GetRequest(scheme, netloc, path, verify, proxies)[source]

Bases: object

Class to resolve GET requests, based on the requests package. Enables the use of proxy servers and the verification of public key certificates.

request()[source]

Performs a GET request.

Returns:

The response object, returned by requests.get().

Raises:
  • SpressoInvalidError – A connection error occurred during the
  • request or the status code of the response is not OK.

spresso.model.settings module

class CachingSetting(name, in_memory, lifetime)[source]

Bases: spresso.model.settings.Entry

Caching configuration entry. Defines the storage type as well as the lifetime.

class Container(*args, name=None)[source]

Bases: spresso.model.settings.Entry

Container class that holds instances of type Entry and itself
is an Entry.
all()[source]

Return all entries of the container.

Returns:The dictionary, containing all entries.
Return type:dict
get(name)[source]

Return an entry from the container.

Parameters:name (str) – Unique identifier of the entry.
Returns:The entry.
Return type:Entry
update(entry)[source]

Updates the container with an entry.

Parameters:entry (Entry) – The entry to be included.
class Domain(name, domain)[source]

Bases: spresso.model.settings.Entry

Domain configuration entry.

class Endpoint(name, path, methods)[source]

Bases: spresso.model.settings.Entry

URL endpoint configuration entry. Enables the configuration of the path and the supported HTTP methods.

class Entry[source]

Bases: object

Basic configuration entry class.

name = None
class ForwardDomain(*args, padding=True)[source]

Bases: spresso.model.settings.Domain

Forward domain configuration entry. Extends Domain by additional security settings.

class Schema(name, schema)[source]

Bases: spresso.model.settings.Entry

JSON schema configuration entry. References a JsonSchema object.

class SelectionContainer(strategy, *args, default=None, **kwargs)[source]

Bases: spresso.model.settings.Container

A specialized container, which returns entries based on a selection strategy. A default return value can be provided. Supported selection strategies are:

  • random: Choose a random Entry from the dictionary.
  • select: Choose a fixed Entry from the dictionary.
default_id = 'default'
select(name=None)[source]

Return an entry from the dictionary. In case of the “select” strategy a name has to be specified.

Parameters:name (str) – Unique identifier.
Returns:None or an entry from the dictionary.
set_random()
set_select_or_default()
set_strategy(strategy)[source]

Set the selection strategy.

Parameters:strategy (str) – The selection strategy.
update_default(value)[source]

Update the default return value.

Parameters:value (str) – The new default entry.

Module contents