Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/__init__.py
# Copyright (C) 2015-2017 The Software Heritage developers | # Copyright (C) 2015-2017 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import collections | import collections | ||||
import functools | import functools | ||||
import inspect | import inspect | ||||
import json | import json | ||||
import logging | import logging | ||||
import pickle | import pickle | ||||
import requests | import requests | ||||
import datetime | import datetime | ||||
from typing import ClassVar, Optional, Type | from typing import ClassVar, Optional, Type | ||||
from deprecated import deprecated | |||||
from flask import Flask, Request, Response, request, abort | from flask import Flask, Request, Response, request, abort | ||||
from .serializers import (decode_response, | from .serializers import (decode_response, | ||||
encode_data_client as encode_data, | encode_data_client as encode_data, | ||||
msgpack_dumps, msgpack_loads, SWHJSONDecoder) | msgpack_dumps, msgpack_loads, SWHJSONDecoder) | ||||
from .negotiation import (Formatter as FormatterBase, | from .negotiation import (Formatter as FormatterBase, | ||||
Negotiator as NegotiatorBase, | Negotiator as NegotiatorBase, | ||||
negotiate as _negotiate) | negotiate as _negotiate) | ||||
▲ Show 20 Lines • Show All 298 Lines • ▼ Show 20 Lines | 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']) | ||||
@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))) | return encode_data_server(obj_meth(**decode_request(request))) | ||||
@deprecated(version='0.0.64', | |||||
reason='Use the RPCServerApp instead') | |||||
class SWHServerAPIApp(RPCServerApp): | |||||
pass | |||||
@deprecated(version='0.0.64', | |||||
reason='Use the MetaRPCClient instead') | |||||
class MetaSWHRemoteAPI(MetaRPCClient): | |||||
pass | |||||
@deprecated(version='0.0.64', | |||||
reason='Use the RPCClient instead') | |||||
class SWHRemoteAPI(RPCClient): | |||||
pass |