Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/__init__.py
Show First 20 Lines • Show All 321 Lines • ▼ Show 20 Lines | def __init__(self, *args, backend_class=None, backend_factory=None, | ||||
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']) | ||||
@negotiate(MsgpackFormatter) | |||||
@negotiate(JSONFormatter) | |||||
@functools.wraps(meth) # Copy signature and doc | @functools.wraps(meth) # Copy signature and doc | ||||
def _f(): | def _f(): | ||||
# Call the actual code | # Call the actual code | ||||
obj_meth = getattr(backend_factory(), meth_name) | obj_meth = getattr(backend_factory(), meth_name) | ||||
return encode_data_server(obj_meth(**decode_request(request))) | kw = decode_request(request) | ||||
return obj_meth(**kw) | |||||
@deprecated(version='0.0.64', | @deprecated(version='0.0.64', | ||||
reason='Use the RPCServerApp instead') | reason='Use the RPCServerApp instead') | ||||
class SWHServerAPIApp(RPCServerApp): | class SWHServerAPIApp(RPCServerApp): | ||||
pass | pass | ||||
Show All 10 Lines |