mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
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.
This commit is contained in:
parent
9cb37fc5d0
commit
971a012ce1
2 changed files with 7 additions and 2 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue