Browse Source

Update libmagic compability to the latest upstream commit

Christoph Biedl 6 years ago
parent
commit
c494591902

+ 0 - 16
debian/patches/fix-buffer-test.patch

@@ -1,16 +0,0 @@
-Subject: Fix test failing in python3
-Author: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
-Date: 2018-01-08
-Forwarded: yes
-
---- a/test/libmagic_test.py
-+++ b/test/libmagic_test.py
-@@ -28,7 +28,7 @@
- 
-     def test_detect_from_content(self):
-         with open(self.filename) as fobj:
--            result = magic.detect_from_content(fobj.read(4096))
-+            result = magic.detect_from_content(fobj.read(4096).encode())
-         self.assert_result(result)
- 
- if __name__ == '__main__':

+ 0 - 15
debian/patches/fix-installation.patch

@@ -1,15 +0,0 @@
-Subject: Fix installation path
-Author: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
-Date: 2018-01-08
-Forwarded: yes
-
---- a/setup.py
-+++ b/setup.py
-@@ -14,6 +14,7 @@
- identification library.  It makes use of the local magic database and
- supports both textual and MIME-type output.
- """,
-+      packages=["magic"],
-       keywords="mime magic file",
-       license="MIT",
-       test_suite='test',

+ 52 - 10
debian/patches/libmagic-compat.patch

@@ -1,7 +1,8 @@
 Subject: libmagic compability
-Origin: libmagic-compat branch, commit 9aba180
+Origin: libmagic-compat branch, commit 315cb4c
 Upstream-Author: Adam Hupp <adam@hupp.org>
 Date: Mon Dec 4 11:55:27 2017 -0800
+Last-Updated: 2018-01-15
 
 --- a/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.
  
 -## 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, 3 libraries using the package name `magic`.  The others are:
@@ -69,6 +70,24 @@ Date: Mon Dec 4 11:55:27 2017 -0800
  
  ## 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 @@
  
  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
 --- /dev/null
 +++ b/magic/__init__.py
-@@ -0,0 +1,357 @@
+@@ -0,0 +1,361 @@
 +"""
 +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
 +
++# avoid shadowing the real open with the version from compat.py
++_real_open = open
 +
 +class MagicException(Exception):
 +    def __init__(self, message):
@@ -475,8 +496,7 @@ Date: Mon Dec 4 11:55:27 2017 -0800
 +
 +    def from_file(self, filename):
 +        # 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
 +
 +        with self.lock:
@@ -721,7 +741,10 @@ Date: Mon Dec 4 11:55:27 2017 -0800
 +          ('detect_from_fobj', 'magic.Magic.from_open_file'),
 +          ('open', 'magic.Magic')]
 +    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
 +    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),
 +                             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
 +++ b/test/libmagic_test.py
-@@ -0,0 +1,35 @@
+@@ -0,0 +1,39 @@
 +# coding: utf-8
 +
 +import unittest
@@ -1059,7 +1095,11 @@ Date: Mon Dec 4 11:55:27 2017 -0800
 +        self.assert_result(result)
 +
 +    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))
 +        self.assert_result(result)
 +
@@ -1081,10 +1121,12 @@ Date: Mon Dec 4 11:55:27 2017 -0800
 +python3 ${THISDIR}/libmagic_test.py
 --- a/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")'
          self.assertEqual("text/x-python", m.from_buffer(b))
-                 
+-                
++
 +
 +    def test_open_file(self):
 +        m = magic.Magic(mime=True)

+ 0 - 29
debian/patches/make-deprecation-warning-switchable.patch

@@ -1,29 +0,0 @@
-Subject: Make the deprecation warning switchable
-Author: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
-Date: 2018-01-08
-Forwarded: soon
-
---- a/magic/__init__.py
-+++ b/magic/__init__.py
-@@ -19,6 +19,7 @@
- 
- import sys
- import glob
-+import os
- import os.path
- import ctypes
- import ctypes.util
-@@ -325,9 +326,10 @@
- 
-     def deprecation_wrapper(compat, fn, alternate):
-         def _(*args, **kwargs):
--            warnings.warn(
--                "Using compatability mode with libmagic's python binding",
--                DeprecationWarning)
-+            if "PYTHONMAGIC_WARN_DEPRECATED" in os.environ:
-+                warnings.warn(
-+                    "Using compatibility mode with libmagic's python binding",
-+                    DeprecationWarning)
- 
-             return compat[fn](*args, **kwargs)
-         return _

+ 0 - 3
debian/patches/series

@@ -1,5 +1,2 @@
 cherry-pick.0.4.11-32-g9d127ce.update-filetype-reported-by-libmagic-5-23-for-keep-going-true.patch
 libmagic-compat.patch
-fix-buffer-test.patch
-fix-installation.patch
-make-deprecation-warning-switchable.patch