[Python-checkins] r53628 - sandbox/trunk/import_in_py/controlled_importlib.py
brett.cannon
python-checkins at python.org
Sat Feb 3 23:05:24 CET 2007
Author: brett.cannon
Date: Sat Feb 3 23:05:21 2007
New Revision: 53628
Modified:
sandbox/trunk/import_in_py/controlled_importlib.py
Log:
Prep the 'sys' module more in ControlledImport.__init__. Also provide default
arguments.
Modified: sandbox/trunk/import_in_py/controlled_importlib.py
==============================================================================
--- sandbox/trunk/import_in_py/controlled_importlib.py (original)
+++ sandbox/trunk/import_in_py/controlled_importlib.py Sat Feb 3 23:05:21 2007
@@ -64,14 +64,18 @@
"""Represent a controllable version of import that allows for more
fine-grained control over what can and cannot be imported."""
- def __init__(self, safe_builtins, safe_frozen, safe_extensions):
+ def __init__(self, safe_builtins=(), safe_frozen=(), safe_extensions=()):
"""Set up importation where built-in, frozen, and extension modules
must be whitelisted and .pyc files are completely blocked
while all. py files are allowed."""
+ importlib.Import.__init__(self, (), ())
# Clear out any traces of the previous import machinery.
sys.path_importer_cache.clear()
+ sys.meta_path = []
+ sys.path_hooks = []
# Whitelist built-in and frozen modules on sys.meta_path.
- # XXX
+ sys.meta_path.append(WhitelistBuiltin(safe_builtins))
+ sys.meta_path.append(WhitelistFrozen(safe_frozen))
# Whitelist extension modules on sys.path.
# XXX
# Allow all .py files but not .pyc files on sys.path.
More information about the Python-checkins
mailing list