Bug#833375: python3-debian: Cannot parse input of bytes under Python 3

Chris Lamb lamby at debian.org
Wed Aug 3 15:31:57 UTC 2016


Package: python3-debian
Version: 0.1.28
Severity: normal

Hi,

The following works under Python 2:

    with open('Sources', 'rb') as f:
        content = f.read()
    for src in Sources.iter_paragraphs(content):
         print((src['Package'], src['Version']))

.. but not under Python 3:

    Traceback (most recent call last):
      File "test.py", line 8, in <module>
        for src in Sources.iter_paragraphs(content):
      File "/usr/lib/python3/dist-packages/debian/deb822.py", line 388, in iter_paragraphs
        x = cls(iterable, fields, encoding=encoding)
      File "/usr/lib/python3/dist-packages/debian/deb822.py", line 1390, in __init__
        Dsc.__init__(self, *args, **kwargs)
      File "/usr/lib/python3/dist-packages/debian/deb822.py", line 1242, in __init__
        self._bytes(s, encoding) for s in sequence)
      File "/usr/lib/python3/dist-packages/debian/deb822.py", line 647, in split_gpg_and_payload
        for line in sequence:
      File "/usr/lib/python3/dist-packages/debian/deb822.py", line 1242, in <genexpr>
        self._bytes(s, encoding) for s in sequence)
      File "/usr/lib/python3/dist-packages/debian/deb822.py", line 1272, in _bytes
        raise TypeError('bytes or unicode/string required (not %s)' % type(s))
    TypeError: bytes or unicode/string required

If you modify it to:

    with open('Sources', 'rb') as f:
        content = f.read()
    content = content.decode('utf8')
    [etc]

.. then it works under Python 3, however I think we should accept
bytes.

Issue is that ``sequence`` is a bytes_iterator. I tried to put together
a patch that fixes this but even detecting this type seems to require
something like:

    elif six.PY3 and isinstance(sequence, type(iter(b''))):
        [..]

(I'm probably missing something obvious..)


Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      lamby at debian.org / chris-lamb.co.uk
       `-



More information about the pkg-python-debian-maint mailing list