odML-Support Classes¶
These classes are
Validation¶
-
class
odml.validation.
Validation
(obj, validate=True, reset=False)¶ Validation provides a set of default validations that can used to validate odml objects. Custom validations can be added via the ‘register_handler’ method.
- Parameters
obj – odml object the validation will be applied to.
-
error
(validation_error)¶ Registers an error found during the validation process.
-
register_custom_handler
(klass, handler)¶ Adds a validation handler for an odml class. The handler is called in the validation process for each corresponding object. The handler is assumed to be a generator function yielding all ValidationErrors it finds.
Section handlers are only called for sections and not for the document node. If both are required, the handler needs to be registered twice.
- Parameters
klass – string corresponding to an odml class. Valid strings are ‘odML’, ‘section’ and ‘property’.
handler – validation function applied to the odml class.
-
static
register_handler
(klass, handler)¶ Adds a validation handler for an odml class. The handler is called in the validation process for each corresponding object. The handler is assumed to be a generator function yielding all ValidationErrors it finds.
Section handlers are only called for sections and not for the document node. If both are required, the handler needs to be registered twice.
- Parameters
klass – string corresponding to an odml class. Valid strings are ‘odML’, ‘section’ and ‘property’.
handler – validation function applied to the odml class.
-
report
()¶ Validates the registered object and returns a results report.
-
run_validation
()¶ Runs a clean new validation on the registered Validation object.
-
validate
(obj)¶ Runs all registered handlers that are applicable to a provided odml class instance. Occurring validation errors will be collected in the Validation.error attribute.
- Parameters
obj – odml class instance.
IssueID¶
-
class
odml.validation.
IssueID
(value)¶ IDs identifying registered validation handlers.
-
custom_validation
= 701¶
-
object_name_readable
= 300¶
-
object_required_attributes
= 101¶
-
property_dependency_check
= 401¶
-
property_terminology_check
= 400¶
-
property_unique_ids
= 201¶
-
property_unique_name
= 203¶
-
property_values_cardinality
= 502¶
-
property_values_check
= 402¶
-
property_values_string_check
= 403¶
-
section_properties_cardinality
= 500¶
-
section_repository_present
= 600¶
-
section_sections_cardinality
= 501¶
-
section_type_must_be_defined
= 102¶
-
section_unique_ids
= 200¶
-
section_unique_name_type
= 202¶
-
unspecified
= 1¶
-
ValidationError¶
-
class
odml.validation.
ValidationError
(obj, msg, rank='error', validation_id=None)¶ Represents an error found in the validation process.
The error is bound to an odML-object (obj) or a list of those and contains a message and a rank which may be one of: ‘error’, ‘warning’.
-
property
is_error
¶ - Returns
Boolean whether the current ValidationError has rank ‘Error’.
-
property
is_warning
¶ - Returns
Boolean whether the current ValidationError has rank ‘Warning’.
-
property
path
¶ - Returns
The absolute path to the odml object the ValidationError is bound to.
-
property
TemplateHandler¶
-
class
odml.templates.
TemplateHandler
¶ TemplateHandler facilitates synchronous and deferred loading, caching, browsing and importing of full or partial odML templates.
-
browse
(url)¶ Load, cache and pretty print an odML template XML file from a URL.
- Parameters
url – location of an odML template XML file.
- Returns
The odML document loaded from url.
-
clear
() → None. Remove all items from D.¶
-
clone_section
(url, section_name, children=True, keep_id=False)¶ Load a section by name from an odML template found at the provided URL and return a clone. By default it will return a clone with all child sections and properties as well as changed IDs for every entity. The named section has to be a root (direct) child of the referenced odML document.
- Parameters
url – location of an odML template XML file.
section_name – Unique name of the requested Section.
children – Boolean whether the child entities of a Section will be returned as well. Default is True.
keep_id – Boolean whether all returned entities will keep the original ID or have a new one assigned. Default is False.
- Returns
The cloned odML section loaded from url.
-
copy
() → a shallow copy of D¶
-
deferred_load
(url)¶ Start a background thread to load an odML template from a URL.
- Parameters
url – location of an odML template XML file.
-
fromkeys
(value=None, /)¶ Create a new dictionary with keys from iterable and values set to value.
-
get
(key, default=None, /)¶ Return the value for key if key is in the dictionary, else default.
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
load
(url)¶ Load and cache an odML template from a URL.
- Parameters
url – location of an odML template XML file.
- Returns
The odML document loaded from url.
-
loading
= {}¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, default is returned if given, otherwise KeyError is raised
-
popitem
()¶ Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
-
setdefault
(key, default=None, /)¶ Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-
values
() → an object providing a view on D’s values¶
-
Terminologies¶
-
class
odml.terminology.
Terminologies
¶ Terminologies facilitates synchronous and deferred loading, caching, browsing and importing of full or partial odML terminologies.
-
clear
() → None. Remove all items from D.¶
-
copy
() → a shallow copy of D¶
-
deferred_load
(url)¶ Starts a background thread to load an odML XML file from a URL.
- Parameters
url – location of an odML XML file.
-
fromkeys
(value=None, /)¶ Create a new dictionary with keys from iterable and values set to value.
-
get
(key, default=None, /)¶ Return the value for key if key is in the dictionary, else default.
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
load
(url)¶ Loads and caches an odML XML file from a URL.
- Parameters
url – location of an odML XML file.
- Returns
The odML document loaded from url.
-
loading
= {}¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, default is returned if given, otherwise KeyError is raised
-
popitem
()¶ Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
-
refresh
(url)¶ Deletes and reloads all cached odML XML files given in the terminology file from a URL.
- Parameters
url – location of an odML XML file.
-
reload_cache
= False¶
-
setdefault
(key, default=None, /)¶ Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-
values
() → an object providing a view on D’s values¶
-