]> granicus.if.org Git - python/commitdiff
Improve error messages for invalid warning arguments; don't raise
authorGuido van Rossum <guido@python.org>
Tue, 19 Dec 2000 03:04:50 +0000 (03:04 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 19 Dec 2000 03:04:50 +0000 (03:04 +0000)
exceptions but always print a warning message.

Lib/warnings.py

index 47eb19aa9fb400d7638caa4ab5127b715549f27b..a894bf2ee0ee3ebbba1f2d42da3d2c381e6ddd68 100644 (file)
@@ -167,14 +167,20 @@ def _getcategory(category):
     if re.match("^[a-zA-Z0-9_]+$", category):
         try:
             cat = eval(category)
-        except KeyError:
-            raise _OptionError("invalid warning category: %s" % `category`)
+        except NameError:
+            raise _OptionError("unknown warning category: %s" % `category`)
     else:
         i = category.rfind(".")
         module = category[:i]
         klass = category[i+1:]
-        m = __import__(module, None, None, [klass])
-        cat = getattr(m, klass)
+        try:
+            m = __import__(module, None, None, [klass])
+        except ImportError:
+            raise _OptionError("invalid module name: %s" % `module`)
+        try:
+            cat = getattr(m, klass)
+        except AttributeError:
+            raise _OptionError("unknown warning category: %s" % `category`)
     if (not isinstance(cat, types.ClassType) or
         not issubclass(cat, Warning)):
         raise _OptionError("invalid warning category: %s" % `category`)