summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/test/source/util.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-03-09 03:35:50 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-03-09 03:35:50 (GMT)
commit2a922ed6adf28fabd10cb852133be5aeeb906aa5 (patch)
tree233b1352e48970174dade4ca795d853b8cc6e501 /Lib/importlib/test/source/util.py
parentaa1c8d88992d482f90268f2352fccb6e74d87279 (diff)
downloadcpython-2a922ed6adf28fabd10cb852133be5aeeb906aa5.zip
cpython-2a922ed6adf28fabd10cb852133be5aeeb906aa5.tar.gz
cpython-2a922ed6adf28fabd10cb852133be5aeeb906aa5.tar.bz2
Introduce importlib.abc. The module contains various ABCs related to imports
(mostly stuff specified by PEP 302). There are two ABCs, PyLoader and PyPycLoader, which help with implementing source and source/bytecode loaders by implementing load_module in terms of other methods. This removes a lot of gritty details loaders typically have to worry about.
Diffstat (limited to 'Lib/importlib/test/source/util.py')
-rw-r--r--Lib/importlib/test/source/util.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/importlib/test/source/util.py b/Lib/importlib/test/source/util.py
index f02d491..280edb4 100644
--- a/Lib/importlib/test/source/util.py
+++ b/Lib/importlib/test/source/util.py
@@ -1,5 +1,6 @@
from .. import util
import contextlib
+import functools
import imp
import os
import os.path
@@ -9,11 +10,24 @@ from test import support
def writes_bytecode(fxn):
+ """Decorator to protect sys.dont_write_bytecode from mutation."""
+ @functools.wraps(fxn)
+ def wrapper(*args, **kwargs):
+ original = sys.dont_write_bytecode
+ sys.dont_write_bytecode = False
+ to_return = fxn(*args, **kwargs)
+ sys.dont_write_bytecode = original
+ return to_return
+ return wrapper
+
+
+def writes_bytecode_files(fxn):
"""Decorator that returns the function if writing bytecode is enabled, else
a stub function that accepts anything and simply returns None."""
if sys.dont_write_bytecode:
return lambda *args, **kwargs: None
else:
+ @functools.wraps(fxn)
def wrapper(*args, **kwargs):
to_return = fxn(*args, **kwargs)
sys.dont_write_bytecode = False