Skip to content

Commit

Permalink
Merge pull request #2678 from rodrigc/asciifix
Browse files Browse the repository at this point in the history
Fix buildbot.test.unit.test_util.CommandToString.test_invalid_ascii on Python 3
  • Loading branch information
tardyp committed Jan 26, 2017
2 parents 16c6a4c + 5853b48 commit c169d99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion master/buildbot/test/unit/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def test_list_with_objects(self):
u"'ab cd'")

def test_invalid_ascii(self):
self.assertEqual(util.command_to_string('a\xffc'), u"'a\ufffdc'")
self.assertEqual(util.command_to_string(b'a\xffc'), u"'a\ufffdc'")


class TestRewrap(unittest.TestCase):
Expand Down
16 changes: 9 additions & 7 deletions master/buildbot/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def join_list(maybeList):

def command_to_string(command):
words = command
if isinstance(words, string_types):
if isinstance(words, (bytes, string_types)):
words = words.split()

try:
Expand All @@ -435,7 +435,14 @@ def command_to_string(command):

# strip instances and other detritus (which can happen if a
# description is requested before rendering)
words = [w for w in words if isinstance(w, (string_types))]
stringWords = []
for w in words:
if isinstance(w, (bytes, string_types)):
# If command was bytes, be gentle in
# trying to covert it.
w = ascii2unicode(w, "replace")
stringWords.append(w)
words = stringWords

if len(words) < 1:
return None
Expand All @@ -444,11 +451,6 @@ def command_to_string(command):
else:
rv = "'%s ...'" % (' '.join(words[:2]))

# cmd was a command and thus probably a bytestring. Be gentle in
# trying to covert it.
if isinstance(rv, bytes):
rv = rv.decode('ascii', 'replace')

return rv


Expand Down

0 comments on commit c169d99

Please sign in to comment.