Skip to content

Commit 2a01b18

Browse files
committed
add MAGIC_SYMLINK support, and tests for same
1 parent 7229954 commit 2a01b18

File tree

4 files changed

+193
-121
lines changed

4 files changed

+193
-121
lines changed

CHANGELOG

+44-34
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
1+
Changes to 0.4.29:
2+
3+
- support MAGIC_SYMLINK (via follow_symlink flag on Magic constructor)
4+
- correctly throw FileNotFoundException depending on flag
5+
16
Changes to 0.4.28:
2-
- support "magic-1.dll" on Windows, which is produced by vcpkg
3-
- add python 3.10 to tox config
4-
- update test for upstream gzip extensions
7+
8+
- support "magic-1.dll" on Windows, which is produced by vcpkg
9+
- add python 3.10 to tox config
10+
- update test for upstream gzip extensions
511

612
Changes to 0.4.27:
7-
- remove spurious pyproject.toml that breaks source builds
13+
14+
- remove spurious pyproject.toml that breaks source builds
815

916
Changes to 0.4.26:
10-
- Use tox for all multi-version testing
11-
- Fix use of pytest, use it via tox
17+
18+
- Use tox for all multi-version testing
19+
- Fix use of pytest, use it via tox
1220

1321
Changes to 0.4.25:
14-
- Support os.PathLike values in Magic.from_file and magic.from_file
15-
- Handle some versions of libmagic that return mime string without charset
16-
- Fix tests for file 5.41
17-
- Include typing stub in package
22+
23+
- Support os.PathLike values in Magic.from_file and magic.from_file
24+
- Handle some versions of libmagic that return mime string without charset
25+
- Fix tests for file 5.41
26+
- Include typing stub in package
1827

1928
Changes to 0.4.24:
20-
- Fix regression in library loading on some Alpine docker images.
29+
30+
- Fix regression in library loading on some Alpine docker images.
2131

2232
Changes to 0.4.23
2333

24-
- Include a `py.typed` sentinal to enable type checking
25-
- Improve fix for attribute error during destruction
26-
- Cleanup library loading logic
27-
- Add new homebrew library dir for OSX
34+
- Include a `py.typed` sentinal to enable type checking
35+
- Improve fix for attribute error during destruction
36+
- Cleanup library loading logic
37+
- Add new homebrew library dir for OSX
2838

2939
Changes to 0.4.21, 0.4.22
3040

31-
- Unify dll loader between the standard and compat library, fixing load
32-
failures on some previously supported platforms.
41+
- Unify dll loader between the standard and compat library, fixing load
42+
failures on some previously supported platforms.
3343

3444
Changes to 0.4.20
3545

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

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

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

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

5666
Changes in 0.4.18
5767

58-
- Make bindings for magic_[set|get]param optional, and throw NotImplementedError
59-
if they are used but not supported. Only call setparam() in the constructor if
60-
it's supported. This prevents breakage on CentOS7 which uses an old version of
61-
libmagic.
68+
- Make bindings for magic\_[set|get]param optional, and throw NotImplementedError
69+
if they are used but not supported. Only call setparam() in the constructor if
70+
it's supported. This prevents breakage on CentOS7 which uses an old version of
71+
libmagic.
6272

6373
- Add tests for CentOS 7 & 8
6474

6575
Changes in 0.4.16 and 0.4.17
6676

6777
- add MAGIC_MIME_TYPE constant, use that in preference to MAGIC_MIME internally.
68-
This sets up for a breaking change in a future major version bump where
69-
MAGIC_MIME will change to mathch magic.h.
78+
This sets up for a breaking change in a future major version bump where
79+
MAGIC_MIME will change to mathch magic.h.
7080
- add magic.version() function to return library version
7181
- add setparam/getparam to control internal behavior
7282
- increase internal limits with setparam to prevent spurious error on some jpeg files
@@ -76,12 +86,12 @@ MAGIC_MIME will change to mathch magic.h.
7686
- include tests in source distribution
7787

7888
- many test improvements:
79-
-- tox runner support
80-
-- remove deprecated test_suite field from setup.py
81-
-- docker tests that cover all LTS ubuntu versions
82-
-- add test for snapp file identification
89+
-- tox runner support
90+
-- remove deprecated test_suite field from setup.py
91+
-- docker tests that cover all LTS ubuntu versions
92+
-- add test for snapp file identification
8393

8494
- doc improvements
85-
-- document dependency install process for debian
86-
-- various typos
87-
-- document test running process
95+
-- document dependency install process for debian
96+
-- various typos
97+
-- document test running process

magic/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class Magic:
3939
"""
4040

4141
def __init__(self, mime=False, magic_file=None, mime_encoding=False,
42-
keep_going=False, uncompress=False, raw=False, extension=False):
42+
keep_going=False, uncompress=False, raw=False, extension=False,
43+
follow_symlinks=False):
4344
"""
4445
Create a new libmagic wrapper.
4546
@@ -65,6 +66,9 @@ def __init__(self, mime=False, magic_file=None, mime_encoding=False,
6566
if extension:
6667
self.flags |= MAGIC_EXTENSION
6768

69+
if follow_symlinks:
70+
self.flags |= MAGIC_SYMLINK
71+
6872
self.cookie = magic_open(self.flags)
6973
self.lock = threading.Lock()
7074

test/README

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
There are a few ways to run the python-magic tests
22

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

0 commit comments

Comments
 (0)