Skip to content

Commit

Permalink
add MAGIC_SYMLINK support, and tests for same
Browse files Browse the repository at this point in the history
  • Loading branch information
ahupp committed Aug 25, 2023
1 parent 7229954 commit 2a01b18
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 121 deletions.
78 changes: 44 additions & 34 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
Changes to 0.4.29:

- support MAGIC_SYMLINK (via follow_symlink flag on Magic constructor)
- correctly throw FileNotFoundException depending on flag

Changes to 0.4.28:
- support "magic-1.dll" on Windows, which is produced by vcpkg
- add python 3.10 to tox config
- update test for upstream gzip extensions

- support "magic-1.dll" on Windows, which is produced by vcpkg
- add python 3.10 to tox config
- update test for upstream gzip extensions

Changes to 0.4.27:
- remove spurious pyproject.toml that breaks source builds

- remove spurious pyproject.toml that breaks source builds

Changes to 0.4.26:
- Use tox for all multi-version testing
- Fix use of pytest, use it via tox

- Use tox for all multi-version testing
- Fix use of pytest, use it via tox

Changes to 0.4.25:
- Support os.PathLike values in Magic.from_file and magic.from_file
- Handle some versions of libmagic that return mime string without charset
- Fix tests for file 5.41
- Include typing stub in package

- Support os.PathLike values in Magic.from_file and magic.from_file
- Handle some versions of libmagic that return mime string without charset
- Fix tests for file 5.41
- Include typing stub in package

Changes to 0.4.24:
- Fix regression in library loading on some Alpine docker images.

- Fix regression in library loading on some Alpine docker images.

Changes to 0.4.23

- Include a `py.typed` sentinal to enable type checking
- Improve fix for attribute error during destruction
- Cleanup library loading logic
- Add new homebrew library dir for OSX
- Include a `py.typed` sentinal to enable type checking
- Improve fix for attribute error during destruction
- Cleanup library loading logic
- Add new homebrew library dir for OSX

Changes to 0.4.21, 0.4.22

- Unify dll loader between the standard and compat library, fixing load
failures on some previously supported platforms.
- Unify dll loader between the standard and compat library, fixing load
failures on some previously supported platforms.

Changes to 0.4.20

- merge in a compatibility layer for the upstream libmagic python binding.
Since both this package and that one are called 'magic', this compat layer
removes a very common source of runtime errors. Use of that libmagic API will
removes a very common source of runtime errors. Use of that libmagic API will
produce a deprecation warning.

- support python 3.9 in tests and pypi metadata
Expand All @@ -44,9 +54,9 @@ Changes to 0.4.20
rather than a filename.

- sometimes the returned description includes snippets of the file, e.g a title
for MS Word docs. Since this is in an unknown encoding, we would throw a
unicode decode error trying to decode. Now, it decodes with
'backslashreplace' to handle this more gracefully. The undecodable characters
for MS Word docs. Since this is in an unknown encoding, we would throw a
unicode decode error trying to decode. Now, it decodes with
'backslashreplace' to handle this more gracefully. The undecodable characters
are replaced with hex escapes.

- add support for MAGIC_EXTENSION, to return possible file extensions.
Expand All @@ -55,18 +65,18 @@ Changes to 0.4.20

Changes in 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.
- 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.

- Add tests for CentOS 7 & 8

Changes in 0.4.16 and 0.4.17

- 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.
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
Expand All @@ -76,12 +86,12 @@ MAGIC_MIME will change to mathch magic.h.
- 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
-- 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
-- document dependency install process for debian
-- various typos
-- document test running process
6 changes: 5 additions & 1 deletion magic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class Magic:
"""

def __init__(self, mime=False, magic_file=None, mime_encoding=False,
keep_going=False, uncompress=False, raw=False, extension=False):
keep_going=False, uncompress=False, raw=False, extension=False,
follow_symlinks=False):
"""
Create a new libmagic wrapper.
Expand All @@ -65,6 +66,9 @@ def __init__(self, mime=False, magic_file=None, mime_encoding=False,
if extension:
self.flags |= MAGIC_EXTENSION

if follow_symlinks:
self.flags |= MAGIC_SYMLINK

self.cookie = magic_open(self.flags)
self.lock = threading.Lock()

Expand Down
6 changes: 2 additions & 4 deletions test/README
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
There are a few ways to run the python-magic tests

1. `pytest` will run the test suite against your default version of python
2. `./test/run_all_versions.py` will run the tests against all installed versions of python.
3. `./test/run_all_docker_test.sh` will run against a variety of different Linux distributions, using docker.

1. `tox` will run the tests against all installed versions of python
2. `./test/run_all_docker_test.sh` will run against a variety of different Linux distributions, using docker.
Loading

0 comments on commit 2a01b18

Please sign in to comment.