Bug#466753: python-debian: apt_pkg does not play nice with multiline-but-of-length-one multivalued fields

Adeodato Simó dato at net.com.org.es
Wed Feb 20 18:26:39 UTC 2008


Package: python-debian
Version: 0.1.9
Severity: normal

Our _multivalued class is sort of smart, and depending on whether a
field in _multivalued_fields is multiline or not, it assigns a list of
dicts or only a dictionary to that value:

-8<-
import deb822

class Foo(deb822._multivalued):
      _multivalued_fields = {
          'x': [ 'x1', 'x2' ],
          'y': [ 'y1', 'y2' ],
          'z': [ 'z1', 'z2' ],
      }

f = Foo('''\
X: A B
Y:
 C D
Z:
 E F
 G H'''.splitlines())

print 'x =', f['x']
print 'y =', f['y']
print 'z =', f['z']
->8-

Result:

  x = {'x1': 'A', 'x2': 'B'}
  y = [{'y1': 'C', 'y2': 'D'}]
  z = [{'z1': 'E', 'z2': 'F'}, {'z1': 'G', 'z2': 'H'}]

So, compare x to y: the first gets assigned directly a dict because the
field is completely in one line; the second a list, because *although
there is only one line*, it is formatted as a multi-line field. This is
the correct behavior.

                                 * * *

Enter now the marvelous world of apt_pkg:

-8<-
f = Foo.iter_paragraphs(file('/tmp/foo')).next()

print 'y =', f['y']
->8-

Result:

  y = {'y1': 'C', 'y2': 'D'}

This is because apt_pkg stripes the first '\n ' from the value of the
field.

We need to address this. One possible way would be always forcing not to
use apt_pkg for classes derived from _multivalued, I guess.

-- 
Adeodato Simó                                     dato at net.com.org.es
Debian Developer                                  adeodato at debian.org
 
- Oh my God, you're pimping me out for a new roof?
- And windows!
                -- Andrew and Bree Van De Kamp






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