]> granicus.if.org Git - python/commitdiff
Better error message if ucnhash cannot be found (obscure attribute
authorFredrik Lundh <fredrik@pythonware.com>
Sat, 20 Jan 2001 11:15:25 +0000 (11:15 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Sat, 20 Jan 2001 11:15:25 +0000 (11:15 +0000)
errors aren't that helpful), or doesn't contain what's expected from
it.  Also tweaked the test script so it compiles even if ucnhash is
missing.

Lib/test/test_ucn.py
Objects/unicodeobject.c

index f680140f153ef7fc31f2dde2e9530ff7b608ae20..0797f2c79c5519ea86e65786e41300f86eb5620b 100644 (file)
@@ -10,6 +10,10 @@ from test_support import verify, verbose
 print 'Testing General Unicode Character Name, and case insensitivity...',
 
 # General and case insensitivity test:
+try:
+    # put all \N escapes inside exec'd raw strings, to make sure this
+    # script runs even if the compiler chokes on \N escapes
+    exec r"""
 s = u"\N{LATIN CAPITAL LETTER T}" \
     u"\N{LATIN SMALL LETTER H}" \
     u"\N{LATIN SMALL LETTER E}" \
@@ -37,6 +41,9 @@ s = u"\N{LATIN CAPITAL LETTER T}" \
     u"\N{LATIN SMALL LETTER P}" \
     u"\N{FULL STOP}"
 verify(s == u"The rEd fOx ate the sheep.", s)
+"""
+except UnicodeError, v:
+    print v
 print "done."
 
 import ucnhash
@@ -63,10 +70,12 @@ print "Found", count, "characters in the unicode name database"
 
 # misc. symbol testing
 print "Testing misc. symbols for unicode character name expansion....",
+exec r"""
 verify(u"\N{PILCROW SIGN}" == u"\u00b6")
 verify(u"\N{REPLACEMENT CHARACTER}" == u"\uFFFD")
 verify(u"\N{HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK}" == u"\uFF9F")
 verify(u"\N{FULLWIDTH LATIN SMALL LETTER A}" == u"\uFF41")
+"""
 print "done."
 
 
index a06c40b9d604f3d99c1d553d40c8b7ca95c8fd83..585afe6364739792c8372c64040d714969646dc8 100644 (file)
@@ -1240,15 +1240,15 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
                 PyObject *mod = 0, *v = 0;
                 mod = PyImport_ImportModule("ucnhash");
                 if (mod == NULL)
-                    goto onError;
+                    goto ucnhashError;
                 v = PyObject_GetAttrString(mod,"Unicode_Names_CAPI");
                 Py_DECREF(mod);
                 if (v == NULL)
-                    goto onError;
+                    goto ucnhashError;
                 unicode_names = PyCObject_AsVoidPtr(v);
                 Py_DECREF(v);
                 if (unicode_names == NULL)
-                    goto onError;
+                    goto ucnhashError;
             }
                 
             if (*s == '{') {
@@ -1311,6 +1311,11 @@ store:
                goto onError;
     return (PyObject *)v;
     
+ ucnhashError:
+    PyErr_SetString(PyExc_UnicodeError,
+                    "\\N escapes not supported (can't load ucnhash module)");
+    return NULL;
+
  onError:
     Py_XDECREF(v);
     return NULL;