|
@@ -1,7 +1,8 @@
|
|
Subject: libmagic compability
|
|
Subject: libmagic compability
|
|
-Origin: libmagic-compat branch, commit 9aba180
|
|
|
|
|
|
+Origin: libmagic-compat branch, commit 315cb4c
|
|
Upstream-Author: Adam Hupp <adam@hupp.org>
|
|
Upstream-Author: Adam Hupp <adam@hupp.org>
|
|
Date: Mon Dec 4 11:55:27 2017 -0800
|
|
Date: Mon Dec 4 11:55:27 2017 -0800
|
|
|
|
+Last-Updated: 2018-01-15
|
|
|
|
|
|
--- a/LICENSE
|
|
--- a/LICENSE
|
|
+++ b/LICENSE
|
|
+++ b/LICENSE
|
|
@@ -53,7 +54,7 @@ Date: Mon Dec 4 11:55:27 2017 -0800
|
|
Minor version bumps should be backwards compatible. Major bumps are not.
|
|
Minor version bumps should be backwards compatible. Major bumps are not.
|
|
|
|
|
|
-## Name Conflict
|
|
-## Name Conflict
|
|
-+## Compatability
|
|
|
|
|
|
++## Compatibility
|
|
|
|
|
|
-There are, sadly, two libraries which use the module name `magic`. Both have been around for quite a while.If you are using this module and get an error using a method like `open`, your code is expecting the other one. Hopefully one day these will be reconciled.
|
|
-There are, sadly, two libraries which use the module name `magic`. Both have been around for quite a while.If you are using this module and get an error using a method like `open`, your code is expecting the other one. Hopefully one day these will be reconciled.
|
|
+There are, sadly, 3 libraries using the package name `magic`. The others are:
|
|
+There are, sadly, 3 libraries using the package name `magic`. The others are:
|
|
@@ -69,6 +70,24 @@ Date: Mon Dec 4 11:55:27 2017 -0800
|
|
|
|
|
|
## Installation
|
|
## Installation
|
|
|
|
|
|
|
|
+@@ -64,7 +73,7 @@
|
|
|
|
+ You'll need DLLs for libmagic. @julian-r has uploaded a versoin of this project that includes binaries to pypi:
|
|
|
|
+ https://pypi.python.org/pypi/python-magic-bin/0.4.14
|
|
|
|
+
|
|
|
|
+-Other sources of the libraries in the past have been [File for Windows](http://gnuwin32.sourceforge.net/packages/file.htm) . You will need to copy the file `magic` out of `[binary-zip]\share\misc`, and pass it's location to `Magic(magic_file=...)`.
|
|
|
|
++Other sources of the libraries in the past have been [File for Windows](http://gnuwin32.sourceforge.net/packages/file.htm) . You will need to copy the file `magic` out of `[binary-zip]\share\misc`, and pass its location to `Magic(magic_file=...)`.
|
|
|
|
+
|
|
|
|
+ If you are using a 64-bit build of python, you'll need 64-bit libmagic binaries which can be found here: https://github.com/pidydx/libmagicwin64. Newer version can be found here: https://github.com/nscaife/file-windows.
|
|
|
|
+
|
|
|
|
+@@ -86,7 +95,7 @@
|
|
|
|
+ Attempting to run the 32-bit libmagic DLL in a 64-bit build of
|
|
|
|
+ python will fail with this error. Here are 64-bit builds of libmagic for windows: https://github.com/pidydx/libmagicwin64
|
|
|
|
+
|
|
|
|
+-- 'WindowsError: exception: access violation writing 0x00000000 ' This may indicate you are mixing
|
|
|
|
++- 'WindowsError: exception: access violation writing 0x00000000 ' This may indicate you are mixing
|
|
|
|
+ Windows Python and Cygwin Python. Make sure your libmagic and python builds are consistent.
|
|
|
|
+
|
|
|
|
+ ## Author
|
|
@@ -116,5 +125,3 @@
|
|
@@ -116,5 +125,3 @@
|
|
|
|
|
|
python-magic is distributed under the MIT license. See the included
|
|
python-magic is distributed under the MIT license. See the included
|
|
@@ -381,7 +400,7 @@ Date: Mon Dec 4 11:55:27 2017 -0800
|
|
-MAGIC_NO_CHECK_TOKENS = 0x100000 # Don't check ascii/tokens
|
|
-MAGIC_NO_CHECK_TOKENS = 0x100000 # Don't check ascii/tokens
|
|
--- /dev/null
|
|
--- /dev/null
|
|
+++ b/magic/__init__.py
|
|
+++ b/magic/__init__.py
|
|
-@@ -0,0 +1,357 @@
|
|
|
|
|
|
+@@ -0,0 +1,361 @@
|
|
+"""
|
|
+"""
|
|
+magic is a wrapper around the libmagic file identification library.
|
|
+magic is a wrapper around the libmagic file identification library.
|
|
+
|
|
+
|
|
@@ -411,6 +430,8 @@ Date: Mon Dec 4 11:55:27 2017 -0800
|
|
+
|
|
+
|
|
+from ctypes import c_char_p, c_int, c_size_t, c_void_p
|
|
+from ctypes import c_char_p, c_int, c_size_t, c_void_p
|
|
+
|
|
+
|
|
|
|
++# avoid shadowing the real open with the version from compat.py
|
|
|
|
++_real_open = open
|
|
+
|
|
+
|
|
+class MagicException(Exception):
|
|
+class MagicException(Exception):
|
|
+ def __init__(self, message):
|
|
+ def __init__(self, message):
|
|
@@ -475,8 +496,7 @@ Date: Mon Dec 4 11:55:27 2017 -0800
|
|
+
|
|
+
|
|
+ def from_file(self, filename):
|
|
+ def from_file(self, filename):
|
|
+ # raise FileNotFoundException or IOError if the file does not exist
|
|
+ # raise FileNotFoundException or IOError if the file does not exist
|
|
-+ # use __builtins__ because the compat stuff at the bottom shadows the builtin open
|
|
|
|
-+ with __builtins__['open'](filename):
|
|
|
|
|
|
++ with _real_open(filename):
|
|
+ pass
|
|
+ pass
|
|
+
|
|
+
|
|
+ with self.lock:
|
|
+ with self.lock:
|
|
@@ -721,7 +741,10 @@ Date: Mon Dec 4 11:55:27 2017 -0800
|
|
+ ('detect_from_fobj', 'magic.Magic.from_open_file'),
|
|
+ ('detect_from_fobj', 'magic.Magic.from_open_file'),
|
|
+ ('open', 'magic.Magic')]
|
|
+ ('open', 'magic.Magic')]
|
|
+ for (fname, alternate) in fn:
|
|
+ for (fname, alternate) in fn:
|
|
-+ to_module[fname] = deprecation_wrapper(compat.__dict__, fname, alternate)
|
|
|
|
|
|
++ # for now, disable the deprecation warning until theres clarity on
|
|
|
|
++ # what the merged module should look like
|
|
|
|
++ to_module[fname] = compat.__dict__.get(fname)
|
|
|
|
++ #to_module[fname] = deprecation_wrapper(compat.__dict__, fname, alternate)
|
|
+
|
|
+
|
|
+ # copy constants over, ensuring there's no conflicts
|
|
+ # copy constants over, ensuring there's no conflicts
|
|
+ is_const_re = re.compile("^[A-Z_]+$")
|
|
+ is_const_re = re.compile("^[A-Z_]+$")
|
|
@@ -1027,9 +1050,22 @@ Date: Mon Dec 4 11:55:27 2017 -0800
|
|
+
|
|
+
|
|
+ return _create_filemagic(mime_magic.buffer(byte_content),
|
|
+ return _create_filemagic(mime_magic.buffer(byte_content),
|
|
+ none_magic.buffer(byte_content))
|
|
+ none_magic.buffer(byte_content))
|
|
|
|
+--- a/setup.py
|
|
|
|
++++ b/setup.py
|
|
|
|
+@@ -8,8 +8,8 @@
|
|
|
|
+ author='Adam Hupp',
|
|
|
|
+ author_email='adam@hupp.org',
|
|
|
|
+ url="http://github.com/ahupp/python-magic",
|
|
|
|
+- version='0.4.15',
|
|
|
|
+- py_modules=['magic'],
|
|
|
|
++ version='0.4.16',
|
|
|
|
++ packages=['magic'],
|
|
|
|
+ long_description="""This module uses ctypes to access the libmagic file type
|
|
|
|
+ identification library. It makes use of the local magic database and
|
|
|
|
+ supports both textual and MIME-type output.
|
|
--- /dev/null
|
|
--- /dev/null
|
|
+++ b/test/libmagic_test.py
|
|
+++ b/test/libmagic_test.py
|
|
-@@ -0,0 +1,35 @@
|
|
|
|
|
|
+@@ -0,0 +1,39 @@
|
|
+# coding: utf-8
|
|
+# coding: utf-8
|
|
+
|
|
+
|
|
+import unittest
|
|
+import unittest
|
|
@@ -1059,7 +1095,11 @@ Date: Mon Dec 4 11:55:27 2017 -0800
|
|
+ self.assert_result(result)
|
|
+ self.assert_result(result)
|
|
+
|
|
+
|
|
+ def test_detect_from_content(self):
|
|
+ def test_detect_from_content(self):
|
|
-+ with open(self.filename) as fobj:
|
|
|
|
|
|
++ # differ from upstream by opening file in binary mode,
|
|
|
|
++ # this avoids hitting a bug in python3+libfile bindings
|
|
|
|
++ # see https://github.com/ahupp/python-magic/issues/152
|
|
|
|
++ # for a similar issue
|
|
|
|
++ with open(self.filename, 'rb') as fobj:
|
|
+ result = magic.detect_from_content(fobj.read(4096))
|
|
+ result = magic.detect_from_content(fobj.read(4096))
|
|
+ self.assert_result(result)
|
|
+ self.assert_result(result)
|
|
+
|
|
+
|
|
@@ -1081,10 +1121,12 @@ Date: Mon Dec 4 11:55:27 2017 -0800
|
|
+python3 ${THISDIR}/libmagic_test.py
|
|
+python3 ${THISDIR}/libmagic_test.py
|
|
--- a/test/test.py
|
|
--- a/test/test.py
|
|
+++ b/test/test.py
|
|
+++ b/test/test.py
|
|
-@@ -38,6 +38,12 @@
|
|
|
|
|
|
+@@ -37,7 +37,13 @@
|
|
|
|
+ self.assertEqual("text/x-python", m.from_buffer(s))
|
|
b = b'#!/usr/bin/env python\nprint("foo")'
|
|
b = b'#!/usr/bin/env python\nprint("foo")'
|
|
self.assertEqual("text/x-python", m.from_buffer(b))
|
|
self.assertEqual("text/x-python", m.from_buffer(b))
|
|
-
|
|
|
|
|
|
+-
|
|
|
|
++
|
|
+
|
|
+
|
|
+ def test_open_file(self):
|
|
+ def test_open_file(self):
|
|
+ m = magic.Magic(mime=True)
|
|
+ m = magic.Magic(mime=True)
|