Skip to content
Snippets Groups Projects
Commit a2af8c66 authored by vlorentz's avatar vlorentz
Browse files

RPCClient: Make methods {get,post}{,_stream} protected

I want to make swh-objstorage inherit from RPCClient, but its get() and get_stream()
methods would class with RPCClient's.
parent 9c9475f7
No related branches found
No related tags found
1 merge request!249RPCClient: Make methods {get,post}{,_stream} protected
......@@ -21,6 +21,7 @@ from typing import (
Union,
)
from deprecated import deprecated
from flask import Flask, Request, Response, abort, request
import requests
from werkzeug.exceptions import HTTPException
......@@ -255,7 +256,7 @@ class RPCClient(metaclass=MetaRPCClient):
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 @@ class RPCClient(metaclass=MetaRPCClient):
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 @@ class RPCClient(metaclass=MetaRPCClient):
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
......
......@@ -123,7 +123,7 @@ def test_api_typeerror(swh_rpc_client):
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment