Skip to content

Commit ff42d76

Browse files
author
Ralf Schlatterbeck
committed
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
1 parent 2ce6917 commit ff42d76

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

roundup/anypy/io_.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
try:
3-
from io import StringIO
3+
from io import StringIO, BytesIO
44
except:
55
from StringIO import StringIO
6+
BytesIO = StringIO
67

roundup/cgi/actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def handle(self):
297297
props = ['id'] + props_without_id
298298

299299
# do the edit
300-
rows = io_.StringIO(self.form['rows'].value)
300+
rows = io_.BytesIO(self.form['rows'].value)
301301
reader = csv.reader(rows)
302302
found = {}
303303
line = 0

test/test_cgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,22 @@ def testSearchPermission(self):
878878
h = HTMLRequest(cl)
879879
self.assertEqual([x.id for x in h.batch()],['1', '2', '3'])
880880

881+
def testEditCSV(self):
882+
form = dict(rows='id,name\n1,newkey')
883+
cl = self._make_client(form, userid='1', classname='keyword')
884+
cl.ok_message = []
885+
actions.EditCSVAction(cl).handle()
886+
self.assertEqual(cl.ok_message, ['Items edited OK'])
887+
k = self.db.keyword.getnode('1')
888+
self.assertEqual(k.name, 'newkey')
889+
form = dict(rows=u'id,name\n1,\xe4\xf6\xfc'.encode('utf-8'))
890+
cl = self._make_client(form, userid='1', classname='keyword')
891+
cl.ok_message = []
892+
actions.EditCSVAction(cl).handle()
893+
self.assertEqual(cl.ok_message, ['Items edited OK'])
894+
k = self.db.keyword.getnode('1')
895+
self.assertEqual(k.name, u'\xe4\xf6\xfc'.encode('utf-8'))
896+
881897
def testRoles(self):
882898
cl = self._make_client({})
883899
self.db.user.set('1', roles='aDmin, uSer')

0 commit comments

Comments
 (0)