Fix one-command/shell differences in http encoding
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 4 Mar 2014 17:31:51 +0000 (19:31 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 4 Mar 2014 17:31:51 +0000 (19:31 +0200)
Refs: #5150

kamaki/cli/__init__.py
kamaki/cli/argument/__init__.py
kamaki/cli/command_shell.py
kamaki/clients/__init__.py

index 1f77521..a30cb43 100644 (file)
@@ -500,9 +500,8 @@ def main(func):
     def wrap():
         try:
             exe = basename(argv[0])
-            if argv[1:]:
-                from utils import pref_enc
-                internal_argv = [arg.decode(pref_enc) for arg in argv]
+            from utils import pref_enc
+            internal_argv = [arg.decode(pref_enc) for arg in argv]
             parser = ArgumentParseManager(exe)
 
             if parser.arguments['version'].value:
index 471a392..b2326ba 100644 (file)
@@ -290,7 +290,7 @@ class DataSizeArgument(ValueArgument):
             limit = int(user_input)
         except ValueError:
             index = 0
-            digits = [str(num) for num in range(0, 10)] + ['.']
+            digits = ['%s' % num for num in range(0, 10)] + ['.']
             while user_input[index] in digits:
                 index += 1
             limit = user_input[:index]
index 866c8ac..93c3272 100644 (file)
 
 from cmd import Cmd
 from os import popen
-from sys import stdout, stderr
+from sys import stdout
 
 from kamaki.cli import exec_cmd, print_error_message, print_subcommands_help
 from kamaki.cli.argument import ArgumentParseManager
-from kamaki.cli.utils import print_dict, split_input
+from kamaki.cli.utils import print_dict, split_input, pref_enc
 from kamaki.cli.history import History
 from kamaki.cli.errors import CLIError
 from kamaki.clients import ClientError
@@ -190,6 +190,7 @@ class Shell(Cmd):
                 <cmd> <term> <term> <args> is always parsed to most specific
                 even if cmd_term_term is not a terminal path
             """
+            line = line.decode(pref_enc)
             subcmd, cmd_args = cmd.parse_out(split_input(line))
             self._history.add(' '.join([cmd.path.replace('_', ' '), line]))
             cmd_parser = ArgumentParseManager(
index f79720d..3c6628d 100644 (file)
@@ -123,14 +123,14 @@ class RequestManager(Logged):
             url += _encode(path[1:] if path.startswith('/') else path)
         delim = '?'
         for key, val in params.items():
-            val = quote('' if val in (None, False) else '%s' % val)
+            val = quote('' if val in (None, False) else '%s' % _encode(val))
             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 += _encode(u'?%s' % parsed.query)
+            self.path += '?%s' % parsed.query
         return (_encode(parsed.scheme), _encode(parsed.netloc))
 
     def __init__(
@@ -162,9 +162,10 @@ class RequestManager(Logged):
             sendlog.info('data size: 0%s' % plog)
 
     def _encode_headers(self):
-        headers = self.headers
+        headers = dict(self.headers)
         for k, v in self.headers.items():
-            headers[k] = quote(v)
+            headers[k] = quote(
+                v.encode('utf-8') if isinstance(v, unicode) else v)
         self.headers = headers
 
     def perform(self, conn):