[Python-modules-commits] [python-pynzb] 03/04: give lxml etree BytesIO in Python 3

Carl Suster arcresu-guest at moszumanska.debian.org
Thu Jan 12 01:29:23 UTC 2017


This is an automated email from the git hooks/post-receive script.

arcresu-guest pushed a commit to branch master
in repository python-pynzb.

commit bb4f526aa0b6664b45d38c64b546e783407034b6
Author: Carl Suster <carl at contraflo.ws>
Date:   Wed Jan 11 22:34:34 2017 +1100

    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.
    
    Forwarded: https://github.com/ericflo/pynzb/pull/6
---
 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..e74ba34 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 io 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")))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pynzb.git



More information about the Python-modules-commits mailing list