diff --git a/swh/core/api/__init__.py b/swh/core/api/__init__.py --- a/swh/core/api/__init__.py +++ b/swh/core/api/__init__.py @@ -21,6 +21,7 @@ Union, ) +from deprecated import deprecated from flask import Flask, Request, Response, abort, request import requests from werkzeug.exceptions import HTTPException @@ -255,7 +256,7 @@ except requests.exceptions.ConnectionError as e: raise self.api_exception(e) - def post(self, endpoint, data, **opts): + def _post(self, endpoint, data, **opts): if isinstance(data, (abc.Iterator, abc.Generator)): data = (self._encode_data(x) for x in data) else: @@ -280,9 +281,17 @@ def _encode_data(self, data): return encode_data(data, extra_encoders=self.extra_type_encoders) - post_stream = post + _post_stream = _post - def get(self, endpoint, **opts): + @deprecated(version="1.2.0", reason="Use _post instead") + def post(self, *args, **kwargs): + return self._post(*args, **kwargs) + + @deprecated(version="1.2.0", reason="Use _post_stream instead") + def post_stream(self, *args, **kwargs): + return self._post_stream(*args, **kwargs) + + def _get(self, endpoint, **opts): chunk_size = opts.pop("chunk_size", self.chunk_size) response = self.raw_verb( "get", endpoint, headers={"accept": "application/x-msgpack"}, **opts @@ -293,8 +302,16 @@ else: return self._decode_response(response) - def get_stream(self, endpoint, **opts): - return self.get(endpoint, stream=True, **opts) + def _get_stream(self, endpoint, **opts): + return self._get(endpoint, stream=True, **opts) + + @deprecated(version="1.2.0", reason="Use _get instead") + def get(self, *args, **kwargs): + return self._get(*args, **kwargs) + + @deprecated(version="1.2.0", reason="Use _get_stream instead") + def get_stream(self, *args, **kwargs): + return self._get_stream(*args, **kwargs) def raise_for_status(self, response) -> None: """check response HTTP status code and raise an exception if it denotes an diff --git a/swh/core/api/tests/test_rpc_client_server.py b/swh/core/api/tests/test_rpc_client_server.py --- a/swh/core/api/tests/test_rpc_client_server.py +++ b/swh/core/api/tests/test_rpc_client_server.py @@ -123,7 +123,7 @@ def test_api_raise_exception_exc_arg(swh_rpc_client): with pytest.raises(RemoteException) as exc_info: - swh_rpc_client.post("raise_exception_exc_arg", data={}) + swh_rpc_client._post("raise_exception_exc_arg", data={}) assert exc_info.value.args[0]["type"] == "Exception" assert type(exc_info.value.args[0]["args"][0]) == Exception