summaryrefslogtreecommitdiff
path: root/magic.py
diff options
context:
space:
mode:
Diffstat (limited to 'magic.py')
-rw-r--r--magic.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/magic.py b/magic.py
index a97e929..8637c95 100644
--- a/magic.py
+++ b/magic.py
@@ -72,6 +72,11 @@ class Magic:
"""
with self.lock:
try:
+ # if we're on python3, convert buf to bytes
+ # otherwise this string is passed as wchar*
+ # which is not what libmagic expects
+ if type(buf) == str and str != bytes:
+ buf = buf.encode('utf-8', errors='replace')
return maybe_decode(magic_buffer(self.cookie, buf))
except MagicException as e:
return self._handle509Bug(e)