summaryrefslogtreecommitdiff
path: root/debian/patches/0003-give-lxml-etree-BytesIO-in-Python-3.patch
blob: 32746fd7e0c3461b0acea426b394d8434fc6ea32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
From 351c51b882bf00d1db03de5a2419372e2e31d6cf Mon Sep 17 00:00:00 2001
From: Carl Suster <carl@contraflo.ws>
Date: Wed, 11 Jan 2017 22:34:34 +1100
Subject: give lxml etree BytesIO in Python 3

The lxml etree API changed in Python 3 to take BytesIO instead of
StringIO. This patch maintains the original behaviour in Python 2 but
switches to BytesIO in Python 3, decoding the XML data as UTF-8.
---
 pynzb/lxml_nzb.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/pynzb/lxml_nzb.py b/pynzb/lxml_nzb.py
index 790671d..9d76c4a 100644
--- a/pynzb/lxml_nzb.py
+++ b/pynzb/lxml_nzb.py
@@ -6,11 +6,17 @@ except ImportError:
     raise ImportError("You must have lxml installed before you can use the " +
         "lxml NZB parser.")
 
-try:
-    from cStringIO import StringIO
-except ImportError:
-    from StringIO import StringIO
+import sys
+if sys.version_info.major < 3:
+    try:
+        from cStringIO import StringIO
+    except ImportError:
+        from StringIO import StringIO
+    def as_io(xml): return StringIO(xml)
+else:
+    from BytesIO import BytesIO
+    def as_io(xml): return BytesIO(bytes(xml, 'utf-8'))
 
 class LXMLNZBParser(BaseETreeNZBParser):
     def get_etree_iter(self, xml, et=etree):
-        return iter(et.iterparse(StringIO(xml), events=("start", "end")))
\ No newline at end of file
+        return iter(et.iterparse(as_io(xml), events=("start", "end")))