diff options
| author | Adam Hupp <adam@hupp.org> | 2016-06-05 15:53:16 -0700 |
|---|---|---|
| committer | Adam Hupp <adam@hupp.org> | 2016-06-05 15:53:16 -0700 |
| commit | b1666986236eab820e9155a5943d6b94938b4c40 (patch) | |
| tree | 7d0be8a117e5d23f66fbbc78afed9995c99799a0 /magic.py | |
| parent | f82dc97ab906e2e83a26085834fa5fe7696972e8 (diff) | |
| download | python-magic-b1666986236eab820e9155a5943d6b94938b4c40.tar.gz | |
Return str rather than bytes for the description strings on python3.
Assumes utf-8 encoding from magic return values, which I hope is
always the case.
Diffstat (limited to 'magic.py')
| -rw-r--r-- | magic.py | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -72,7 +72,7 @@ class Magic: """ with self.lock: try: - return magic_buffer(self.cookie, buf) + return maybe_decode(magic_buffer(self.cookie, buf)) except MagicException as e: return self._handle509Bug(e) @@ -82,7 +82,7 @@ class Magic: pass with self.lock: try: - return magic_file(self.cookie, filename) + return maybe_decode(magic_file(self.cookie, filename)) except MagicException as e: return self._handle509Bug(e) @@ -189,6 +189,14 @@ def errorcheck_negative_one(result, func, args): return result +# return str on python3. Don't want to unconditionally +# decode because that results in unicode on python2 +def maybe_decode(s): + if str == bytes: + return s + else: + return s.decode('utf-8') + def coerce_filename(filename): if filename is None: return None |
