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.
This commit is contained in:
Brett Cannon 2009-03-09 03:35:50 +00:00
parent aa1c8d8899
commit 2a922ed6ad
9 changed files with 739 additions and 171 deletions

View file

@ -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