swh.core.api package¶
Submodules¶
Module contents¶
-
class
swh.core.api.
JSONFormatter
(request_mimetype: Optional[str] = None)[source]¶ Bases:
swh.core.api.Formatter
-
format
: Optional[str] = 'json'¶
-
mimetypes
: List[str] = ['application/json']¶
-
-
class
swh.core.api.
MsgpackFormatter
(request_mimetype: Optional[str] = None)[source]¶ Bases:
swh.core.api.Formatter
-
format
: Optional[str] = 'msgpack'¶
-
mimetypes
: List[str] = ['application/x-msgpack']¶
-
-
exception
swh.core.api.
RemoteException
(payload: Optional[Any] = None, response: Optional[requests.models.Response] = None)[source]¶ Bases:
Exception
raised when remote returned an out-of-band failure notification, e.g., as a HTTP status code or serialized exception
-
response
¶ HTTP response corresponding to the failure
-
-
class
swh.core.api.
MetaRPCClient
(name, bases, attributes)[source]¶ Bases:
type
Metaclass for RPCClient, which adds a method for each endpoint of the database it is designed to access.
See for example
swh.indexer.storage.api.client.RemoteStorage
-
class
swh.core.api.
RPCClient
(url, api_exception=None, timeout=None, chunk_size=4096, reraise_exceptions=None, **kwargs)[source]¶ Bases:
object
Proxy to an internal SWH RPC
-
backend_class
= None¶ For each method of backend_class decorated with
remote_api_endpoint()
, a method with the same prototype and docstring will be added to this class. Calls to this new method will be translated into HTTP requests to a remote server.This backend class will never be instantiated, it only serves as a template.
-
extra_type_encoders
: List[Tuple[type, str, Callable]] = []¶ Value of extra_encoders passed to json_dumps or msgpack_dumps to be able to serialize more object types.
-
extra_type_decoders
: Dict[str, Callable] = {}¶ Value of extra_decoders passed to json_loads or msgpack_loads to be able to deserialize more object types.
-
api_exception
¶ The exception class to raise in case of communication error with the server.
alias of
swh.core.api.APIError
-
reraise_exceptions
: ClassVar[List[Type[Exception]]] = []¶ On server errors, if any of the exception classes in this list has the same name as the error name, then the exception will be instantiated and raised instead of a generic RemoteException.
-
post_stream
(endpoint, data, **opts)¶
-
-
class
swh.core.api.
BytesRequest
(environ, populate_request=True, shallow=False)[source]¶ Bases:
flask.wrappers.Request
Request with proper escaping of arbitrary byte sequences.
-
encoding
= 'utf-8'¶
-
encoding_errors
= 'surrogateescape'¶
-
-
swh.core.api.
encode_data_server
(data, content_type='application/x-msgpack', extra_type_encoders=None)[source]¶
-
class
swh.core.api.
RPCServerApp
(*args, backend_class=None, backend_factory=None, **kwargs)[source]¶ Bases:
flask.app.Flask
For each endpoint of the given backend_class, tells app.route to call a function that decodes the request and sends it to the backend object provided by the factory.
- Parameters
backend_class (Any) – The class of the backend, which will be analyzed to look for API endpoints.
backend_class]] backend_factory (Optional[Callable[[],) – A function with no argument that returns an instance of backend_class. If unset, defaults to calling backend_class constructor directly.
-
request_class
¶ alias of
swh.core.api.BytesRequest
-
extra_type_encoders
: List[Tuple[type, str, Callable]] = []¶ Value of extra_encoders passed to json_dumps or msgpack_dumps to be able to serialize more object types.
-
extra_type_decoders
: Dict[str, Callable] = {}¶ Value of extra_decoders passed to json_loads or msgpack_loads to be able to deserialize more object types.