Revert #571603 since it is ok to import codecs that are not subdirectories

of encodings. Skip modules that don't have a getregentry function.
This commit is contained in:
Martin v. Löwis 2002-07-29 14:05:24 +00:00
parent a290527376
commit b9e0764d8b
1 changed files with 12 additions and 9 deletions

View File

@ -55,24 +55,27 @@ def search_function(encoding):
try: try:
mod = __import__('encodings.' + modname, mod = __import__('encodings.' + modname,
globals(), locals(), _import_tail) globals(), locals(), _import_tail)
except ImportError,why: except ImportError:
import aliases import aliases
modname = aliases.aliases.get(modname, modname) modname = aliases.aliases.get(modname, modname)
try: try:
mod = __import__('encodings.' + modname, globals(), locals(), _import_tail) mod = __import__(modname, globals(), locals(), _import_tail)
except ImportError,why: except ImportError:
mod = None mod = None
try:
getregentry = mod.getregentry
except AttributeError:
# Not a codec module
mod = None
if mod is None: if mod is None:
# Cache misses # Cache misses
_cache[encoding] = None _cache[encoding] = None
return None return None
# Now ask the module for the registry entry # Now ask the module for the registry entry
try: entry = tuple(getregentry())
entry = tuple(mod.getregentry())
except AttributeError:
entry = ()
if len(entry) != 4: if len(entry) != 4:
raise CodecRegistryError,\ raise CodecRegistryError,\
'module "%s" (%s) failed to register' % \ 'module "%s" (%s) failed to register' % \