Fix details that ruin internal unicode objects
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 5 Mar 2014 14:39:37 +0000 (16:39 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 5 Mar 2014 14:39:37 +0000 (16:39 +0200)
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
kamaki/clients/image/__init__.py
kamaki/clients/pithos/__init__.py

index 3c6628d..7f95f87 100644 (file)
@@ -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(
index f1a6b3b..43bcbf1 100644 (file)
@@ -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 (
index 44ad020..fdffefe 100644 (file)
@@ -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