fix client library & tests to work with changes made in
authorSofia Papagiannaki <papagian@gmail.com>
Tue, 29 Nov 2011 15:02:01 +0000 (17:02 +0200)
committerSofia Papagiannaki <papagian@gmail.com>
Tue, 29 Nov 2011 15:02:01 +0000 (17:02 +0200)
Revision 9fefc052 and Revision ce2f73d7

tools/lib/client.py
tools/test

index 1bf68f3..84457d2 100644 (file)
@@ -35,7 +35,7 @@ from httplib import HTTPConnection, HTTP
 from sys import stdin
 from xml.dom import minidom
 from StringIO import StringIO
-from urllib import quote
+from urllib import quote, unquote
 
 import json
 import types
@@ -82,7 +82,7 @@ class Client(object):
         
         for k,v in params.items():
             if v:
-                full_path = '%s&%s=%s' %(full_path, quote(k), quote(unicode(v)))
+                full_path = '%s&%s=%s' %(full_path, quote(k), quote(str(v)))
             else:
                 full_path = '%s&%s=' %(full_path, k)
         conn = HTTPConnection(self.host)
@@ -91,7 +91,7 @@ class Client(object):
         for k,v in headers.items():
             headers.pop(k)
             k = k.replace('_', '-')
-            headers[k] = v
+            headers[k] = quote(v, safe='/=,:@ *"') if type(v) == types.StringType else v
         
         kwargs['headers'] = headers
         kwargs['headers']['X-Auth-Token'] = self.token
@@ -107,7 +107,8 @@ class Client(object):
         resp = conn.getresponse()
         t2 = datetime.datetime.utcnow()
         #print 'response time:', str(t2-t1)
-        headers = dict(resp.getheaders())
+        headers = resp.getheaders()
+        headers = dict((unquote(h), unquote(v)) for h,v in headers)
         
         if self.verbose:
             print '%d %s' % (resp.status, resp.reason)
@@ -977,12 +978,3 @@ class Pithos_Client(OOS_Client):
         action = 'read' if read else 'write'
         sharing = '%s=%s' % (action, ','.join(l))
         self.update_object(container, object, f=None, x_object_sharing=sharing)
-
-def _encode_headers(headers):
-    h = {}
-    for k, v in headers.items():
-        k = urllib.quote(k)
-        if v and type(v) == types.StringType:
-            v = urllib.quote(v, '/=,-* :"')
-        h[k] = v
-    return h
index 0e522ac..eedc098 100755 (executable)
@@ -40,6 +40,7 @@ from xml.dom import minidom
 from StringIO import StringIO
 from hashlib import new as newhasher
 from binascii import hexlify
+
 import json
 import unittest
 import time as _time
@@ -1970,8 +1971,7 @@ class TestPublish(BaseTestCase):
         self.client.publish_object('c', 'o')
         meta = self.client.retrieve_object_metadata('c', 'o')
         self.assertTrue('x-object-public' in meta)
-        url = '/public/%s/c/o' % get_user()
-        self.assertEqual(meta['x-object-public'], url)
+        url = meta['x-object-public']
         public_client = Pithos_Client(get_server(), get_auth(), get_user(), api='')
         data = public_client.get(url)[2]
         self.assertEqual(o_data, data)