Re: [xml] [PATCH] python 3 bindings call "decode" on "str" object



On Mon, Jan 18, 2016 at 01:01:40PM +0100, Michael Stahl wrote:
with python3-libxml2-2.9.3-2.fc23.x86_64 RPM i get this exception:

Traceback (most recent call last):
  File "/usr/lib64/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/data/lo/master/bin/get-bugzilla-attachments-by-mimetype", line 515, in run
    get_through_rss_query(uri, mimetype, prefix, extension)
  File "/data/lo/master/bin/get-bugzilla-attachments-by-mimetype", line 264, in get_through_rss_query
    process(query, True, get_file_bz_ids(files, prefix))
  File "/data/lo/master/bin/get-bugzilla-attachments-by-mimetype", line 226, in process
    d = feedparser.parse(url)
  File "/usr/lib/python3.4/site-packages/feedparser.py", line 3957, in parse
    saxparser.parse(source)
  File "/usr/lib64/python3.4/site-packages/drv_libxml2.py", line 189, in parse
    eltName = (_d(reader.NamespaceUri()),\
  File "/usr/lib64/python3.4/site-packages/drv_libxml2.py", line 70, in _d
    return _decoder(s)[0]
  File "/usr/lib64/python3.4/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
TypeError: 'str' does not support the buffer interface

looks like python/types.c actually creates Unicode str that don't
benefit from decoding:

  Ah yes the SAX example driver is not something I checked after adding python3
support, pushed:

  https://git.gnome.org/browse/libxml2/commit/?id=65112cb36aa56bb27697c38ff52c1489cc21cba5


  thanks !

Daniel

#define PY_IMPORT_STRING PyUnicode_FromString

From d44c6c1bbaced5f41b00e54a256e11bc098f2639 Mon Sep 17 00:00:00 2001
From: Michael Stahl <mstahl redhat com>
Date: Mon, 18 Jan 2016 12:46:41 +0100
Subject: [PATCH] python 3: libxml2.c wrappers create Unicode str already

... so stop decoding these, which only results in
"TypeError: 'str' does not support the buffer interface".
---
 python/drv_libxml2.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/python/drv_libxml2.py b/python/drv_libxml2.py
index c2ec3e2..71b1c67 100644
--- a/python/drv_libxml2.py
+++ b/python/drv_libxml2.py
@@ -44,8 +44,18 @@ if sys.version_info[0] < 3:
     __author__  = codecs.unicode_escape_decode(__author__)[0]
 
     StringTypes = (str, unicode)
+    # libxml2 returns strings as UTF8
+    _decoder = codecs.lookup("utf8")[1]
+    def _d(s):
+        if s is None:
+            return s
+        else:
+            return _decoder(s)[0]
 else:
     StringTypes = str
+    # s is Unicode `str` already
+    def _d(s):
+        return s
 
 from xml.sax._exceptions import *
 from xml.sax import xmlreader, saxutils
@@ -61,14 +71,6 @@ from xml.sax.handler import \
      property_dom_node, \
      property_xml_string
 
-# libxml2 returns strings as UTF8
-_decoder = codecs.lookup("utf8")[1]
-def _d(s):
-    if s is None:
-        return s
-    else:
-        return _decoder(s)[0]
-
 try:
     import libxml2
 except ImportError:
-- 
2.5.0


_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
https://mail.gnome.org/mailman/listinfo/xml


-- 
Daniel Veillard      | Open Source and Standards, Red Hat
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | virtualization library  http://libvirt.org/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]