]> granicus.if.org Git - python/commitdiff
Fixed search function error reporting in the encodings package
authorMarc-André Lemburg <mal@egenix.com>
Wed, 19 Sep 2001 11:52:07 +0000 (11:52 +0000)
committerMarc-André Lemburg <mal@egenix.com>
Wed, 19 Sep 2001 11:52:07 +0000 (11:52 +0000)
__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.

Lib/encodings/__init__.py

index 51ec8732622d61767a84b4996c65f68a401227b1..3830954d16c79ea78a4d4935db6b4f9701ab5fe2 100644 (file)
@@ -28,11 +28,15 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
 
 """#"
 
-import codecs,aliases
+import codecs,aliases,exceptions
 
 _cache = {}
 _unknown = '--unknown--'
 
+class CodecRegistryError(exceptions.LookupError,
+                         exceptions.SystemError):
+    pass
+
 def search_function(encoding):
     
     # Cache lookup
@@ -56,14 +60,14 @@ def search_function(encoding):
     except AttributeError:
         entry = ()
     if len(entry) != 4:
-        raise SystemError,\
-              'module "%s.%s" failed to register' % \
-              (__name__,modname)
+        raise CodecRegistryError,\
+              'module "%s" (%s) failed to register' % \
+              (mod.__name__, mod.__file__)
     for obj in entry:
         if not callable(obj):
-            raise SystemError,\
-                  'incompatible codecs in module "%s.%s"' % \
-                  (__name__,modname)
+            raise CodecRegistryError,\
+                  'incompatible codecs in module "%s" (%s)' % \
+                  (mod.__name__, mod.__file__)
 
     # Cache the codec registry entry
     _cache[encoding] = entry