Skip to content

Commit

Permalink
- Prevent deprecation warning by using importlib (fixes #24)
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Apr 7, 2019
1 parent 14351bf commit 407a550
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
4.5 (unreleased)
----------------

- Prevent deprecation warning by using ``importlib`` instead of ``imp``
(`#24 <https://github.com/zopefoundation/Products.PythonScripts/issues/24>`_)

- Prevent syntax warning due to outdated default script content
(`#26 <https://github.com/zopefoundation/Products.PythonScripts/issues/26>`_)

Expand Down
11 changes: 8 additions & 3 deletions src/Products/PythonScripts/PythonScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Python code.
"""

import imp # NOQA
import marshal
import os
import re
Expand Down Expand Up @@ -54,8 +53,14 @@
LOG = getLogger('PythonScripts')

# Track the Python bytecode version
Python_magic = imp.get_magic()
del imp
try:
import importlib.util
Python_magic = importlib.util.MAGIC_NUMBER
del importlib.util
except ImportError: # Python 2
import imp
Python_magic = imp.get_magic()
del imp

# This should only be incremented to force recompilation.
Script_magic = 4
Expand Down

0 comments on commit 407a550

Please sign in to comment.