Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9e0764

Browse files
committed
Revert #571603 since it is ok to import codecs that are not subdirectories
of encodings. Skip modules that don't have a getregentry function.
1 parent a290527 commit b9e0764

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

Lib/encodings/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,27 @@ def search_function(encoding):
5555
try:
5656
mod = __import__('encodings.' + modname,
5757
globals(), locals(), _import_tail)
58-
except ImportError,why:
58+
except ImportError:
5959
import aliases
6060
modname = aliases.aliases.get(modname, modname)
6161
try:
62-
mod = __import__('encodings.' + modname, globals(), locals(), _import_tail)
63-
except ImportError,why:
62+
mod = __import__(modname, globals(), locals(), _import_tail)
63+
except ImportError:
6464
mod = None
65+
66+
try:
67+
getregentry = mod.getregentry
68+
except AttributeError:
69+
# Not a codec module
70+
mod = None
71+
6572
if mod is None:
6673
# Cache misses
6774
_cache[encoding] = None
68-
return None
69-
75+
return None
7076

7177
# Now ask the module for the registry entry
72-
try:
73-
entry = tuple(mod.getregentry())
74-
except AttributeError:
75-
entry = ()
78+
entry = tuple(getregentry())
7679
if len(entry) != 4:
7780
raise CodecRegistryError,\
7881
'module "%s" (%s) failed to register' % \

0 commit comments

Comments
 (0)