From 75e73aaba82595450f8bb732bb7dd46ac468972a Mon Sep 17 00:00:00 2001 From: Stavros Sachtouris Date: Wed, 5 Mar 2014 16:39:37 +0200 Subject: [PATCH] Fix details that ruin internal unicode objects Refs: #5150, #5180 Specifics: - the image path is conctructed with a + operator, use the '%s' notation instead - Do not quote everything on the URL, because it destroyes ? and & characters. Encode and quote only what needs to be --- kamaki/clients/__init__.py | 12 +++++------- kamaki/clients/image/__init__.py | 4 ++-- kamaki/clients/pithos/__init__.py | 5 +---- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/kamaki/clients/__init__.py b/kamaki/clients/__init__.py index 3c6628d..7f95f87 100644 --- a/kamaki/clients/__init__.py +++ b/kamaki/clients/__init__.py @@ -127,11 +127,10 @@ class RequestManager(Logged): url += '%s%s%s' % (delim, key, ('=%s' % val) if val else '') delim = '&' parsed = urlparse(url) - self.url = _encode(u'%s' % url) - self.path = _encode((u'%s' % parsed.path) if parsed.path else '/') - if parsed.query: - self.path += '?%s' % parsed.query - return (_encode(parsed.scheme), _encode(parsed.netloc)) + self.url = '%s' % url + self.path = (('%s' % parsed.path) if parsed.path else '/') + ( + '?%s' % parsed.query if parsed.query else '') + return (parsed.scheme, parsed.netloc) def __init__( self, method, url, path, @@ -178,7 +177,7 @@ class RequestManager(Logged): self.dump_log() conn.request( method=self.method.upper(), - url=('%s' % self.path) or '', + url=self.path.encode('utf-8'), headers=self.headers, body=self.data) sendlog.info('') @@ -486,7 +485,6 @@ class Client(Logged): headers.setdefault('Content-Type', 'application/json') if data: headers.setdefault('Content-Length', '%s' % len(data)) - plog = ('\t[%s]' % self) if self.LOG_PID else '' sendlog.debug('\n\nCMT %s@%s%s', method, self.base_url, plog) req = RequestManager( diff --git a/kamaki/clients/image/__init__.py b/kamaki/clients/image/__init__.py index f1a6b3b..43bcbf1 100644 --- a/kamaki/clients/image/__init__.py +++ b/kamaki/clients/image/__init__.py @@ -70,7 +70,7 @@ class ImageClient(Client): :returns: (list) id,name + full image info if detail """ path = path4url('images', 'detail') if detail else ( - path4url('images') + '/') + '%s/' % path4url('images')) async_params = {} if isinstance(filters, dict): @@ -115,7 +115,7 @@ class ImageClient(Client): :returns: (dict) metadata of the created image """ - path = path4url('images') + '/' + path = '%s/' % path4url('images') self.set_header('X-Image-Meta-Name', name) location = location if ( isinstance(location, str) or isinstance(location, unicode)) else ( diff --git a/kamaki/clients/pithos/__init__.py b/kamaki/clients/pithos/__init__.py index 44ad020..fdffefe 100644 --- a/kamaki/clients/pithos/__init__.py +++ b/kamaki/clients/pithos/__init__.py @@ -466,10 +466,7 @@ class PithosClient(PithosRestClient): sendlog.info('%s blocks missing' % len(missing)) num_of_blocks = len(missing) missing = self._upload_missing_blocks( - missing, - hmap, - f, - upload_gen) + missing, hmap, f, upload_gen) if missing: if num_of_blocks == len(missing): retries -= 1 -- 1.7.10.4