mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Corrected import behaviour for codecs which live outside the encodings
package.
This commit is contained in:
parent
f2f219daa2
commit
a0af63b242
2 changed files with 12 additions and 17 deletions
|
@ -4,8 +4,8 @@
|
|||
directory.
|
||||
|
||||
Codec modules must have names corresponding to standard lower-case
|
||||
encoding names with hyphens and periods mapped to underscores,
|
||||
e.g. 'utf-8' is implemented by the module 'utf_8.py'.
|
||||
encoding names with hyphens mapped to underscores, e.g. 'utf-8' is
|
||||
implemented by the module 'utf_8.py'.
|
||||
|
||||
Each codec module must export the following interface:
|
||||
|
||||
|
@ -52,23 +52,18 @@ def search_function(encoding):
|
|||
# default import module lookup scheme with the alias name.
|
||||
#
|
||||
modname = encoding.replace('-', '_')
|
||||
modname = modname.replace('.', '_')
|
||||
try:
|
||||
mod = __import__('encodings.' + modname,
|
||||
globals(), locals(), _import_tail)
|
||||
except ImportError,why:
|
||||
import aliases
|
||||
modname = aliases.aliases.get(modname, _unknown)
|
||||
if modname is not _unknown:
|
||||
try:
|
||||
mod = __import__(modname,
|
||||
globals(), locals(), _import_tail)
|
||||
except ImportError,why:
|
||||
mod = None
|
||||
else:
|
||||
modname = aliases.aliases.get(modname, modname)
|
||||
try:
|
||||
mod = __import__(modname, globals(), locals(), _import_tail)
|
||||
except ImportError,why:
|
||||
mod = None
|
||||
if mod is None:
|
||||
# cache misses
|
||||
# Cache misses
|
||||
_cache[encoding] = None
|
||||
return None
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
map encodings names to module names.
|
||||
|
||||
Note that the search function converts the encoding names to lower
|
||||
case and replaces hyphens and periods with underscores *before*
|
||||
performing the lookup.
|
||||
case and replaces hyphens with underscores *before* performing the
|
||||
lookup.
|
||||
|
||||
Contents:
|
||||
|
||||
|
@ -25,13 +25,13 @@ aliases = {
|
|||
|
||||
# ascii codec
|
||||
'646' : 'ascii',
|
||||
'ansi_x3_4_1968' : 'ascii',
|
||||
'ansi_x3_4_1986' : 'ascii',
|
||||
'ansi_x3.4_1968' : 'ascii',
|
||||
'ansi_x3.4_1986' : 'ascii',
|
||||
'cp367' : 'ascii',
|
||||
'csascii' : 'ascii',
|
||||
'ibm367' : 'ascii',
|
||||
'iso646_us' : 'ascii',
|
||||
'iso_646_irv:1991' : 'ascii',
|
||||
'iso_646.irv:1991' : 'ascii',
|
||||
'iso_ir_6' : 'ascii',
|
||||
'us' : 'ascii',
|
||||
'us_ascii' : 'ascii',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue