fix sol005 client so that delete_cmd output is processed in the caller function
[osm/osmclient.git] / osmclient / sol005 / http.py
index 20593b8..5311ca8 100644 (file)
@@ -50,17 +50,19 @@ 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
 
     def send_cmd(self, endpoint='', postfields_dict=None,
                  formfile=None, filename=None,
-                 put_method=False):
+                 put_method=False, patch_method=False):
         data = BytesIO()
         curl_cmd = self._get_curl_cmd(endpoint)
         if put_method:
             curl_cmd.setopt(pycurl.PUT, 1)
+        elif patch_method:
+            curl_cmd.setopt(pycurl.CUSTOMREQUEST, "PATCH")
         else:
             curl_cmd.setopt(pycurl.POST, 1)
         curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
@@ -82,21 +84,10 @@ class Http(http.Http):
         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):
@@ -104,7 +95,7 @@ class Http(http.Http):
                              postfields_dict=postfields_dict,
                              formfile=formfile,
                              filename=filename,
-                             put_method=False)
+                             put_method=False, patch_method=False)
 
     def put_cmd(self, endpoint='', postfields_dict=None,
                 formfile=None, filename=None):
@@ -112,7 +103,15 @@ class Http(http.Http):
                              postfields_dict=postfields_dict,
                              formfile=formfile,
                              filename=filename,
-                             put_method=True)
+                             put_method=True, patch_method=False)
+
+    def patch_cmd(self, endpoint='', postfields_dict=None,
+                formfile=None, filename=None):
+        return self.send_cmd(endpoint=endpoint,
+                             postfields_dict=postfields_dict,
+                             formfile=formfile,
+                             filename=filename,
+                             put_method=False, patch_method=True)
 
     def get2_cmd(self, endpoint):
         data = BytesIO()
@@ -120,6 +119,9 @@ class Http(http.Http):
         curl_cmd.setopt(pycurl.HTTPGET, 1)
         curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
         curl_cmd.perform()
+        http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
         curl_cmd.close()
-        return data.getvalue()
+        if data.getvalue():
+            return http_code, data.getvalue().decode()
+        return http_code, None