[Python-3000-checkins] r59062 - in python/branches/py3k: Lib/test/test_csv.py Modules/_csv.c

amaury.forgeotdarc python-3000-checkins at python.org
Mon Nov 19 22:20:22 CET 2007


Author: amaury.forgeotdarc
Date: Mon Nov 19 22:20:21 2007
New Revision: 59062

Modified:
   python/branches/py3k/Lib/test/test_csv.py
   python/branches/py3k/Modules/_csv.c
Log:
Correct test_cvs on Windows, as suggested by Raghuram Devarakonda
in issue1395. All other places in this file already use newline=''...

Also check that csv.reader is given an iterable returning strings.


Modified: python/branches/py3k/Lib/test/test_csv.py
==============================================================================
--- python/branches/py3k/Lib/test/test_csv.py	(original)
+++ python/branches/py3k/Lib/test/test_csv.py	Mon Nov 19 22:20:21 2007
@@ -6,7 +6,7 @@
 import sys
 import os
 import unittest
-from io import StringIO
+from io import StringIO, BytesIO
 from tempfile import TemporaryFile
 import csv
 import gc
@@ -211,6 +211,10 @@
                           ['ab\0c'], None, strict = 1)
         self._read_test(['"ab"c'], [['abc']], doublequote = 0)
 
+        self.assertRaises(csv.Error, self._read_test,
+                          [b'ab\0c'], None)
+
+
     def test_read_eol(self):
         self._read_test(['a,b'], [['a','b']])
         self._read_test(['a,b\n'], [['a','b']])
@@ -375,7 +379,7 @@
 
 class TestCsvBase(unittest.TestCase):
     def readerAssertEqual(self, input, expected_result):
-        with TemporaryFile("w+") as fileobj:
+        with TemporaryFile("w+", newline='') as fileobj:
             fileobj.write(input)
             fileobj.seek(0)
             reader = csv.reader(fileobj, dialect = self.dialect)

Modified: python/branches/py3k/Modules/_csv.c
==============================================================================
--- python/branches/py3k/Modules/_csv.c	(original)
+++ python/branches/py3k/Modules/_csv.c	Mon Nov 19 22:20:21 2007
@@ -270,7 +270,7 @@
 			*target = NULL;
 		else if (!IS_BASESTRING(src)) {
 			PyErr_Format(PyExc_TypeError, 
-				     "\"%s\" must be an string", name);
+				     "\"%s\" must be a string", name);
 			return -1;
 		}
 		else {
@@ -793,6 +793,16 @@
 					     "newline inside string");
                         return NULL;
                 }
+		if (!PyUnicode_Check(lineobj))
+		{
+			PyErr_Format(error_obj,
+				     "Iterator should return strings, "
+				     "not %.200s "
+				     "(did you open the file in text mode?)",
+				     lineobj->ob_type->tp_name
+				);
+			return NULL;
+		}
                 ++self->line_num;
                 line = PyUnicode_AsUnicode(lineobj);
                 linelen = PyUnicode_GetSize(lineobj);


More information about the Python-3000-checkins mailing list