Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pkg.b2s: Pass through str as-is on Python 3
Things change, and we may start getting str where we previously got
bytes, such as what has apparently now happened with some versions of
the return value of magic.descriptor(fd) in Fedora Rawhide.

https://bugzilla.redhat.com/show_bug.cgi?id=1439941
  • Loading branch information
scop committed Apr 7, 2017
1 parent 047613f commit 4875475
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Pkg.py
Expand Up @@ -41,8 +41,8 @@
unicode = str

def b2s(b):
if b is None:
return None
if b is None or isinstance(b, str):
return b
if isinstance(b, (list, tuple)):
return [b2s(x) for x in b]
return b.decode(errors='replace')
Expand Down
4 changes: 4 additions & 0 deletions test/test.Pkg.py
Expand Up @@ -30,6 +30,10 @@ def test_rangeCompare(self):
):
self.assertFalse(Pkg.rangeCompare(req, prov))

def test_b2s(self):
for thing in ("foo", ["foo"]):
self.assertEqual(thing, Pkg.b2s(thing))


if __name__ == '__main__':
unittest.main()

0 comments on commit 4875475

Please sign in to comment.