[Python-checkins] cpython: Issue #19448: report name / NID in exception message of ASN1Object

christian.heimes python-checkins at python.org
Fri Nov 22 16:21:04 CET 2013


http://hg.python.org/cpython/rev/7d914d4b05fe
changeset:   87344:7d914d4b05fe
user:        Christian Heimes <christian at cheimes.de>
date:        Fri Nov 22 16:20:53 2013 +0100
summary:
  Issue #19448: report name / NID in exception message of ASN1Object

files:
  Lib/test/test_ssl.py |  6 ++++--
  Modules/_ssl.c       |  6 +++---
  2 files changed, 7 insertions(+), 5 deletions(-)


diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -585,7 +585,8 @@
         self.assertEqual(val, expected)
         self.assertIsInstance(val, ssl._ASN1Object)
         self.assertRaises(ValueError, ssl._ASN1Object.fromnid, -1)
-        self.assertRaises(ValueError, ssl._ASN1Object.fromnid, 100000)
+        with self.assertRaisesRegex(ValueError, "unknown NID 100000"):
+            ssl._ASN1Object.fromnid(100000)
         for i in range(1000):
             try:
                 obj = ssl._ASN1Object.fromnid(i)
@@ -603,7 +604,8 @@
         self.assertEqual(ssl._ASN1Object.fromname('serverAuth'), expected)
         self.assertEqual(ssl._ASN1Object.fromname('1.3.6.1.5.5.7.3.1'),
                          expected)
-        self.assertRaises(ValueError, ssl._ASN1Object.fromname, 'serverauth')
+        with self.assertRaisesRegex(ValueError, "unknown object 'serverauth'"):
+            ssl._ASN1Object.fromname('serverauth')
 
 
 class ContextTests(unittest.TestCase):
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -3387,7 +3387,7 @@
     }
     obj = OBJ_txt2obj(txt, name ? 0 : 1);
     if (obj == NULL) {
-        PyErr_Format(PyExc_ValueError, "Unknown object");
+        PyErr_Format(PyExc_ValueError, "unknown object '%.100s'", txt);
         return NULL;
     }
     result = asn1obj2py(obj);
@@ -3411,12 +3411,12 @@
         return NULL;
     }
     if (nid < NID_undef) {
-        PyErr_Format(PyExc_ValueError, "NID must be positive.");
+        PyErr_SetString(PyExc_ValueError, "NID must be positive.");
         return NULL;
     }
     obj = OBJ_nid2obj(nid);
     if (obj == NULL) {
-        PyErr_Format(PyExc_ValueError, "Unknown NID");
+        PyErr_Format(PyExc_ValueError, "unknown NID %i", nid);
         return NULL;
     }
     result = asn1obj2py(obj);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list