From: Michael Tremer Date: Fri, 2 Dec 2016 13:06:15 +0000 (+0100) Subject: http: Move support for decoding strings into HTTP client X-Git-Tag: 0.9.28~1285^2~1427 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7773b2cee60fb0719b6a5f39250170eb3637bb25;p=pakfire.git http: Move support for decoding strings into HTTP client Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/http.py b/src/pakfire/http.py index 36d001195..de8065837 100644 --- a/src/pakfire/http.py +++ b/src/pakfire/http.py @@ -164,13 +164,13 @@ class Client(object): return content def _decode_content(self, type, content): - assert type in ("json") + assert type in ("ascii", "json") # Decode from bytes to string content = content.decode("ascii") - # Parse JSON try: + # Parse JSON if type == "json": content = json.loads(content) diff --git a/src/pakfire/hub.py b/src/pakfire/hub.py index 5c9336a5d..84c74cb4f 100644 --- a/src/pakfire/hub.py +++ b/src/pakfire/hub.py @@ -58,9 +58,7 @@ class Hub(object): """ Tests the connection """ - s = self._request("/noop") - - return s.decode("ascii") + return self._request("/noop", decode="ascii") def test_error(self, code): assert code >= 100 and code <= 999 @@ -90,9 +88,7 @@ class Hub(object): "upload_id" : upload_id, } - build_id = self._request("/builds/create", data=data) - - return build_id.decode("ascii") + return self._request("/builds/create", data=data, decode="ascii") # Job actions @@ -159,9 +155,7 @@ class FileUploader(object): "hash" : self._make_checksum("sha1", self.path), } - response = self.hub._request("/uploads/create", method="GET", data=data) - - return response.decode("ascii") + return self.hub._request("/uploads/create", method="GET", decode="ascii", data=data) def _send_chunk(self, upload_id, chunk): """