ocx-common
clients
Module for server clients.
- class ocx_common.clients.clients.CurlRestClient(headers=None, timeout=30)[source]
Bases:
IRestClient,ABCcURL client
- Parameters:
headers – The request headers
timeout – The request timeout
- Parameters:
base_url – base url
timeout – Timeout in ms
- delete(url, payload, headers=None)[source]
Delete method.
- Parameters:
headers – The request header
url – the resource.
payload – The request body.
- Return type:
Response- Returns:
The Response object.
- Raises:
RequestClientError on (HTTPError, ConnectionError). –
- get(url, headers=None)[source]
Get method.
- Parameters:
headers – Request header
url – The resource endpoint
- Return type:
Response- Returns:
The Response object.
- Raises:
CurlClientError if the status code is not 200. –
- patch(url, payload, headers=None)[source]
Patch method.
- Parameters:
headers – The request header
url – the resource.
payload – The request body.
- Return type:
Response- Returns:
The Response object.
- Raises:
RequestClientError on (HTTPError, ConnectionError). –
- post(url, payload, headers=None)[source]
Post method.
- Parameters:
headers – The request headers
url – the resource.
payload – The request body.
- Return type:
Response- Returns:
The Response object.
- Raises:
RequestClientError on pycurl.error. –
- put(url, payload, headers=None)[source]
Put method.
- Parameters:
headers – Request header
url – the resource.
payload – The request body.
- Return type:
Response- Returns:
The Response object.
- Raises:
RequestClientError on (HTTPError, ConnectionError). –
- class ocx_common.clients.clients.EmbeddingMethod(value)[source]
Bases:
EnumEmbedding type.
- BASE64 = 'BASE64'
- STRING = 'STRING'
- URL = 'URL'
- exception ocx_common.clients.clients.RequestClientError(*args, **kwargs)[source]
Bases:
RequestExceptionRequest client errors.
Initialize RequestException with request and response objects.
- class ocx_common.clients.clients.RestClient(headers=None, timeout=30)[source]
Bases:
IRestClient,ABCRequest client
- Parameters:
headers – The request headers
timeout – The request timeout
- Parameters:
base_url – base url
timeout – Timeout in ms
- delete(url, payload, headers=None)[source]
Delete method.
- Parameters:
headers – The request header
url – the resource.
payload – The request body.
- Return type:
Response- Returns:
The Response object.
- Raises:
RequestClientError on (HTTPError, ConnectionError). –
- get(url, headers=None)[source]
Get method.
- Parameters:
headers – The request header dictionary
url – The resource url
- Return type:
Response- Returns:
The request Response object.
- Raises:
RequestClientError on (HTTPError, ConnectionError). –
- patch(url, payload, headers=None)[source]
Patch method.
- Parameters:
headers – The request header
url – the resource.
payload – The request body.
- Return type:
Response- Returns:
The Response object.
- Raises:
RequestClientError on (HTTPError, ConnectionError). –
- post(url, payload, headers=None)[source]
Post method.
- Parameters:
headers – The request headers
url – the resource.
payload – The request body.
- Return type:
Response- Returns:
The Response object.
- Raises:
RequestClientError on (HTTPError, ConnectionError). –
decorators
Reusable decorators
interfaces
Interfaces module.
- class ocx_common.interfaces.interfaces.IModuleDeclaration[source]
Bases:
ABCAbstract module import declaration Interface
- class ocx_common.interfaces.interfaces.IObservable[source]
Bases:
ABCInterface. The observable object.
- class ocx_common.interfaces.interfaces.IParser[source]
Bases:
ABCAbstract IParser interface.
loader
Dynamically load a python module.
- class ocx_common.loader.loader.DeclarationOfOcxImport(name, version)[source]
Bases:
IModuleDeclarationDeclaration of the ocx module.
- class ocx_common.loader.loader.DynamicLoader[source]
Bases:
objectDynamically loads modules, classes of functions from a module declaration.
- classmethod get_all_class_names(module_name, version)[source]
Return all class names in the module by the
__all__variable.- Parameters:
module_name – The module name
version – The module version
- Return type:
List- Returns:
The list of available module class names.
Example
>>> from ocx_common.loader.loader import DeclarationOfOcxImport , DynamicLoader >>> class_name = "Vessel" >>> declaration = DeclarationOfOcxImport("ocx", '3.0.1') >>> data_class = DynamicLoader.import_class(declaration, class_name)() >>> data_class.__doc__ Vessel asset subject to Classification.
- classmethod import_class(module_declaration, class_name)[source]
The module import declaration.
- Parameters:
class_name – The class name to load form the declared module
module_declaration – The declaration of the python module to be loaded
- Return type:
Any- Returns:
Return the loaded class, None if failed.
- exception ocx_common.loader.loader.DynamicLoaderError[source]
Bases:
BaseExceptionDynamic import errors.
- class ocx_common.loader.loader.ModuleDeclaration(package, sub_module, name)[source]
Bases:
IModuleDeclaration,ABCGeneral module declaration
- Parameters:
package – the package name
sub_module – The submodule-name
name – The method name
parser
Module for parsing a 3Docx model.
- class ocx_common.parser.parsers.MetaData[source]
Bases:
objectDataclass metadata.
- static meta_class_fields(data_class)[source]
Return the dataclass metadata.
- Parameters:
data_class – The dataclass instance
- Return type:
Dict- Returns:
The metadata of the class
- class ocx_common.parser.parsers.ObservableEvent(value)[source]
Bases:
EnumEvents that can be listened to and broadcast.
- DATACLASS = 'dataclass'
- REPORT = 'report'
- SERIALIZE = 'serialize'
- class ocx_common.parser.parsers.OcxModelParser(fail_on_unknown_properties=False, fail_on_unknown_attributes=False, fail_on_converter_warnings=True)[source]
Bases:
objectOcxModelParser class for 3Docx XML files.
- Parameters:
ocx_model – The file path or URL to the source model.
- class ocx_common.parser.parsers.OcxNotifyParser(fail_on_unknown_properties=False, fail_on_unknown_attributes=False, fail_on_converter_warnings=True)[source]
Bases:
IObservable,ABCOcx notification parser class for 3Docx XML files.
- Parameters:
fail_on_unknown_properties – Don’t bail out on unknown properties.
fail_on_unknown_attributes – Don’t bail out on unknown attributes
fail_on_converter_warnings – bool = Convert warnings to exceptions
- parse(xml_file)[source]
Parse a 3Docx XML model and return the root dataclass.
- Parameters:
xml_file – The 3Docx xml file or url to parse.
- Return type:
Optional[TypeVar(T)]- Returns:
The root dataclass instance of the parsed 3Docx XML.
- exception ocx_common.parser.parsers.OcxParserError[source]
Bases:
ParserErrorErrors raised by this module.
- class ocx_common.parser.parsers.XsdSchemaParser(target_namespace, location)[source]
Bases:
objectA schema parser parsing an XSD schema and returning the xsdata.models.xsd.Schema.
- Parameters:
- target_namespace – The target namespace of the schema.
- location – The path to the schema XSD file.
utilities
Shared utility classes and functions
- ocx_common.utilities.utilities.all_equal(iterable)[source]
Verify that all items in a list are equal :Parameters: iterable
- Return type:
bool- Returns:
True if all are equal, False otherwise.
- ocx_common.utilities.utilities.camel_case_split(str)[source]
Split camel case string to individual strings.
- Return type:
List
- ocx_common.utilities.utilities.default_to_grid(d)[source]
Converts defaultdicts to a data grid with unique row ids.
- Parameters:
d – The dict to be converted
- Return type:
Dict
- ocx_common.utilities.utilities.default_to_regular(d)[source]
Converts defaultdict of defaultdict to dict of dicts.
- Parameters:
d – The dict to be converted
- Return type:
Dict
- ocx_common.utilities.utilities.dromedary_case_split(str)[source]
Split camel case string to individual strings.
- Return type:
List
- ocx_common.utilities.utilities.file_uri_to_path(uri)[source]
Converts a file:// URI to a proper file system path.
- Return type:
str
- ocx_common.utilities.utilities.get_file_path(file_name)[source]
Get the correct file path also when called within a one-file executable.
- ocx_common.utilities.utilities.get_key_from_value(my_dict, value)[source]
Return the key associated with the value
- Parameters:
my_dict – The dictionary of key, value pairs
value – The value to search for
- Return type:
Any- Returns:
The key if found
- Raises:
ValueError if the value does not exist in the dictionary. –
- ocx_common.utilities.utilities.is_local_file_uri(uri)[source]
Return True if the file uri is a local file
- Return type:
bool
- ocx_common.utilities.utilities.is_substring_in_list(substring, string_list)[source]
- Parameters:
substring – The search string
string_list – List of strings
- Returns:
True if the substring is found, False otherwise.
- ocx_common.utilities.utilities.is_valid_absolute_windows_path(path)[source]
Returns True if the path is a valid absolute Windows path.
- Parameters:
path (str) – The path to validate.
- Return type:
bool- Returns:
bool – True if valid, False otherwise.
- ocx_common.utilities.utilities.is_valid_file_path(path)[source]
- Parameters:
path
Returns:
- Return type:
bool
- ocx_common.utilities.utilities.is_valid_unix_file_path(path)[source]
- Return type:
boolReturn True if the path is a valid UNIX path
- Parameters:
path – path to validate
Returns: True if validated, False otherwise.
- ocx_common.utilities.utilities.is_windows_drive_letter(scheme)[source]
- Parameters:
scheme – The urlparse scheme
- Return type:
bool- Returns:
True if the scheme is a valid Windows drive letter
- ocx_common.utilities.utilities.iter_files(directory, filter_str)[source]
Iterate over files in a directory based on a specified filter pattern.
- Parameters:
directory (str) – The path to the directory.
filter_str (str) – The filter pattern to apply when filtering files.
- Return type:
Generator- Returns:
Generator – A generator yielding file paths that match the filter criteria.
- ocx_common.utilities.utilities.list_files_in_directory(directory, filter)[source]
Lists files in a directory based on a specified filter using glob pattern matching.
- Parameters:
directory (str) – The path to the directory.
filter (str) – The filter pattern to apply when listing files.
- Return type:
List- Returns:
List – A list of file paths that match the filter criteria.
- Raises:
AssertionError – If the directory does not exist.
- ocx_common.utilities.utilities.nested_dict()[source]
A recursive function that creates a default dictionary where each value is another default dictionary.
x_path
A python XPath implementation for OCX types
- class ocx_common.x_path.x_path.OcxPath(document_root, namespaces, extensions=None, regexp=True, smart_strings=True)[source]
Bases:
object
- class ocx_common.x_path.x_path.OcxPathBuilder[source]
Bases:
object- static select_any_nodes_with_attribute_value(attribute_name, attribute_value, namespace='ocx')[source]
- Return type:
str
- static select_any_nodes_with_global_attribute_name(attribute_name, namespace='ocx')[source]
- Return type:
str
- static select_any_nodes_with_local_attribute_name(attribute_name, namespace='ocx')[source]
- Return type:
str
- static select_any_nodes_with_local_value(attribute_name, attribute_value, namespace='ocx')[source]
- Return type:
str
- static select_named_nodes_with_global_attribute_name(node_name, attribute_name, namespace='ocx')[source]
- Return type:
str
- static select_named_nodes_with_global_attribute_value(node_name, attribute_name, attribute_value, namespace='ocx')[source]
- Return type:
str
- static select_named_nodes_with_local_attribute_name(node_name, attribute_name, namespace='ocx')[source]
- Return type:
str