From: Sofia Papagiannaki Date: Tue, 29 Nov 2011 15:02:01 +0000 (+0200) Subject: fix client library & tests to work with changes made in X-Git-Tag: pithos/v0.8.1~9 X-Git-Url: https://code.grnet.gr/git/pithos/commitdiff_plain/b5dc1bda79da09c58fc170943527eedb30bc9676?hp=a46f71751a39fd97f9f4ee8c035e3c0514623bf8 fix client library & tests to work with changes made in Revision 9fefc052 and Revision ce2f73d7 --- diff --git a/tools/lib/client.py b/tools/lib/client.py index 1bf68f3..84457d2 100644 --- a/tools/lib/client.py +++ b/tools/lib/client.py @@ -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 diff --git a/tools/test b/tools/test index 0e522ac..eedc098 100755 --- a/tools/test +++ b/tools/test @@ -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)