Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-236

A QtCore.QFile can't be directly parsed with xml.sax.parse in Python 3

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 1.2.0
    • PySide
    • None
    • Ubuntu 14.04 on x86_64

    Description

      The QtCore.QFile class' read method returns a QByteArray, which xml.sax.parse can't handle right away in Python 3.4.0. It works in Python 2.7.6. Here is a testcase:

      import PySide2
      import xml.sax, xml.sax.handler
      buf = PySide2.QtCore.QByteArray(b"<foo/>")
      xml.sax.parseString(buf, xml.sax.handler.ContentHandler())
      

      Here's the error I get in Python 3.4.0:

      Traceback (most recent call last):
        File "qbytearray.py", line 6, in <module>
          xml.sax.parseString(buf, xml.sax.handler.ContentHandler())
        File "/usr/lib/python3.4/xml/sax/__init__.py", line 45, in parseString
          inpsrc.setByteStream(BytesIO(string))
      TypeError: 'PySide.QtCore.QByteArray' does not support the buffer interface
      

      The same error occurs with xml.sax.parse(fp, handler) when fp is of the QtCore.QFile type.

      I have a workaround that converts the QByteArray to a bytes type before passing it to the xml parser.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            christian.haggstrom christian haggstrom
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes