From 20b39defda9bb97ac33f3de25558d76187f2b584 Mon Sep 17 00:00:00 2001 From: schlatterbeck Date: Fri, 15 Jul 2011 12:36:47 +0000 Subject: [PATCH] - Fix StringIO issue2550713: io.StringIO in newer versions of python returns unicode strings and expects a unicode string in the constructor. Unfortunately csv doesn't handle unicode (yet). So we need to use a BytesIO which gets the utf-8 string from the web-interface. Compatibility for old versions by using Stringio.Stringio for emulating a io.BytesIO also works. - We didn't have a regression test for the EditCSVAction git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4633 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/anypy/io_.py | 3 ++- roundup/cgi/actions.py | 2 +- test/test_cgi.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/roundup/anypy/io_.py b/roundup/anypy/io_.py index 86f8023..5d6e52e 100644 --- a/roundup/anypy/io_.py +++ b/roundup/anypy/io_.py @@ -1,6 +1,7 @@ try: - from io import StringIO + from io import StringIO, BytesIO except: from StringIO import StringIO + BytesIO = StringIO diff --git a/roundup/cgi/actions.py b/roundup/cgi/actions.py index d48fb59..86bd4f1 100755 --- a/roundup/cgi/actions.py +++ b/roundup/cgi/actions.py @@ -297,7 +297,7 @@ class EditCSVAction(Action): props = ['id'] + props_without_id # do the edit - rows = io_.StringIO(self.form['rows'].value) + rows = io_.BytesIO(self.form['rows'].value) reader = csv.reader(rows) found = {} line = 0 diff --git a/test/test_cgi.py b/test/test_cgi.py index 7fbe89c..c99d9e8 100644 --- a/test/test_cgi.py +++ b/test/test_cgi.py @@ -878,6 +878,22 @@ class FormTestCase(unittest.TestCase): h = HTMLRequest(cl) self.assertEqual([x.id for x in h.batch()],['1', '2', '3']) + def testEditCSV(self): + form = dict(rows='id,name\n1,newkey') + cl = self._make_client(form, userid='1', classname='keyword') + cl.ok_message = [] + actions.EditCSVAction(cl).handle() + self.assertEqual(cl.ok_message, ['Items edited OK']) + k = self.db.keyword.getnode('1') + self.assertEqual(k.name, 'newkey') + form = dict(rows=u'id,name\n1,\xe4\xf6\xfc'.encode('utf-8')) + cl = self._make_client(form, userid='1', classname='keyword') + cl.ok_message = [] + actions.EditCSVAction(cl).handle() + self.assertEqual(cl.ok_message, ['Items edited OK']) + k = self.db.keyword.getnode('1') + self.assertEqual(k.name, u'\xe4\xf6\xfc'.encode('utf-8')) + def testRoles(self): cl = self._make_client({}) self.db.user.set('1', roles='aDmin, uSer') -- 2.30.2