diff --git a/CHANGELOG.md b/CHANGELOG.md index 56dbb3f..9a6fbba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.0.17 (2024-10-31) + +* Handle PermissionError in fallback code for old import name [#182](https://github.com/Kludex/python-multipart/pull/182). + ## 0.0.16 (2024-10-27) * Add dunder attributes to `multipart` package [#177](https://github.com/Kludex/python-multipart/pull/177). diff --git a/multipart/__init__.py b/multipart/__init__.py index cdc0154..67f0e5b 100644 --- a/multipart/__init__.py +++ b/multipart/__init__.py @@ -7,14 +7,17 @@ for p in sys.path: file_path = Path(p, "multipart.py") - if file_path.is_file(): - spec = importlib.util.spec_from_file_location("multipart", file_path) - assert spec is not None, f"{file_path} found but not loadable!" - module = importlib.util.module_from_spec(spec) - sys.modules["multipart"] = module - assert spec.loader is not None, f"{file_path} must be loadable!" - spec.loader.exec_module(module) - break + try: + if file_path.is_file(): + spec = importlib.util.spec_from_file_location("multipart", file_path) + assert spec is not None, f"{file_path} found but not loadable!" + module = importlib.util.module_from_spec(spec) + sys.modules["multipart"] = module + assert spec.loader is not None, f"{file_path} must be loadable!" + spec.loader.exec_module(module) + break + except PermissionError: + pass else: warnings.warn("Please use `import python_multipart` instead.", PendingDeprecationWarning, stacklevel=2) from python_multipart import * diff --git a/python_multipart/__init__.py b/python_multipart/__init__.py index a2d50d2..be8327f 100644 --- a/python_multipart/__init__.py +++ b/python_multipart/__init__.py @@ -2,7 +2,7 @@ __author__ = "Andrew Dunham" __license__ = "Apache" __copyright__ = "Copyright (c) 2012-2013, Andrew Dunham" -__version__ = "0.0.16" +__version__ = "0.0.17" from .multipart import ( BaseParser,