summaryrefslogtreecommitdiffstats
path: root/Lib/encodings
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-02-15 22:54:39 (GMT)
committerBrett Cannon <bcannon@gmail.com>2007-02-15 22:54:39 (GMT)
commit971a012ce178d1b50b272bc035bfcc795e73c781 (patch)
treebb3651debb9a00d817847dafc90cceea24b0bc4f /Lib/encodings
parent9cb37fc5d02564b618aceb90d0f51dd56b1b505b (diff)
downloadcpython-971a012ce178d1b50b272bc035bfcc795e73c781.zip
cpython-971a012ce178d1b50b272bc035bfcc795e73c781.tar.gz
cpython-971a012ce178d1b50b272bc035bfcc795e73c781.tar.bz2
Update the encoding package's search function to use absolute imports when
calling __import__. This helps make the expected search locations for encoding modules be more explicit. One could use an explicit value for __path__ when making the call to __import__ to force the exact location searched for encodings. This would give the most strict search path possible if one is worried about malicious code being imported. The unfortunate side-effect of that is that if __path__ was modified on 'encodings' on purpose in a safe way it would not be picked up in future __import__ calls.
Diffstat (limited to 'Lib/encodings')
-rw-r--r--Lib/encodings/__init__.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py
index 6cf6089..190b3c4 100644
--- a/Lib/encodings/__init__.py
+++ b/Lib/encodings/__init__.py
@@ -93,8 +93,10 @@ def search_function(encoding):
if not modname or '.' in modname:
continue
try:
- mod = __import__('encodings.' + modname,
- globals(), locals(), _import_tail)
+ # Import equivalent to `` from .modname import *``.
+ # '*' is used so that __import__ returns the desired module and not
+ # 'encodings' itself.
+ mod = __import__(modname, globals(), locals(), ['*'], 1)
except ImportError:
pass
else: