Skip to content

Commit

Permalink
Unicode command support under Py2
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Aug 25, 2017
1 parent 9892a38 commit 3dbd994
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 6 additions & 14 deletions plumbum/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def shquote(text):
"""Quotes the given text with shell escaping (assumes as syntax similar to ``sh``)"""
if not text:
return "''"
text = str(text)
text = six.str(text)
if not text:
return "''"
for c in text:
Expand All @@ -33,8 +33,8 @@ def shquote(text):
return text
if "'" not in text:
return "'" + text + "'"
res = "".join(('\\' + c if c in _funnychars else c) for c in text)
return '"' + res + '"'
res = six.str("").join((six.str('\\' + c) if c in _funnychars else c) for c in text)
return six.str('"') + res + six.str('"')

def shquote_list(seq):
return [shquote(item) for item in seq]
Expand Down Expand Up @@ -440,7 +440,7 @@ def _get_encoding(self):
return self.custom_encoding

def formulate(self, level = 0, args = ()):
argv = [str(self.executable)]
argv = [six.str(self.executable)]
for a in args:
if a is None:
continue
Expand All @@ -450,18 +450,10 @@ def formulate(self, level = 0, args = ()):
else:
argv.extend(a.formulate(level + 1))
elif isinstance(a, (list, tuple)):
argv.extend(shquote(b) if level >= self.QUOTE_LEVEL else str(b) for b in a)
argv.extend(shquote(b) if level >= self.QUOTE_LEVEL else six.str(b) for b in a)
else:
argv.append(shquote(a) if level >= self.QUOTE_LEVEL else str(a))
argv.append(shquote(a) if level >= self.QUOTE_LEVEL else six.str(a))
# if self.custom_encoding:
# argv = [a.encode(self.custom_encoding) for a in argv if isinstance(a, six.string_types)]
return argv









2 changes: 2 additions & 0 deletions plumbum/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def u(s):
def get_method_function(m):
return m.im_func

str = unicode_type

# Try/except fails because io has the wrong StringIO in Python2
# You'll get str/unicode errors
if six.PY3:
Expand Down

0 comments on commit 3dbd994

Please sign in to comment.