mex.common.connector package¶
Submodules¶
mex.common.connector.base module¶
- class mex.common.connector.base.BaseConnector¶
Bases:
object
Base class for connectors that are handled as singletons.
- abstract __init__() None ¶
Create a new connector instance.
- abstract close() None ¶
Close the connector’s underlying sockets.
- final classmethod get() Self ¶
Get the singleton instance for this class from the store.
- class mex.common.connector.base._ConnectorStore¶
Bases:
SingletonStore
[BaseConnector
]Thin wrapper for storing thread-local singletons of connectors.
- reset() None ¶
Close all connectors and remove them from the singleton store.
mex.common.connector.http module¶
- class mex.common.connector.http.HTTPConnector¶
Bases:
BaseConnector
Base class for requests-based HTTP connectors.
- TIMEOUT = 10¶
- __init__() None ¶
Create a new http connection.
- _check_availability() None ¶
Send a GET request to verify the host is available.
- _send_request(method: str, url: str, params: Mapping[str, list[str] | str | None] | None, **kwargs: Any) Response ¶
Send the response with advanced retrying rules.
- _set_authentication() None ¶
Authenticate to the host.
- _set_session() None ¶
Create and set request session.
- abstract _set_url() None ¶
Set url of the host.
- close() None ¶
Close the connector’s underlying requests session.
- request(method: Literal['OPTIONS', 'POST', 'GET', 'PUT', 'DELETE'], endpoint: str | None = None, payload: Any = None, params: Mapping[str, list[str] | str | None] | None = None, **kwargs: Any) dict[str, Any] ¶
Prepare and send a request with error handling and payload de/serialization.
- Parameters:
method – HTTP method to use
endpoint – Path to API endpoint to be prefixed with host and version
payload – Data to be serialized as JSON using the MExEncoder
params – Dictionary to be sent in the query string of the request
kwargs – Further keyword arguments passed to requests
- Raises:
RequestException – Error from requests that can’t be solved with a retry
HTTPError – Re-raised HTTP error with (truncated) response body
JSONDecodeError – If body of response cannot be parsed correctly
- Returns:
Parsed JSON body of the response
- url: str = ''¶
Module contents¶
- class mex.common.connector.BaseConnector¶
Bases:
object
Base class for connectors that are handled as singletons.
- abstract __init__() None ¶
Create a new connector instance.
- abstract close() None ¶
Close the connector’s underlying sockets.
- final classmethod get() Self ¶
Get the singleton instance for this class from the store.
- class mex.common.connector.HTTPConnector¶
Bases:
BaseConnector
Base class for requests-based HTTP connectors.
- TIMEOUT = 10¶
- __init__() None ¶
Create a new http connection.
- _check_availability() None ¶
Send a GET request to verify the host is available.
- _send_request(method: str, url: str, params: Mapping[str, list[str] | str | None] | None, **kwargs: Any) Response ¶
Send the response with advanced retrying rules.
- _set_authentication() None ¶
Authenticate to the host.
- _set_session() None ¶
Create and set request session.
- abstract _set_url() None ¶
Set url of the host.
- close() None ¶
Close the connector’s underlying requests session.
- request(method: Literal['OPTIONS', 'POST', 'GET', 'PUT', 'DELETE'], endpoint: str | None = None, payload: Any = None, params: Mapping[str, list[str] | str | None] | None = None, **kwargs: Any) dict[str, Any] ¶
Prepare and send a request with error handling and payload de/serialization.
- Parameters:
method – HTTP method to use
endpoint – Path to API endpoint to be prefixed with host and version
payload – Data to be serialized as JSON using the MExEncoder
params – Dictionary to be sent in the query string of the request
kwargs – Further keyword arguments passed to requests
- Raises:
RequestException – Error from requests that can’t be solved with a retry
HTTPError – Re-raised HTTP error with (truncated) response body
JSONDecodeError – If body of response cannot be parsed correctly
- Returns:
Parsed JSON body of the response
- url: str = ''¶