X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fhttp.py;h=867db2da04162b020618475ae4886ec4828050f0;hb=3b9e2c9599832958c8b8bf7c85433a76f65bd043;hp=60f0a49a3d29682ee1e4b1568ffe0c0ed5fd3749;hpb=0a7f1259519c504ddb2b47b9c47b6c0543144145;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/http.py b/osmclient/sol005/http.py index 60f0a49..867db2d 100644 --- a/osmclient/sol005/http.py +++ b/osmclient/sol005/http.py @@ -17,9 +17,7 @@ from io import BytesIO import pycurl import json -import yaml from osmclient.common import http -from osmclient.common.exceptions import ClientException class Http(http.Http): @@ -50,7 +48,7 @@ class Http(http.Http): curl_cmd.close() # TODO 202 accepted should be returned somehow if data.getvalue(): - return http_code, json.loads(data.getvalue().decode()) + return http_code, data.getvalue().decode() else: return http_code, None @@ -60,11 +58,10 @@ class Http(http.Http): data = BytesIO() curl_cmd = self._get_curl_cmd(endpoint) if put_method: - curl_cmd.setopt(pycurl.PUT, 1) + curl_cmd.setopt(pycurl.CUSTOMREQUEST, "PUT") elif patch_method: curl_cmd.setopt(pycurl.CUSTOMREQUEST, "PATCH") - else: - curl_cmd.setopt(pycurl.POST, 1) + curl_cmd.setopt(pycurl.POST, 1) curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write) if postfields_dict is not None: @@ -77,28 +74,17 @@ class Http(http.Http): (pycurl.FORM_FILE, formfile[1])))]) elif filename is not None: - with open(filename, 'r') as stream: + with open(filename, 'rb') as stream: postdata=stream.read() curl_cmd.setopt(pycurl.POSTFIELDS, postdata) curl_cmd.perform() http_code = curl_cmd.getinfo(pycurl.HTTP_CODE) curl_cmd.close() - if http_code not in (200, 201, 202, 204): - raise ClientException(data.getvalue().decode()) - if postfields_dict is not None: - if data.getvalue(): - return json.loads(data.getvalue().decode()) - return None - elif formfile is not None: - if data.getvalue(): - return yaml.safe_load(data.getvalue().decode()) - return None - elif filename is not None: - if data.getvalue(): - return yaml.safe_load(data.getvalue().decode()) - return None - return None + if data.getvalue(): + return http_code, data.getvalue().decode() + else: + return http_code, None def post_cmd(self, endpoint='', postfields_dict=None, formfile=None, filename=None): @@ -133,6 +119,6 @@ class Http(http.Http): http_code = curl_cmd.getinfo(pycurl.HTTP_CODE) curl_cmd.close() if data.getvalue(): - return http_code, data.getvalue() + return http_code, data.getvalue().decode() return http_code, None