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.
-
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/'¶
-
-
class
Origin
(request_header, **kwargs)[source]¶ Bases:
spresso.model.base.SettingsMixin
Class for validating the origin header of a HTTP Request.
-
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
-
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:
-
-
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.
-
spresso.model.request module¶
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
-
all
()[source]¶ Return all entries of the container.
Returns: The dictionary, containing all entries. Return type: dict
-
-
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
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:
-
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
()¶
-