[Python-3000-checkins] r56442 - in python/branches/p3yk: Doc/lib/libnis.tex Lib/test/test_parser.py Python/ast.c

guido.van.rossum python-3000-checkins at python.org
Wed Jul 18 19:26:38 CEST 2007


Author: guido.van.rossum
Date: Wed Jul 18 19:26:38 2007
New Revision: 56442

Modified:
   python/branches/p3yk/Doc/lib/libnis.tex
   python/branches/p3yk/Lib/test/test_parser.py
   python/branches/p3yk/Python/ast.c
Log:
Merged revisions 56413-56441 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r56439 | georg.brandl | 2007-07-17 23:37:55 -0700 (Tue, 17 Jul 2007) | 2 lines
  
  Use "Unix" as platform name, not "UNIX".
........
  r56441 | guido.van.rossum | 2007-07-18 10:19:14 -0700 (Wed, 18 Jul 2007) | 3 lines
  
  SF patch# 1755885 by Kurt Kaiser: show location of Unicode escape errors.
  (Slightly tweaked for style and refcounts.)
........


Modified: python/branches/p3yk/Doc/lib/libnis.tex
==============================================================================
--- python/branches/p3yk/Doc/lib/libnis.tex	(original)
+++ python/branches/p3yk/Doc/lib/libnis.tex	Wed Jul 18 19:26:38 2007
@@ -2,7 +2,7 @@
          Interface to Sun's NIS (Yellow Pages)}
 
 \declaremodule{extension}{nis}
-  \platform{UNIX}
+  \platform{Unix}
 \moduleauthor{Fred Gansevles}{Fred.Gansevles at cs.utwente.nl}
 \sectionauthor{Moshe Zadka}{moshez at zadka.site.co.il}
 \modulesynopsis{Interface to Sun's NIS (Yellow Pages) library.}

Modified: python/branches/p3yk/Lib/test/test_parser.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_parser.py	(original)
+++ python/branches/p3yk/Lib/test/test_parser.py	Wed Jul 18 19:26:38 2007
@@ -443,6 +443,12 @@
         st = parser.suite('1 = 3 + 4')
         self.assertRaises(SyntaxError, parser.compilest, st)
 
+    def test_compile_badunicode(self):
+        st = parser.suite('a = u"\U12345678"')
+        self.assertRaises(SyntaxError, parser.compilest, st)
+        st = parser.suite('a = u"\u1"')
+        self.assertRaises(SyntaxError, parser.compilest, st)
+
 def test_main():
     test_support.run_unittest(
         RoundtripLegalSyntaxTestCase,

Modified: python/branches/p3yk/Python/ast.c
==============================================================================
--- python/branches/p3yk/Python/ast.c	(original)
+++ python/branches/p3yk/Python/ast.c	Wed Jul 18 19:26:38 2007
@@ -1297,9 +1297,26 @@
         return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), n->n_col_offset, c->c_arena);
     case STRING: {
         PyObject *str = parsestrplus(c, n, &bytesmode);
-        if (!str)
+        if (!str) {
+            if (PyErr_ExceptionMatches(PyExc_UnicodeError)){
+                PyObject *type, *value, *tback, *errstr;
+                PyErr_Fetch(&type, &value, &tback);
+                errstr = ((PyUnicodeErrorObject *)value)->reason;
+                if (errstr) {
+                    char *s = "";
+                    char buf[128];
+                    s = PyString_AsString(errstr);
+                    PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s);
+                    ast_error(n, buf);
+                } else {
+                    ast_error(n, "(unicode error) unknown error");
+                }
+                Py_DECREF(type);
+                Py_DECREF(value);
+                Py_XDECREF(tback);
+            }
             return NULL;
-
+        }
         PyArena_AddPyObject(c->c_arena, str);
         if (bytesmode)
             return Bytes(str, LINENO(n), n->n_col_offset, c->c_arena);


More information about the Python-3000-checkins mailing list