Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/__init__.py
Show First 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | :param Callable[[], backend_class] backend_factory: A function with no | ||||
an instance of | an instance of | ||||
`backend_class`.""" | `backend_class`.""" | ||||
request_class = BytesRequest | request_class = BytesRequest | ||||
def __init__(self, *args, backend_class=None, backend_factory=None, | def __init__(self, *args, backend_class=None, backend_factory=None, | ||||
**kwargs): | **kwargs): | ||||
super().__init__(*args, **kwargs) | super().__init__(*args, **kwargs) | ||||
self.backend_class = backend_class | |||||
if backend_class is not None: | if backend_class is not None: | ||||
if backend_factory is None: | if backend_factory is None: | ||||
raise TypeError('Missing argument backend_factory') | backend_factory = backend_class | ||||
for (meth_name, meth) in backend_class.__dict__.items(): | for (meth_name, meth) in backend_class.__dict__.items(): | ||||
if hasattr(meth, '_endpoint_path'): | if hasattr(meth, '_endpoint_path'): | ||||
self.__add_endpoint(meth_name, meth, backend_factory) | self.__add_endpoint(meth_name, meth, backend_factory) | ||||
def __add_endpoint(self, meth_name, meth, backend_factory): | def __add_endpoint(self, meth_name, meth, backend_factory): | ||||
from flask import request | from flask import request | ||||
@self.route('/'+meth._endpoint_path, methods=['POST']) | @self.route('/'+meth._endpoint_path, methods=['POST']) | ||||
Show All 23 Lines |