summaryrefslogtreecommitdiff
path: root/swiftclient/shell.py
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2015-05-18 10:14:09 -0700
committerTim Burke <tim.burke@gmail.com>2015-07-07 15:39:55 -0700
commitbb252130ac2f332110172b8e2094dc629c8a896b (patch)
tree288b6f666fac6e7dac981fc0f568042302876440 /swiftclient/shell.py
parentcf0b6c03df5b014e8c21ffcb0fe92f58e11c7ae3 (diff)
downloadpython-swiftclient-bb252130ac2f332110172b8e2094dc629c8a896b.tar.gz
Always decode command-line arguments as UTF-8
There was always an implicit assumption that they were UTF-8 before, and by converting them to unicode we close another hole allowing raw bytes to appear in user-facing messages. Closes-Bug: #1431866 Change-Id: If2e41d9a592c3ad02818e9c6f0959fd4b73cd0e0
Diffstat (limited to 'swiftclient/shell.py')
-rwxr-xr-xswiftclient/shell.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index 4438e9d..0663e4f 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
import logging
import signal
@@ -23,6 +23,7 @@ import socket
from optparse import OptionParser, OptionGroup, SUPPRESS_HELP
from os import environ, walk, _exit as os_exit
from os.path import isfile, isdir, join
+from six import text_type
from sys import argv as sys_argv, exit, stderr
from time import gmtime, strftime
@@ -106,7 +107,7 @@ def st_delete(parser, args, output_manager):
if '/' in container:
output_manager.error(
'WARNING: / in container name; you '
- 'might have meant %r instead of %r.' % (
+ "might have meant '%s' instead of '%s'." % (
container.replace('/', ' ', 1), container)
)
return
@@ -249,7 +250,7 @@ def st_download(parser, args, output_manager):
if '/' in container:
output_manager.error(
'WARNING: / in container name; you '
- 'might have meant %r instead of %r.' % (
+ "might have meant '%s' instead of '%s'." % (
container.replace('/', ' ', 1), container)
)
return
@@ -500,7 +501,7 @@ def st_stat(parser, args, output_manager):
if '/' in container:
output_manager.error(
'WARNING: / in container name; you might have '
- 'meant %r instead of %r.' %
+ "meant '%s' instead of '%s'." %
(container.replace('/', ' ', 1), container))
return
args = args[1:]
@@ -604,7 +605,7 @@ def st_post(parser, args, output_manager):
if '/' in container:
output_manager.error(
'WARNING: / in container name; you might have '
- 'meant %r instead of %r.' %
+ "meant '%s' instead of '%s'." %
(args[0].replace('/', ' ', 1), args[0]))
return
args = args[1:]
@@ -844,7 +845,7 @@ def st_upload(parser, args, output_manager):
msg = ': %s' % error
output_manager.warning(
'Warning: failed to create container '
- '%r%s', container, msg
+ "'%s'%s", container, msg
)
else:
output_manager.error("%s" % error)
@@ -1037,6 +1038,8 @@ def main(arguments=None):
else:
argv = sys_argv
+ argv = [a if isinstance(a, text_type) else a.decode('utf-8') for a in argv]
+
version = client_version
parser = OptionParser(version='python-swiftclient %s' % version,
usage='''