]> granicus.if.org Git - file/commitdiff
add python3 changes.
authorChristos Zoulas <christos@zoulas.com>
Thu, 22 Sep 2011 16:58:37 +0000 (16:58 +0000)
committerChristos Zoulas <christos@zoulas.com>
Thu, 22 Sep 2011 16:58:37 +0000 (16:58 +0000)
ChangeLog
python/magic.py

index a87d70c0f1c8cdff4051fa3ad56fba9e362e5a20..28f87aabc9fb26b869a063289a5eb876eab954b3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-09-22  12:57  Christos Zoulas <christos@zoulas.com>
+
+       * Python3 binding fixes from Kelly Anderson
+
 2011-09-20  11:32  Christos Zoulas <christos@zoulas.com>
 
        * If a string type magic entry is marked as text or binary
index 41a42ee553f709353e1e404aa882974729477ce7..bd42f565ea9c103a29572ab0856c4ee02212cf0e 100644 (file)
@@ -109,13 +109,17 @@ class Magic(object):
         """
         _close(self._magic_t)
 
-    def file(self, file):
+    def file(self, filename):
         """
         Returns a textual description of the contents of the argument passed
         as a filename or None if an error occurred and the MAGIC_ERROR flag
         is set.  A call to errno() will return the numeric error code.
         """
-        return _file(self._magic_t, file)
+        try: # attempt python3 approach first
+            bi = bytes(filename, 'utf-8')
+            return str(_file(self._magic_t, bi), 'utf-8')
+        except:
+            return _file(self._magic_t, filename)
 
     def descriptor(self, fd):
         """
@@ -129,14 +133,20 @@ class Magic(object):
         as a buffer or None if an error occurred and the MAGIC_ERROR flag
         is set. A call to errno() will return the numeric error code.
         """
-        return _buffer(self._magic_t, buf, len(buf))
+        try: # attempt python3 approach first
+            return str(_buffer(self._magic_t, buf, len(buf)), 'utf-8')
+        except:
+            return _buffer(self._magic_t, buf, len(buf))
 
     def error(self):
         """
         Returns a textual explanation of the last error or None
         if there was no error.
         """
-        return _error(self._magic_t)
+        try: # attempt python3 approach first
+            return str(_error(self._magic_t), 'utf-8')
+        except:
+            return _error(self._magic_t)
   
     def setflags(self, flags):
         """
@@ -149,7 +159,7 @@ class Magic(object):
         """
         return _setflags(self._magic_t, flags)
 
-    def load(self, file=None):
+    def load(self, filename=None):
         """
         Must be called to load entries in the colon separated list of database files
         passed as argument or the default database file if no argument before
@@ -157,7 +167,7 @@ class Magic(object):
         
         Returns 0 on success and -1 on failure.
         """
-        return _load(self._magic_t, file)
+        return _load(self._magic_t, filename)
 
     def compile(self, dbs):
         """