Merge lp:~ceronman/txsolr/xml-input-encoding-867786 into lp:txsolr

Proposed by Manuel Cerón
Status: Merged
Merged at revision: 60
Proposed branch: lp:~ceronman/txsolr/xml-input-encoding-867786
Merge into: lp:txsolr
Diff against target: 58 lines (+21/-2)
2 files modified
txsolr/input.py (+2/-2)
txsolr/test/test_input.py (+19/-0)
To merge this branch: bzr merge lp:~ceronman/txsolr/xml-input-encoding-867786
Reviewer Review Type Date Requested Status
Nicholas Tollervey (community) Approve
Esteve Fernandez (community) Approve
Review via email: mp+78149@code.launchpad.net

Description of the change

This branch introduces the following changes:

 - The XML Input encoder now forces UTF-8 encoding when generating XML documents. This prevents unicode errors in Python 2.6.

To post a comment you must log in.
Revision history for this message
Esteve Fernandez (esteve) wrote :

+1 LGTM

review: Approve
Revision history for this message
Nicholas Tollervey (ntoll) wrote :

+1 LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txsolr/input.py'
2--- txsolr/input.py 2010-10-14 10:58:34 +0000
3+++ txsolr/input.py 2011-10-04 19:05:24 +0000
4@@ -127,7 +127,7 @@
5 docElement.append(fieldElement)
6 addElement.append(docElement)
7
8- result = ElementTree.tostring(addElement)
9+ result = ElementTree.tostring(addElement, encoding='utf-8')
10 return StringProducer(result)
11
12 def createDelete(self, id):
13@@ -143,7 +143,7 @@
14 idElement.text = self._encodeValue(id)
15 deleteElement.append(idElement)
16
17- result = ElementTree.tostring(deleteElement)
18+ result = ElementTree.tostring(deleteElement, encoding='utf-8')
19 return StringProducer(result)
20
21 def createDeleteByQuery(self, query):
22
23=== modified file 'txsolr/test/test_input.py'
24--- txsolr/test/test_input.py 2011-05-24 02:26:43 +0000
25+++ txsolr/test/test_input.py 2011-10-04 19:05:24 +0000
26@@ -56,6 +56,16 @@
27 input = self.input.createAdd(document).body
28 self.assertEqual(input, expected, 'Wrong input')
29
30+ def testCreateAddEncoding(self):
31+ """
32+ L{SimpleXMLInputFactory.createAdd} encodes the C{add} request as UTF-8.
33+ """
34+ document = {'id': 1, 'text': u'\U0001d1b6'}
35+ expected = ('<add><doc><field name="text">\xf0\x9d\x86\xb6</field>'
36+ '<field name="id">1</field></doc></add>')
37+ input = self.input.createAdd(document).body
38+ self.assertEqual(input, expected, 'Wrong input')
39+
40 def testCreateAddWithCollection(self):
41 """
42 L{SimpleXMLInputFactory.createAdd} creates a correct body for an C{add}
43@@ -111,6 +121,15 @@
44 expected = '<delete><id>123</id></delete>'
45 self.assertEqual(self.input.createDelete(id).body, expected)
46
47+ def testCreateDeleteEncoding(self):
48+ """
49+ L{SimpleXMLInputFactory.createDelete} encodes a C{delete} request as
50+ UTF-8.
51+ """
52+ id = u'\U0001d1b6'
53+ expected = '<delete><id>\xf0\x9d\x86\xb6</id></delete>'
54+ self.assertEqual(self.input.createDelete(id).body, expected)
55+
56 def testCreateDeleteWithEncoding(self):
57 """
58 L{SimpleXMLInputFactory.createDelete} correctly escapes XML special

Subscribers

People subscribed via source and target branches

to all changes: