cherry-pick.FILE5_18-11-ge14d88d.fix-python-regression.patch 808 B

123456789101112131415161718192021
  1. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  2. Date: Thu Apr 3 20:47:24 2014 +0000
  3. Upstream-Commit: e14d88d8df2aafb74ba0c0b3d0116fc84b68cbd8
  4. Description:
  5. Fix regression: If a file was already bytes, don't try to convert it.
  6. From: Arfrever Frehtes Taifersar Arahesis
  7. --- a/python/magic.py
  8. +++ b/python/magic.py
  9. @@ -116,7 +116,10 @@
  10. is set. A call to errno() will return the numeric error code.
  11. """
  12. try: # attempt python3 approach first
  13. - bi = bytes(filename, 'utf-8')
  14. + if isinstance(filename, bytes):
  15. + bi = filename
  16. + else:
  17. + bi = bytes(filename, 'utf-8')
  18. return str(_file(self._magic_t, bi), 'utf-8')
  19. except:
  20. return _file(self._magic_t, filename.encode('utf-8'))