[Skencil-commits] r518 - in skencil/trunk: . Sketch/Modules test

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Sun Jan 29 20:56:22 CET 2006


Author: bh
Date: 2006-01-29 20:56:22 +0100 (Sun, 29 Jan 2006)
New Revision: 518

Modified:
   skencil/trunk/ChangeLog
   skencil/trunk/Sketch/Modules/skreadmodule.c
   skencil/trunk/test/ChangeLog
   skencil/trunk/test/test_skread.py
Log:

* Sketch/Modules/skreadmodule.c (sklex): Detect NUL-bytes after a
backslash (it might be the end of the data!)
(tokenize_line): Raise an SyntaxError when the tokenizer finds an
error

* test_skread.py (SKReadTest.test_tokenize_line_error_reporting)
(SKReadTest.test_incomplete_string_escapes): New tests for the
skread error handling changes


Modified: skencil/trunk/ChangeLog
===================================================================
--- skencil/trunk/ChangeLog	2006-01-29 19:13:58 UTC (rev 517)
+++ skencil/trunk/ChangeLog	2006-01-29 19:56:22 UTC (rev 518)
@@ -1,5 +1,12 @@
 2006-01-29  Bernhard Herzog  <bh at intevation.de>
 
+	* Sketch/Modules/skreadmodule.c (sklex): Detect NUL-bytes after a
+	backslash (it might be the end of the data!)
+	(tokenize_line): Raise an SyntaxError when the tokenizer finds an
+	error
+
+2006-01-29  Bernhard Herzog  <bh at intevation.de>
+
 	* Sketch/Modules/curveobject.c (curve_parse_string_append),
 	Sketch/Modules/skreadmodule.c (sklex),
 	Sketch/Modules/pstokenize.c (read_name_or_number): Set LC_NUMERIC

Modified: skencil/trunk/Sketch/Modules/skreadmodule.c
===================================================================
--- skencil/trunk/Sketch/Modules/skreadmodule.c	2006-01-29 19:13:58 UTC (rev 517)
+++ skencil/trunk/Sketch/Modules/skreadmodule.c	2006-01-29 19:56:22 UTC (rev 518)
@@ -190,6 +190,14 @@
 			    }
 			}
 			break;
+		    case '\0':
+			/* Either an embedded NUL or the end of the
+			 * data! */
+			Py_DECREF(*lval);
+			*lval = NULL;
+			buffer->error = "unexpected end of input";
+			return 0;
+			
 		    default:
 			/* copy the \ and character literally */
 			*dest++ = '\\';
@@ -618,6 +626,11 @@
 	    GET_TOKEN(&info);
     }
     info.value = NULL;
+    if (info.error)
+    {
+	PyErr_SetString(PyExc_SyntaxError, info.error);
+	goto fail;
+    }
 
     if (max_tokens == 0)
     {

Modified: skencil/trunk/test/ChangeLog
===================================================================
--- skencil/trunk/test/ChangeLog	2006-01-29 19:13:58 UTC (rev 517)
+++ skencil/trunk/test/ChangeLog	2006-01-29 19:56:22 UTC (rev 518)
@@ -1,3 +1,9 @@
+2006-01-29  Bernhard Herzog  <bh at intevation.de>
+
+	* test_skread.py (SKReadTest.test_tokenize_line_error_reporting)
+	(SKReadTest.test_incomplete_string_escapes): New tests for the
+	skread error handling changes
+
 2005-12-18  Bernhard Herzog  <bh at intevation.de>
 
 	* test_context.py: New.  Some tests for the context object.

Modified: skencil/trunk/test/test_skread.py
===================================================================
--- skencil/trunk/test/test_skread.py	2006-01-29 19:13:58 UTC (rev 517)
+++ skencil/trunk/test/test_skread.py	2006-01-29 19:56:22 UTC (rev 518)
@@ -1,5 +1,5 @@
 # Sketch - A Python-based interactive drawing program
-# Copyright (C) 2002 by Bernhard Herzog
+# Copyright (C) 2002, 2006 by Bernhard Herzog
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Library General Public
@@ -131,5 +131,16 @@
         eq(skread.tokenize_line("0+10.25-5.5,3.125, 8"),
            [0, 10.25, -5.5, 3.125, 8])
 
+    def test_tokenize_line_error_reporting(self):
+        """Test tokenize_line error reporting"""
+        # End of line in string literal
+        self.assertRaises(SyntaxError, skread.tokenize_line, '"\\"')
+
+    def test_incomplete_string_escapes(self):
+        """Test tokenize_line with incomplete \\-escapes in string literals"""
+        # backslash followed by a NUL-Byte
+        self.assertRaises(SyntaxError, skread.tokenize_line, '"\\\x00"')
+
+
 if __name__ == "__main__":
     unittest.main()



More information about the Skencil-commits mailing list