Package: python-debian
Version: 0.1.21
Severity: normal
Tags: patch

Deb822.__init__ says:
        :param sequence: a string, or any any object that returns a line of
            input each time, normally a file().  Alternately, sequence can
            be a dict that contains the initial key-value pairs.

and iter_paragraphs says:
        :param sequence: same as in __init__.

However, it breaks with a single string. Even the test suite passes a
list of strings.

Attached patch adds quick-and-dirty support for a single string.
diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py
index 4c5b74e..c4ad14c 100644
--- a/lib/debian/deb822.py
+++ b/lib/debian/deb822.py
@@ -308,6 +308,9 @@ class Deb822(Deb822Dict):
             necessary in order to properly interpret the strings.)
         """
 
+        if isinstance(sequence, basestring):
+            sequence = sequence.splitlines()
+
         if _have_apt_pkg and use_apt_pkg and isinstance(sequence, file):
             parser = apt_pkg.TagFile(sequence)
             for section in parser:
diff --git a/tests/test_deb822.py b/tests/test_deb822.py
index c3806bd..8f23e78 100755
--- a/tests/test_deb822.py
+++ b/tests/test_deb822.py
@@ -821,6 +821,16 @@ Description: python modules to work with Debian-related data formats
             UNPARSED_PARAGRAPHS_WITH_COMMENTS.splitlines(), use_apt_pkg=False))
         self._test_iter_paragraphs_comments(paragraphs)
 
+    def test_iter_paragraphs_string_comments_use_apt_pkg(self):
+        paragraphs = list(deb822.Deb822.iter_paragraphs(
+            UNPARSED_PARAGRAPHS_WITH_COMMENTS, use_apt_pkg=True))
+        self._test_iter_paragraphs_comments(paragraphs)
+
+    def test_iter_paragraphs_string_comments_native(self):
+        paragraphs = list(deb822.Deb822.iter_paragraphs(
+            UNPARSED_PARAGRAPHS_WITH_COMMENTS, use_apt_pkg=False))
+        self._test_iter_paragraphs_comments(paragraphs)
+
 
 class TestPkgRelations(unittest.TestCase):
 

Reply via email to