Project

Profile

Help

Issue #3370 » deb822.patch

mihai.ibanescu@gmail.com, 07/10/2018 09:56 PM

View differences:

lib/debian/deb822.py
self[curkey] = content
def __str__(self):
if six.PY2:
# self.dump() returns unicode
return self.dump().encode(self.encoding)
return self.dump()
def __unicode__(self):
return self.dump()
if sys.version >= '3':
if six.PY3:
def __bytes__(self):
return self.dump().encode(self.encoding)
......
for key in self:
value = self.get_as_string(key)
keyenc = key
if isinstance(keyenc, six.binary_type):
# Convert the key into unicode
keyenc = key.decode(self.encoding)
if not value or value[0] == '\n':
# Avoid trailing whitespace after "Field:" if it's on its own
# line or the value is empty. We don't have to worry about the
# case where value == '\n', since we ensure that is not the
# case in __setitem__.
entry = '%s:%s\n' % (key, value)
entry = '%s:%s\n' % (keyenc, value)
else:
entry = '%s: %s\n' % (key, value)
entry = '%s: %s\n' % (keyenc, value)
if not return_string and not text_mode:
fd.write(entry.encode(encoding))
else:
lib/debian/tests/test_deb822.py
d.dump(fd=buf, text_mode=True)
self.assertEqual(CHANGES_FILE, buf.getvalue())
def test_dump_different_encodings(self):
"""
Make sure we can dump in a different encoding that the original one
"""
srcenc = 'iso-8859-1'
obj = deb822.Deb822({'\xed': 'i'}, encoding=srcenc)
self.assertEquals(
b'\xed: i\n'.decode(srcenc),
obj.dump(encoding='utf-8'))
def test_bug597249_colon_as_first_value_character(self):
"""Colon should be allowed as the first value character. See #597249.
(4-4/5)