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

Skip to content

Commit 816a1b7

Browse files
committed
Fixed search function error reporting in the encodings package
__init__.py module to raise errors which can be catched as LookupErrors as well as SystemErrors. Modified the error messages to include more information about the failing module.
1 parent 494f2ae commit 816a1b7

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Lib/encodings/__init__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@
2828
2929
"""#"
3030

31-
import codecs,aliases
31+
import codecs,aliases,exceptions
3232

3333
_cache = {}
3434
_unknown = '--unknown--'
3535

36+
class CodecRegistryError(exceptions.LookupError,
37+
exceptions.SystemError):
38+
pass
39+
3640
def search_function(encoding):
3741

3842
# Cache lookup
@@ -56,14 +60,14 @@ def search_function(encoding):
5660
except AttributeError:
5761
entry = ()
5862
if len(entry) != 4:
59-
raise SystemError,\
60-
'module "%s.%s" failed to register' % \
61-
(__name__,modname)
63+
raise CodecRegistryError,\
64+
'module "%s" (%s) failed to register' % \
65+
(mod.__name__, mod.__file__)
6266
for obj in entry:
6367
if not callable(obj):
64-
raise SystemError,\
65-
'incompatible codecs in module "%s.%s"' % \
66-
(__name__,modname)
68+
raise CodecRegistryError,\
69+
'incompatible codecs in module "%s" (%s)' % \
70+
(mod.__name__, mod.__file__)
6771

6872
# Cache the codec registry entry
6973
_cache[encoding] = entry

0 commit comments

Comments
 (0)