summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/.git-dpm4
-rw-r--r--debian/patches/0003-give-lxml-etree-BytesIO-in-Python-3.patch40
-rw-r--r--debian/patches/series1
-rw-r--r--pynzb/lxml_nzb.py16
4 files changed, 54 insertions, 7 deletions
diff --git a/debian/.git-dpm b/debian/.git-dpm
index f563988..e8ed9aa 100644
--- a/debian/.git-dpm
+++ b/debian/.git-dpm
@@ -1,6 +1,6 @@
# see git-dpm(1) from git-dpm package
-01027917584eafdf4228bf0590123dfd47fe14a8
-01027917584eafdf4228bf0590123dfd47fe14a8
+5bb9aae805947e77215ff8c433d52a987dbf75a0
+5bb9aae805947e77215ff8c433d52a987dbf75a0
124074ce42e5d83c71e028a8757afb392cc96548
124074ce42e5d83c71e028a8757afb392cc96548
python-pynzb_0.1.0.orig.tar.gz
diff --git a/debian/patches/0003-give-lxml-etree-BytesIO-in-Python-3.patch b/debian/patches/0003-give-lxml-etree-BytesIO-in-Python-3.patch
new file mode 100644
index 0000000..0f86fce
--- /dev/null
+++ b/debian/patches/0003-give-lxml-etree-BytesIO-in-Python-3.patch
@@ -0,0 +1,40 @@
+From 5bb9aae805947e77215ff8c433d52a987dbf75a0 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..b1d0dc6 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 io(xml): return StringIO(xml)
++else:
++ from BytesIO import BytesIO
++ def 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(io(xml), events=("start", "end")))
diff --git a/debian/patches/series b/debian/patches/series
index 14592c9..37dcf18 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,3 @@
0001-set-message_id-properly-in-expat-parser.patch
0002-enable-use_2to3-in-setup.py.patch
+0003-give-lxml-etree-BytesIO-in-Python-3.patch
diff --git a/pynzb/lxml_nzb.py b/pynzb/lxml_nzb.py
index 790671d..b1d0dc6 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 io(xml): return StringIO(xml)
+else:
+ from BytesIO import BytesIO
+ def 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(io(xml), events=("start", "end")))