Allow non-ascii paramters on path2url
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 26 Feb 2013 10:19:12 +0000 (12:19 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 26 Feb 2013 10:19:12 +0000 (12:19 +0200)
Replace calls of the form unicode(v) to the equivalent" '%s' % v

kamaki/cli/argument.py
kamaki/cli/commands/cyclades_cli.py
kamaki/cli/errors.py
kamaki/cli/utils.py
kamaki/clients/__init__.py
kamaki/clients/compute.py
kamaki/clients/connection/__init__.py
kamaki/clients/connection/kamakicon.py
kamaki/clients/cyclades.py
kamaki/clients/utils.py

index d121739..075f013 100644 (file)
@@ -83,7 +83,7 @@ class Argument(object):
         if isinstance(newname, list) or isinstance(newname, tuple):
             self._parsed_name += list(newname)
         else:
-            self._parsed_name.append(unicode(newname))
+            self._parsed_name.append('%s' % newname)
 
     @property
     def help(self):
@@ -92,7 +92,7 @@ class Argument(object):
 
     @help.setter
     def help(self, newhelp):
-        self._help = unicode(newhelp)
+        self._help = '%s' % newhelp
 
     @property
     def arity(self):
@@ -189,7 +189,7 @@ class CmdLineConfigArgument(Argument):
         if options == self.default:
             return
         if not isinstance(options, list):
-            options = [unicode(options)]
+            options = ['%s' % options]
         for option in options:
             keypath, sep, val = option.partition('=')
             if not sep:
index 692132d..72b2c89 100644 (file)
@@ -353,7 +353,7 @@ class server_firewall(_init_cyclades):
     def _run(self, server_id, profile):
         self.client.set_firewall_profile(
             server_id=int(server_id),
-            profile=unicode(profile).upper())
+            profile=('%s' % profile).upper())
 
     def main(self, server_id, profile):
         super(self.__class__, self)._run()
index 710fef7..4d6b1a8 100644 (file)
@@ -113,7 +113,7 @@ def raiseCLIError(err, message='', importance=0, details=[]):
     else:
         origerr = stack[0]
 
-    message = unicode(message) if message else unicode(origerr)
+    message = '%s' % (message if message else origerr)
 
     try:
         status = err.status or err.errno
index 4ee07b0..f6e2b10 100644 (file)
@@ -99,6 +99,7 @@ def print_dict(
 
     counter = 1
     for key, val in sorted(d.items()):
+        key = '%s' % key
         if key in exclude:
             continue
         print_str = ''
@@ -106,8 +107,8 @@ def print_dict(
             print_str = '%s. ' % counter
             counter += 1
         print_str = '%s%s' % (' ' * (ident - len(print_str)), print_str)
-        print_str += ('%s' % key).strip()
-        print_str += ' ' * (margin - len(unicode(key).strip()))
+        print_str += key.strip()
+        print_str += ' ' * (margin - len(key.strip()))
         print_str += ': '
         if isinstance(val, dict):
             print(print_str)
@@ -126,7 +127,7 @@ def print_dict(
                 with_enumeration=recursive_enumeration,
                 recursive_enumeration=recursive_enumeration)
         else:
-            print print_str + ' ' + unicode(val).strip()
+            print print_str + ' ' + ('%s' % val).strip()
 
 
 def print_list(
@@ -158,7 +159,7 @@ def print_list(
                 isinstance(item, list) or
                 item in exclude))
         except ValueError:
-            margin = (2 + len(unicode(len(l)))) if enumerate else 1
+            margin = (2 + len(('%s' % len(l)))) if enumerate else 1
 
     counter = 1
     prefix = ''
@@ -242,9 +243,9 @@ def print_items(
         if isinstance(item, dict):
             title = sorted(set(title).intersection(item.keys()))
             if with_redundancy:
-                header = ' '.join(unicode(item[key]) for key in title)
+                header = ' '.join('%s' % item[key] for key in title)
             else:
-                header = ' '.join(unicode(item.pop(key)) for key in title)
+                header = ' '.join('%s' % item.pop(key) for key in title)
             print(bold(header))
         if isinstance(item, dict):
             print_dict(item, ident=1)
@@ -305,7 +306,7 @@ def dict2file(d, f, depth=0):
             f.write('\n')
             list2file(v, f, depth + 1)
         else:
-            f.write(' %s\n' % unicode(v))
+            f.write(' %s\n' % v)
 
 
 def list2file(l, f, depth=1):
@@ -315,7 +316,7 @@ def list2file(l, f, depth=1):
         elif isinstance(item, list):
             list2file(item, f, depth + 1)
         else:
-            f.write('%s%s\n' % ('\t' * depth, unicode(item)))
+            f.write('%s%s\n' % ('\t' * depth, item))
 
 # Split input auxiliary
 
index db55d81..433b023 100644 (file)
@@ -189,7 +189,7 @@ class Client(object):
                 data = dumps(kwargs.pop('json'))
                 self.set_default_header('Content-Type', 'application/json')
             if data:
-                self.set_default_header('Content-Length', unicode(len(data)))
+                self.set_default_header('Content-Length', '%s' % len(data))
 
             sendlog.info('perform a %s @ %s', method, self.base_url)
 
index ef7a2c3..1fa3893 100644 (file)
@@ -101,7 +101,8 @@ class ComputeClient(ComputeClientApi):
                 if isinstance(err.details, list):
                     tmp_err = err.details
                 else:
-                    tmp_err = unicode(err.details).split(',')
+                    errd = '%s' % err.details
+                    tmp_err = errd.split(',')
                 tmp_err = tmp_err[0].split(':')
                 tmp_err = tmp_err[2].split('"')
                 err.message = tmp_err[1]
index 7c8cf69..b1935e5 100644 (file)
@@ -144,7 +144,7 @@ class HTTPConnection(object):
         self.method = method
 
     def set_header(self, name, value):
-        self.headers[unicode(name)] = unicode(value)
+        self.headers['%s' % name] = '%s' % value
 
     def remove_header(self, name):
         try:
index 0285b42..68db220 100644 (file)
@@ -74,7 +74,7 @@ class KamakiHTTPResponse(HTTPResponse):
         :returns: (str) content
         """
         self._get_response()
-        return unicode(self._content)
+        return '%s' % self._content
 
     @text.setter
     def test(self, v):
@@ -123,9 +123,9 @@ class KamakiHTTPConnection(HTTPConnection):
         for k, v in extra_params.items():
             params[k] = v
         for i, (key, val) in enumerate(params.items()):
-            param_str = ('?' if i == 0 else '&') + unicode(key)
+            param_str = '%s%s' % ('?' if i == 0 else '&', key)
             if val is not None:
-                param_str += '=' + unicode(val)
+                param_str += '=%s' % val
             url += param_str
 
         parsed = urlparse(url)
index 7cfe681..066ca4a 100644 (file)
@@ -229,7 +229,7 @@ class CycladesClient(CycladesClientApi):
         for (nic_id, network_id) in [(
                 net['id'],
                 net['network_id']) for net in vm_nets if nic_id == net['id']]:
-            req = {'remove': {'attachment': unicode(nic_id)}}
+            req = {'remove': {'attachment': '%s' % nic_id}}
             r = self.networks_post(network_id, 'action', json_data=req)
             r.release()
             num_of_disconnections += 1
index 56641e7..0060e95 100644 (file)
@@ -89,7 +89,7 @@ def path4url(*args):
 
     path = ''
     for arg in args:
-        suffix = unicode(arg)
+        suffix = '%s' % arg
         try:
             while suffix[0] == '/':
                 suffix = suffix[1:]