commit python-python-magic for openSUSE:Factory
Hello community, here is the log from the commit of package python-python-magic for openSUSE:Factory checked in at 2020-07-31 15:54:33 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-python-magic (Old) and /work/SRC/openSUSE:Factory/.python-python-magic.new.3592 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-python-magic" Fri Jul 31 15:54:33 2020 rev:4 rq:823398 version:0.4.18 Changes: -------- --- /work/SRC/openSUSE:Factory/python-python-magic/python-python-magic.changes 2019-07-04 15:44:36.326234147 +0200 +++ /work/SRC/openSUSE:Factory/.python-python-magic.new.3592/python-python-magic.changes 2020-07-31 15:56:40.724395737 +0200 @@ -1,0 +2,35 @@ +Sat Jul 25 14:46:39 UTC 2020 - Sebastian Wagner <sebix+novell.com@sebix.at> + +- remove patches not necessary anymore: + - magic-new-mime.patch + - magic-pep8.patch + - magic-tests.patch + - magic-new-file.patch +- add patch fix-test.patch and fix-test-tumbleweed.patch to adapt the `file` test outputs to OpenSUSE. +- update to version 0.4.18: + - Make bindings for magic_[set|get]param optional, and throw NotImplementedError + if they are used but not supported. Only call setparam() in the constructor if + it's supported. This prevents breakage on CentOS7 which uses an old version of + libmagic. +- update to version 0.4.16 and 0.4.17 (changelog is combined upstream): + - add MAGIC_MIME_TYPE constant, use that in preference to MAGIC_MIME internally. + This sets up for a breaking change in a future major version bump where + MAGIC_MIME will change to mathch magic.h. + - add magic.version() function to return library version + - add setparam/getparam to control internal behavior + - increase internal limits with setparam to prevent spurious error on some jpeg files + - various setup.py improvements to declare modern python support + - support MSYS2 magic dlls + - fix warning about using 'is' on an int in python 3.8 + - include tests in source distribution + - many test improvements: + - tox runner support + - remove deprecated test_suite field from setup.py + - docker tests that cover all LTS ubuntu versions + - add test for snapp file identification + - doc improvements + - document dependency install process for debian + - various typos + - document test running process + +------------------------------------------------------------------- Old: ---- 0.4.15.tar.gz magic-new-file.patch magic-new-mime.patch magic-pep8.patch magic-tests.patch New: ---- 0.4.18.tar.gz fix-test-tumbleweed.patch fix-test.patch ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-python-magic.spec ++++++ --- /var/tmp/diff_new_pack.N0RB9H/_old 2020-07-31 15:56:43.192398294 +0200 +++ /var/tmp/diff_new_pack.N0RB9H/_new 2020-07-31 15:56:43.196398299 +0200 @@ -1,7 +1,7 @@ # # spec file for package python-python-magic # -# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2020 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -19,17 +19,16 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} %define oldpython python Name: python-python-magic -Version: 0.4.15 +Version: 0.4.18 Release: 0 Summary: File type identification using libmagic License: Python-2.0 Group: Development/Languages/Python URL: https://github.com/ahupp/python-magic Source: https://github.com/ahupp/python-magic/archive/%{version}.tar.gz -Patch0: magic-new-mime.patch -Patch1: magic-pep8.patch -Patch2: magic-tests.patch -Patch3: magic-new-file.patch +#PATCH-FIX-OPENSUSE fix-test.patch -- adapt file outputs to opensuse +Patch0: fix-test.patch +Patch1: fix-test-tumbleweed.patch BuildRequires: %{python_module setuptools} BuildRequires: fdupes BuildRequires: file @@ -52,7 +51,13 @@ %prep %setup -q -n python-magic-%{version} -%autopatch -p1 +%if 0%{?suse_version} > 1500 +# Tumbleweed +%patch1 -p1 +%elif 0%{?sle_version} < 150300 && 0%{?is_opensuse} +# Leap 15.2 and older +%patch0 -p1 +%endif %build %python_build @@ -62,11 +67,12 @@ %python_expand %fdupes %{buildroot}%{$python_sitelib} %check -export LANG=en_US.UTF-8 -%python_exec setup.py test +export LC_ALL=en_US.UTF-8 +%python_expand PYTHONPATH=. $python test/test.py %files %{python_files} %license LICENSE +%doc README.md %{python_sitelib}/magic.py* %pycache_only %{python_sitelib}/__pycache__/magic*.py* %{python_sitelib}/python_magic-%{version}-py*.egg-info ++++++ 0.4.15.tar.gz -> 0.4.18.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/.gitignore new/python-magic-0.4.18/.gitignore --- old/python-magic-0.4.15/.gitignore 2017-12-04 07:06:41.000000000 +0100 +++ new/python-magic-0.4.18/.gitignore 2020-05-06 04:25:46.000000000 +0200 @@ -1,2 +1,12 @@ +.coverage* +.tox/ +bin/ deb_dist +htmlcov/ +lib/ +__pycache__/ python_magic.egg-info +pip-selfcheck.json +pyvenv.cfg +*.pyc +*~ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/.travis.yml new/python-magic-0.4.18/.travis.yml --- old/python-magic-0.4.15/.travis.yml 2017-12-04 07:06:41.000000000 +0100 +++ new/python-magic-0.4.18/.travis.yml 2020-05-06 04:25:46.000000000 +0200 @@ -1,25 +1,20 @@ language: python - -# needed to use trusty -sudo: required - dist: xenial +cache: pip python: - - "2.6" - "2.7" - - "3.3" - - "3.4" - "3.5" - "3.6" - - "nightly" + - "3.7" + - "3.8" install: - pip install coverage - - python setup.py install + - pip install . script: - - coverage run setup.py test + - LC_ALL=en_US.UTF-8 coverage run ./test/test.py after_success: - pip install coveralls && coveralls diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/MANIFEST.in new/python-magic-0.4.18/MANIFEST.in --- old/python-magic-0.4.15/MANIFEST.in 2017-12-04 07:06:41.000000000 +0100 +++ new/python-magic-0.4.18/MANIFEST.in 2020-05-06 04:25:46.000000000 +0200 @@ -1,2 +1,5 @@ include *.py include LICENSE +graft tests +global-exclude __pycache__ +global-exclude *.py[co] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/README.md new/python-magic-0.4.18/README.md --- old/python-magic-0.4.15/README.md 2017-12-04 07:06:41.000000000 +0100 +++ new/python-magic-0.4.18/README.md 2020-05-06 04:25:46.000000000 +0200 @@ -2,7 +2,7 @@ [![PyPI version](https://badge.fury.io/py/python-magic.svg)](https://badge.fury.io/py/python-magic) [![Build Status](https://travis-ci.org/ahupp/python-magic.svg?branch=master)](https://travis-ci.org/ahupp/python-magic) -python-magic is a python interface to the libmagic file type +python-magic is a Python interface to the libmagic file type identification library. libmagic identifies file types by checking their headers according to a predefined list of file types. This functionality is exposed to the command line by the Unix command @@ -14,7 +14,8 @@
import magic magic.from_file("testdata/test.pdf") 'PDF document, version 1.2' ->>> magic.from_buffer(open("testdata/test.pdf").read(1024)) +# recommend using at least the first 2048 bytes, as less can produce incorrect identification +>>> magic.from_buffer(open("testdata/test.pdf").read(2048)) 'PDF document, version 1.2' magic.from_file("testdata/test.pdf", mime=True) 'application/pdf' @@ -41,35 +42,33 @@ 'text/plain'
-## Versioning
-
-Minor version bumps should be backwards compatible. Major bumps are not.
-
-## Name Conflict
-
-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.
-
## Installation
-The current stable version of python-magic is available on pypi and
+The current stable version of python-magic is available on PyPI and
can be installed by running `pip install python-magic`.
Other sources:
-- pypi: http://pypi.python.org/pypi/python-magic/
-- github: https://github.com/ahupp/python-magic
+- PyPI: http://pypi.python.org/pypi/python-magic/
+- GitHub: https://github.com/ahupp/python-magic
+
+This module is a simple wrapper around the libmagic C library, and
+that must be installed as well:
+
+### Debian/Ubuntu
+
+ $ sudo apt-get install libmagic1
### Windows
-You'll need DLLs for libmagic. @julian-r has uploaded a versoin of this project that includes binaries to pypi:
+You'll need DLLs for libmagic. @julian-r has uploaded a version 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.
-
### OSX
- When using Homebrew: `brew install libmagic`
@@ -89,6 +88,42 @@
- '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.
+
+## Bug Reports
+
+python-magic is a thin layer over the libmagic C library.
+Historically, most bugs that have been reported against python-magic
+are actually bugs in libmagic; libmagic bugs can be reported on their
+tracker here: https://bugs.astron.com/my_view_page.php. If you're not
+sure where the bug lies feel free to file an issue on GitHub and I can
+triage it.
+
+## Running the tests
+
+To run the tests across 3 recent Ubuntu LTS releases (depends on Docker):
+
+ $ ./test_docker.sh
+
+To run tests locally across all available python versions:
+
+ $ ./test/run.py
+
+To run against a specific python version:
+
+ $ LC_ALL=en_US.UTF-8 python3 test/test.py
+
+## Versioning
+
+Minor version bumps should be backwards compatible. Major bumps are not.
+
+## Name Conflict
+
+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.
+
+
## Author
Written by Adam Hupp in 2001 for a project that never got off the
@@ -96,16 +131,17 @@
switched to ctypes once that was part of the python standard library.
You can contact me via my [website](http://hupp.org/adam) or
-[github](http://github.com/ahupp).
+[GitHub](http://github.com/ahupp).
## Contributors
-Thanks to these folks on github who submitted features and bugfixes.
+Thanks to these folks on github who submitted features and bug fixes.
- Amit Sethi
- [bigben87](https://github.com/bigben87)
- [fallgesetz](https://github.com/fallgesetz)
- [FlaPer87](https://github.com/FlaPer87)
+- [Hugo van Kemenade](https://github.com/hugovk)
- [lukenowak](https://github.com/lukenowak)
- NicolasDelaby
- sacha@ssl.co.uk
@@ -117,4 +153,5 @@
python-magic is distributed under the MIT license. See the included
LICENSE file for details.
+I am providing code in the repository to you under an open source license. Because this is my personal repository, the license you receive to my code is from me and not my employer (Facebook).
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/magic.py new/python-magic-0.4.18/magic.py
--- old/python-magic-0.4.15/magic.py 2017-12-04 07:06:41.000000000 +0100
+++ new/python-magic-0.4.18/magic.py 2020-05-06 04:25:46.000000000 +0200
@@ -14,17 +14,15 @@
'PDF document, version 1.2'
>>>
-
"""
import sys
import glob
-import os.path
import ctypes
import ctypes.util
import threading
-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, byref, POINTER
class MagicException(Exception):
@@ -36,11 +34,10 @@
class Magic:
"""
Magic is a wrapper around the libmagic C library.
-
"""
def __init__(self, mime=False, magic_file=None, mime_encoding=False,
- keep_going=False, uncompress=False):
+ keep_going=False, uncompress=False, raw=False):
"""
Create a new libmagic wrapper.
@@ -49,23 +46,35 @@
magic_file - use a mime database other than the system default
keep_going - don't stop at the first match, keep going
uncompress - Try to look inside compressed files.
+ raw - Do not try to decode "non-printable" chars.
"""
self.flags = MAGIC_NONE
if mime:
- self.flags |= MAGIC_MIME
+ self.flags |= MAGIC_MIME_TYPE
if mime_encoding:
self.flags |= MAGIC_MIME_ENCODING
if keep_going:
self.flags |= MAGIC_CONTINUE
-
if uncompress:
self.flags |= MAGIC_COMPRESS
+ if raw:
+ self.flags |= MAGIC_RAW
self.cookie = magic_open(self.flags)
self.lock = threading.Lock()
-
+
magic_load(self.cookie, magic_file)
+
+ # For https://github.com/ahupp/python-magic/issues/190
+ # libmagic has fixed internal limits that some files exceed, causing
+ # an error. We can avoid this (at least for the sample file given)
+ # by bumping the limit up. It's not clear if this is a general solution
+ # or whether other internal limits should be increased, but given
+ # the lack of other reports I'll assume this is rare.
+ if _has_param:
+ self.setparam(MAGIC_PARAM_NAME_MAX, 64)
+
def from_buffer(self, buf):
"""
Identify the contents of `buf`
@@ -76,7 +85,7 @@
# 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')
+ buf = buf.encode('utf-8', errors='replace')
return maybe_decode(magic_buffer(self.cookie, buf))
except MagicException as e:
return self._handle509Bug(e)
@@ -95,11 +104,17 @@
# libmagic 5.09 has a bug where it might fail to identify the
# mimetype of a file and returns null from magic_file (and
# likely _buffer), but also does not return an error message.
- if e.message is None and (self.flags & MAGIC_MIME):
+ if e.message is None and (self.flags & MAGIC_MIME_TYPE):
return "application/octet-stream"
else:
raise e
-
+
+ def setparam(self, param, val):
+ return magic_setparam(self.cookie, param, val)
+
+ def getparam(self, param):
+ return magic_getparam(self.cookie, param)
+
def __del__(self):
# no _thread_check here because there can be no other
# references to this object at this point.
@@ -117,12 +132,14 @@
_instances = {}
+
def _get_magic_type(mime):
i = _instances.get(mime)
if i is None:
i = _instances[mime] = Magic(mime=mime)
return i
+
def from_file(filename, mime=False):
""""
Accepts a filename and returns the detected filetype. Return
@@ -135,6 +152,7 @@
m = _get_magic_type(mime)
return m.from_file(filename)
+
def from_buffer(buffer, mime=False):
"""
Accepts a binary string and returns the detected filetype. Return
@@ -148,25 +166,27 @@
return m.from_buffer(buffer)
-
-
libmagic = None
# Let's try to find magic or magic1
-dll = ctypes.util.find_library('magic') or ctypes.util.find_library('magic1') or ctypes.util.find_library('cygmagic-1')
+dll = ctypes.util.find_library('magic') \
+ or ctypes.util.find_library('magic1') \
+ or ctypes.util.find_library('cygmagic-1') \
+ or ctypes.util.find_library('libmagic-1') \
+ or ctypes.util.find_library('msys-magic-1') #for MSYS2
-# This is necessary because find_library returns None if it doesn't find the library
+# necessary because find_library returns None if it doesn't find the library
if dll:
libmagic = ctypes.CDLL(dll)
if not libmagic or not libmagic._name:
- windows_dlls = ['magic1.dll','cygmagic-1.dll']
+ windows_dlls = ['magic1.dll', 'cygmagic-1.dll', 'libmagic-1.dll', 'msys-magic-1.dll']
platform_to_lib = {'darwin': ['/opt/local/lib/libmagic.dylib',
'/usr/local/lib/libmagic.dylib'] +
- # Assumes there will only be one version installed
- glob.glob('/usr/local/Cellar/libmagic/*/lib/libmagic.dylib'),
+ # Assumes there will only be one version installed
+ glob.glob('/usr/local/Cellar/libmagic/*/lib/libmagic.dylib'), # flake8:noqa
'win32': windows_dlls,
'cygwin': windows_dlls,
- 'linux': ['libmagic.so.1'], # fallback for some Linuxes (e.g. Alpine) where library search does not work
+ 'linux': ['libmagic.so.1'], # fallback for some Linuxes (e.g. Alpine) where library search does not work # flake8:noqa
}
platform = 'linux' if sys.platform.startswith('linux') else sys.platform
for dll in platform_to_lib.get(platform, []):
@@ -182,6 +202,7 @@
magic_t = ctypes.c_void_p
+
def errorcheck_null(result, func, args):
if result is None:
err = magic_error(args[0])
@@ -189,8 +210,9 @@
else:
return result
+
def errorcheck_negative_one(result, func, args):
- if result is -1:
+ if result == -1:
err = magic_error(args[0])
raise MagicException(err)
else:
@@ -204,13 +226,14 @@
return s
else:
return s.decode('utf-8')
-
+
+
def coerce_filename(filename):
if filename is None:
return None
# ctypes will implicitly convert unicode strings to bytes with
- # .encode('ascii'). If you use the filesystem encoding
+ # .encode('ascii'). If you use the filesystem encoding
# then you'll get inconsistent behavior (crashes) depending on the user's
# LANG environment variable
is_unicode = (sys.version_info[0] <= 2 and
@@ -222,6 +245,7 @@
else:
return filename
+
magic_open = libmagic.magic_open
magic_open.restype = magic_t
magic_open.argtypes = [c_int]
@@ -243,6 +267,7 @@
_magic_file.argtypes = [magic_t, c_char_p]
_magic_file.errcheck = errorcheck_null
+
def magic_file(cookie, filename):
return _magic_file(cookie, coerce_filename(filename))
@@ -251,6 +276,7 @@
_magic_buffer.argtypes = [magic_t, c_void_p, c_size_t]
_magic_buffer.errcheck = errorcheck_null
+
def magic_buffer(cookie, buf):
return _magic_buffer(cookie, buf, len(buf))
@@ -260,6 +286,7 @@
_magic_load.argtypes = [magic_t, c_char_p]
_magic_load.errcheck = errorcheck_negative_one
+
def magic_load(cookie, filename):
return _magic_load(cookie, coerce_filename(filename))
@@ -275,15 +302,55 @@
magic_compile.restype = c_int
magic_compile.argtypes = [magic_t, c_char_p]
-
+_has_param = False
+if hasattr(libmagic, 'magic_setparam') and hasattr(libmagic, 'magic_getparam'):
+ _has_param = True
+ _magic_setparam = libmagic.magic_setparam
+ _magic_setparam.restype = c_int
+ _magic_setparam.argtypes = [magic_t, c_int, POINTER(c_size_t)]
+ _magic_setparam.errcheck = errorcheck_negative_one
+
+ _magic_getparam = libmagic.magic_getparam
+ _magic_getparam.restype = c_int
+ _magic_getparam.argtypes = [magic_t, c_int, POINTER(c_size_t)]
+ _magic_getparam.errcheck = errorcheck_negative_one
+
+def magic_setparam(cookie, param, val):
+ if not _has_param:
+ raise NotImplementedError("magic_setparam not implemented")
+ v = c_size_t(val)
+ return _magic_setparam(cookie, param, byref(v))
+
+def magic_getparam(cookie, param):
+ if not _has_param:
+ raise NotImplementedError("magic_getparam not implemented")
+ val = c_size_t()
+ _magic_getparam(cookie, param, byref(val))
+ return val.value
+
+_has_version = False
+if hasattr(libmagic, "magic_version"):
+ _has_version = True
+ magic_version = libmagic.magic_version
+ magic_version.restype = c_int
+ magic_version.argtypes = []
+
+def version():
+ if not _has_version:
+ raise NotImplementedError("magic_version not implemented")
+ return magic_version()
MAGIC_NONE = 0x000000 # No flags
MAGIC_DEBUG = 0x000001 # Turn on debugging
MAGIC_SYMLINK = 0x000002 # Follow symlinks
MAGIC_COMPRESS = 0x000004 # Check inside compressed files
MAGIC_DEVICES = 0x000008 # Look at the contents of devices
-MAGIC_MIME = 0x000010 # Return a mime string
+MAGIC_MIME_TYPE = 0x000010 # Return a mime string
MAGIC_MIME_ENCODING = 0x000400 # Return the MIME encoding
+# TODO: should be
+# MAGIC_MIME = MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING
+MAGIC_MIME = 0x000010 # Return a mime string
+
MAGIC_CONTINUE = 0x000020 # Return all matches
MAGIC_CHECK = 0x000040 # Print warnings to stderr
MAGIC_PRESERVE_ATIME = 0x000080 # Restore access time on exit
@@ -299,3 +366,11 @@
MAGIC_NO_CHECK_TROFF = 0x040000 # Don't check ascii/troff
MAGIC_NO_CHECK_FORTRAN = 0x080000 # Don't check ascii/fortran
MAGIC_NO_CHECK_TOKENS = 0x100000 # Don't check ascii/tokens
+
+MAGIC_PARAM_INDIR_MAX = 0 # Recursion limit for indirect magic
+MAGIC_PARAM_NAME_MAX = 1 # Use count limit for name/use magic
+MAGIC_PARAM_ELF_PHNUM_MAX = 2 # Max ELF notes processed
+MAGIC_PARAM_ELF_SHNUM_MAX = 3 # Max ELF program sections processed
+MAGIC_PARAM_ELF_NOTES_MAX = 4 # # Max ELF sections processed
+MAGIC_PARAM_REGEX_MAX = 5 # Length limit for regex searches
+MAGIC_PARAM_BYTES_MAX = 6 # Max number of bytes to read from file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/setup.py new/python-magic-0.4.18/setup.py
--- old/python-magic-0.4.15/setup.py 2017-12-04 07:06:41.000000000 +0100
+++ new/python-magic-0.4.18/setup.py 2020-05-06 04:25:46.000000000 +0200
@@ -2,33 +2,39 @@
# -*- coding: utf-8 -*-
from setuptools import setup
+import io
+import os
+
+
+def read(file_name):
+ """Read a text file and return the content as a string."""
+ with io.open(os.path.join(os.path.dirname(__file__), file_name),
+ encoding='utf-8') as f:
+ return f.read()
setup(name='python-magic',
description='File type identification using libmagic',
author='Adam Hupp',
author_email='adam@hupp.org',
url="http://github.com/ahupp/python-magic",
- version='0.4.15',
+ version='0.4.18',
py_modules=['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.
-""",
+ long_description=read('README.md'),
+ long_description_content_type='text/markdown',
keywords="mime magic file",
license="MIT",
- test_suite='test',
+ python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
- 'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
- 'Programming Language :: Python :: 3.3',
- 'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
+ 'Programming Language :: Python :: 3.7',
+ 'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: CPython',
],
)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test/Dockerfile_bionic new/python-magic-0.4.18/test/Dockerfile_bionic
--- old/python-magic-0.4.15/test/Dockerfile_bionic 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/test/Dockerfile_bionic 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,8 @@
+FROM ubuntu:bionic
+RUN apt-get update
+RUN apt-get -y install python
+RUN apt-get -y install python3
+RUN apt-get -y install locales
+RUN locale-gen en_US.UTF-8
+COPY . /python-magic
+CMD cd /python-magic/test && python3 ./run.py
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test/Dockerfile_centos7 new/python-magic-0.4.18/test/Dockerfile_centos7
--- old/python-magic-0.4.15/test/Dockerfile_centos7 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/test/Dockerfile_centos7 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,5 @@
+FROM centos:7
+RUN yum -y update
+RUN yum -y install file-devel python3 python2 which
+COPY . /python-magic
+CMD cd /python-magic/test && python3 ./run.py
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test/Dockerfile_centos8 new/python-magic-0.4.18/test/Dockerfile_centos8
--- old/python-magic-0.4.15/test/Dockerfile_centos8 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/test/Dockerfile_centos8 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,5 @@
+FROM centos:8
+RUN yum -y update
+RUN yum -y install file-libs python3 python2 which
+COPY . /python-magic
+CMD cd /python-magic/test && python3 ./run.py
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test/Dockerfile_focal new/python-magic-0.4.18/test/Dockerfile_focal
--- old/python-magic-0.4.15/test/Dockerfile_focal 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/test/Dockerfile_focal 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,8 @@
+FROM ubuntu:focal
+RUN apt-get update
+RUN apt-get -y install python2
+RUN apt-get -y install python3
+RUN apt-get -y install locales
+RUN locale-gen en_US.UTF-8
+COPY . /python-magic
+CMD cd /python-magic/test && python3 ./run.py
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test/Dockerfile_xenial new/python-magic-0.4.18/test/Dockerfile_xenial
--- old/python-magic-0.4.15/test/Dockerfile_xenial 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/test/Dockerfile_xenial 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,8 @@
+FROM ubuntu:xenial
+RUN apt-get update
+RUN apt-get -y install python
+RUN apt-get -y install python3
+RUN apt-get -y install locales
+RUN locale-gen en_US.UTF-8
+COPY . /python-magic
+CMD cd /python-magic/test && python3 ./run.py
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test/README new/python-magic-0.4.18/test/README
--- old/python-magic-0.4.15/test/README 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/test/README 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,10 @@
+To run the tests across a selection of Ubuntu LTS versions:
+
+docker build -t "python_magic/xenial:latest" -f test/Dockerfile_xenial .
+docker build -t "python_magic/bionic:latest" -f test/Dockerfile_bionic .
+docker build -t "python_magic/focal:latest" -f test/Dockerfile_focal .
+
+docker run python_magic/xenial:latest
+docker run python_magic/bionic:latest
+docker run python_magic/focal:latest
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test/run.py new/python-magic-0.4.18/test/run.py
--- old/python-magic-0.4.15/test/run.py 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/test/run.py 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,32 @@
+
+import subprocess
+import os.path
+import sys
+
+this_dir = os.path.dirname(sys.argv[0])
+
+new_env = {
+ 'LC_ALL': 'en_US.UTF-8',
+ 'PYTHONPATH': os.path.join(this_dir, ".."),
+}
+
+def has_py(version):
+ ret = subprocess.run("which %s" % version, shell=True, stdout=subprocess.DEVNULL)
+ return ret.returncode == 0
+
+def run_test(versions):
+
+ found = False
+ for i in versions:
+ if not has_py(i):
+ # if this version doesn't exist in path, skip
+ continue
+ found = True
+ print("Testing %s" % i)
+ subprocess.run([i, os.path.join(this_dir, "test.py")], env=new_env, check=True)
+
+ if not found:
+ sys.exit("No versions found: " + str(versions))
+
+run_test(["python2", "python2.7"])
+run_test(["python3.5", "python3.6", "python3.7", "python3.8"])
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test/run.sh new/python-magic-0.4.18/test/run.sh
--- old/python-magic-0.4.15/test/run.sh 2017-12-04 07:06:41.000000000 +0100
+++ new/python-magic-0.4.18/test/run.sh 1970-01-01 01:00:00.000000000 +0100
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-
-# ensure we can use unicode filenames in the test
-export LC_ALL=en_US.UTF-8
-THISDIR=`dirname $0`
-export PYTHONPATH=${THISDIR}/..
-
-echo "python2.6"
-python2.6 ${THISDIR}/test.py
-echo "python2.7"
-python2.7 ${THISDIR}/test.py
-echo "python3.0"
-python3 ${THISDIR}/test.py
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test/test.py new/python-magic-0.4.18/test/test.py
--- old/python-magic-0.4.15/test/test.py 2017-12-04 07:06:41.000000000 +0100
+++ new/python-magic-0.4.18/test/test.py 2020-05-06 04:25:46.000000000 +0200
@@ -1,35 +1,60 @@
-import os, sys
+import os
# for output which reports a local time
os.environ['TZ'] = 'GMT'
+
+if os.environ.get('LC_ALL','') != 'en_US.UTF-8':
+ # this ensure we're in a utf-8 default filesystem encoding which is
+ # necessary for some tests
+ raise Exception("must run `export LC_ALL=en_US.UTF-8` before running test suite")
+
import shutil
import os.path
import unittest
import magic
+import sys
class MagicTest(unittest.TestCase):
- TESTDATA_DIR = os.path.join(os.path.dirname(__file__), 'testdata')
+ TESTDATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'testdata')
+
+ def test_version(self):
+ try:
+ self.assertTrue(magic.version() > 0)
+ except NotImplementedError:
+ pass
+
+ def test_fs_encoding(self):
+ self.assertEqual('utf-8', sys.getfilesystemencoding().lower())
- def assert_values(self, m, expected_values):
+ def assert_values(self, m, expected_values, buf_equals_file=True):
for filename, expected_value in expected_values.items():
try:
filename = os.path.join(self.TESTDATA_DIR, filename)
except TypeError:
- filename = os.path.join(self.TESTDATA_DIR.encode('utf-8'), filename)
+ filename = os.path.join(
+ self.TESTDATA_DIR.encode('utf-8'), filename)
-
if type(expected_value) is not tuple:
expected_value = (expected_value,)
- for i in expected_value:
- with open(filename, 'rb') as f:
- buf_value = m.from_buffer(f.read())
-
- file_value = m.from_file(filename)
- if buf_value == i and file_value == i:
- break
- else:
- self.assertTrue(False, "no match for " + repr(expected_value))
+ with open(filename, 'rb') as f:
+ buf_value = m.from_buffer(f.read())
+
+ file_value = m.from_file(filename)
+
+ if buf_equals_file:
+ self.assertEqual(buf_value, file_value)
+
+ for value in (buf_value, file_value):
+ self.assertIn(value, expected_value)
+
+ def test_from_file_str_and_bytes(self):
+ filename = os.path.join(self.TESTDATA_DIR, "test.pdf")
+
+ self.assertEqual('application/pdf',
+ magic.from_file(filename, mime=True))
+ self.assertEqual('application/pdf',
+ magic.from_file(filename.encode('utf-8'), mime=True))
def test_from_buffer_str_and_bytes(self):
m = magic.Magic(mime=True)
@@ -37,16 +62,18 @@
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_mime_types(self):
- dest = os.path.join(MagicTest.TESTDATA_DIR, b'\xce\xbb'.decode('utf-8'))
+ dest = os.path.join(MagicTest.TESTDATA_DIR,
+ b'\xce\xbb'.decode('utf-8'))
shutil.copyfile(os.path.join(MagicTest.TESTDATA_DIR, 'lambda'), dest)
try:
m = magic.Magic(mime=True)
self.assert_values(m, {
'magic._pyc_': 'application/octet-stream',
'test.pdf': 'application/pdf',
- 'test.gz': 'application/gzip',
+ 'test.gz': ('application/gzip', 'application/x-gzip'),
+ 'test.snappy.parquet': 'application/octet-stream',
'text.txt': 'text/plain',
b'\xce\xbb'.decode('utf-8'): 'text/plain',
b'\xce\xbb': 'text/plain',
@@ -56,19 +83,47 @@
def test_descriptions(self):
m = magic.Magic()
- os.environ['TZ'] = 'UTC' # To get the last modified date of test.gz in UTC
+ os.environ['TZ'] = 'UTC' # To get last modified date of test.gz in UTC
try:
self.assert_values(m, {
'magic._pyc_': 'python 2.4 byte-compiled',
'test.pdf': 'PDF document, version 1.2',
'test.gz':
- ('gzip compressed data, was "test", from Unix, last modified: Sun Jun 29 01:32:52 2008',
- 'gzip compressed data, was "test", last modified: Sun Jun 29 01:32:52 2008, from Unix'),
+ ('gzip compressed data, was "test", from Unix, last '
+ 'modified: Sun Jun 29 01:32:52 2008',
+ 'gzip compressed data, was "test", last modified'
+ ': Sun Jun 29 01:32:52 2008, from Unix',
+ 'gzip compressed data, was "test", last modified'
+ ': Sun Jun 29 01:32:52 2008, from Unix, original size 15',
+ 'gzip compressed data, was "test", '
+ 'last modified: Sun Jun 29 01:32:52 2008, '
+ 'from Unix, original size modulo 2^32 15'
+ ),
'text.txt': 'ASCII text',
- })
+ 'test.snappy.parquet': ('Apache Parquet', 'Par archive data'),
+ }, buf_equals_file=False)
finally:
del os.environ['TZ']
+ def test_unicode_result_nonraw(self):
+ m = magic.Magic(raw=False)
+ src = os.path.join(MagicTest.TESTDATA_DIR, 'pgpunicode')
+ result = m.from_file(src)
+ # NOTE: This check is added as otherwise some magic files don't identify the test case as a PGP key.
+ if 'PGP' in result:
+ assert r"PGP\011Secret Sub-key -" == result
+ else:
+ raise unittest.SkipTest("Magic file doesn't return expected type.")
+
+ def test_unicode_result_raw(self):
+ m = magic.Magic(raw=True)
+ src = os.path.join(MagicTest.TESTDATA_DIR, 'pgpunicode')
+ result = m.from_file(src)
+ if 'PGP' in result:
+ assert b'PGP\tSecret Sub-key -' == result.encode('utf-8')
+ else:
+ raise unittest.SkipTest("Magic file doesn't return expected type.")
+
def test_mime_encodings(self):
m = magic.Magic(mime_encoding=True)
self.assert_values(m, {
@@ -92,20 +147,41 @@
m = magic.Magic(mime=True)
self.assertEqual(m.from_file(filename), 'image/jpeg')
-
- m = magic.Magic(mime=True, keep_going=True)
- self.assertEqual(m.from_file(filename), 'image/jpeg')
+ try:
+ # this will throw if you have an "old" version of the library
+ # I'm otherwise not sure how to query if keep_going is supported
+ magic.version()
+ m = magic.Magic(mime=True, keep_going=True)
+ self.assertEqual(m.from_file(filename),
+ 'image/jpeg\\012- application/octet-stream')
+ except NotImplementedError:
+ pass
def test_rethrow(self):
old = magic.magic_buffer
try:
- def t(x,y):
+ def t(x, y):
raise magic.MagicException("passthrough")
magic.magic_buffer = t
-
- self.assertRaises(magic.MagicException, magic.from_buffer, "hello", True)
+
+ with self.assertRaises(magic.MagicException):
+ magic.from_buffer("hello", True)
finally:
magic.magic_buffer = old
+
+ def test_getparam(self):
+ m = magic.Magic(mime=True)
+ try:
+ m.setparam(magic.MAGIC_PARAM_INDIR_MAX, 1)
+ self.assertEqual(m.getparam(magic.MAGIC_PARAM_INDIR_MAX), 1)
+ except NotImplementedError:
+ pass
+
+ def test_name_count(self):
+ m = magic.Magic()
+ with open(os.path.join(self.TESTDATA_DIR, 'name_use.jpg'), 'rb') as f:
+ m.from_buffer(f.read())
+
if __name__ == '__main__':
unittest.main()
Binary files old/python-magic-0.4.15/test/testdata/name_use.jpg and new/python-magic-0.4.18/test/testdata/name_use.jpg differ
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test/testdata/pgpunicode new/python-magic-0.4.18/test/testdata/pgpunicode
--- old/python-magic-0.4.15/test/testdata/pgpunicode 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/test/testdata/pgpunicode 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1 @@
+qÊ
\ No newline at end of file
Binary files old/python-magic-0.4.15/test/testdata/test.snappy.parquet and new/python-magic-0.4.18/test/testdata/test.snappy.parquet differ
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test.ps1 new/python-magic-0.4.18/test.ps1
--- old/python-magic-0.4.15/test.ps1 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/test.ps1 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,11 @@
+
+
+function TestInContainer($name) {
+ $TAG="python_magic/${name}:latest"
+ docker build -t $TAG -f "test/Dockerfile_${name}" .
+ docker run "python_magic/${name}:latest"
+}
+
+TestInContainer "xenial"
+TestInContainer "bionic"
+TestInContainer "focal"
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/test_docker.sh new/python-magic-0.4.18/test_docker.sh
--- old/python-magic-0.4.15/test_docker.sh 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/test_docker.sh 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# Test with various versions of ubuntu. This more or less re-creates the
+# Travis CI test environment
+
+set -e
+
+function TestInContainer {
+ local name="$1"
+ local TAG="python_magic/${name}:latest"
+ docker build -t $TAG -f "test/Dockerfile_${name}" .
+ docker run "python_magic/${name}:latest"
+}
+
+TestInContainer "xenial"
+TestInContainer "bionic"
+TestInContainer "focal"
+TestInContainer "centos7"
+TestInContainer "centos8"
+
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/tox.ini new/python-magic-0.4.18/tox.ini
--- old/python-magic-0.4.15/tox.ini 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/tox.ini 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,39 @@
+[tox]
+envlist =
+ coverage-clean,
+ py27,
+ py35,
+ py36,
+ py37,
+ py38,
+ coverage-report
+
+[testenv]
+commands =
+ coverage run --source=magic ./test/test.py
+
+setenv =
+ COVERAGE_FILE=.coverage.{envname}
+ LC_ALL=en_US.UTF-8
+deps =
+ .[test]
+ zope.testrunner
+ coverage
+
+[testenv:coverage-clean]
+deps = coverage
+setenv =
+ COVERAGE_FILE=.coverage
+skip_install = true
+commands = coverage erase
+
+[testenv:coverage-report]
+deps = coverage
+setenv =
+ COVERAGE_FILE=.coverage
+skip_install = true
+commands =
+ coverage combine
+ coverage report
+ coverage html
+ coverage
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-magic-0.4.15/upload.sh new/python-magic-0.4.18/upload.sh
--- old/python-magic-0.4.15/upload.sh 1970-01-01 01:00:00.000000000 +0100
+++ new/python-magic-0.4.18/upload.sh 2020-05-06 04:25:46.000000000 +0200
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+python setup.py sdist bdist_wheel upload
++++++ fix-test-tumbleweed.patch ++++++
--- python-magic-0.4.18/test/test.py 2020-05-06 04:25:46.000000000 +0200
+++ python-magic-0.4.18/test/test.py 2020-07-25 19:51:08.263172240 +0200
@@ -59,9 +59,9 @@
def test_from_buffer_str_and_bytes(self):
m = magic.Magic(mime=True)
s = '#!/usr/bin/env python\nprint("foo")'
- self.assertEqual("text/x-python", m.from_buffer(s))
+ self.assertEqual("text/x-script.python", m.from_buffer(s))
b = b'#!/usr/bin/env python\nprint("foo")'
- self.assertEqual("text/x-python", m.from_buffer(b))
+ self.assertEqual("text/x-script.python", m.from_buffer(b))
def test_mime_types(self):
dest = os.path.join(MagicTest.TESTDATA_DIR,
@@ -70,7 +70,7 @@
try:
m = magic.Magic(mime=True)
self.assert_values(m, {
- 'magic._pyc_': 'application/octet-stream',
+ 'magic._pyc_': 'text/x-bytecode.python',
'test.pdf': 'application/pdf',
'test.gz': ('application/gzip', 'application/x-gzip'),
'test.snappy.parquet': 'application/octet-stream',
@@ -97,7 +97,9 @@
': Sun Jun 29 01:32:52 2008, from Unix, original size 15',
'gzip compressed data, was "test", '
'last modified: Sun Jun 29 01:32:52 2008, '
- 'from Unix, original size modulo 2^32 15'
+ 'from Unix, original size modulo 2^32 15',
+ 'gzip compressed data, was "test", last modified: '
+ 'Sun Jun 29 01:32:52 2008, from Unix, truncated',
),
'text.txt': 'ASCII text',
'test.snappy.parquet': ('Apache Parquet', 'Par archive data'),
++++++ fix-test.patch ++++++
--- python-magic-0.4.18/test/test.py 2020-05-06 04:25:46.000000000 +0200
+++ python-magic-0.4.18/test/test.py 2020-07-25 20:02:37.988452945 +0200
@@ -97,7 +97,9 @@
': Sun Jun 29 01:32:52 2008, from Unix, original size 15',
'gzip compressed data, was "test", '
'last modified: Sun Jun 29 01:32:52 2008, '
- 'from Unix, original size modulo 2^32 15'
+ 'from Unix, original size modulo 2^32 15',
+ 'gzip compressed data, was "test", last modified: '
+ 'Sun Jun 29 01:32:52 2008, from Unix, truncated',
),
'text.txt': 'ASCII text',
'test.snappy.parquet': ('Apache Parquet', 'Par archive data'),
participants (1)
-
root