[python-debian/master] deb822.Deb822.iter_paragraphs: Actually work with string input.

John Wright jsw at debian.org
Mon Oct 8 08:29:49 UTC 2012


Thanks to Stefano Rivera for the patch.  (I modified it to use
six.string_types instead of basestring for compatibility with both
Python 2 and Python 3.)

Closes: #647455
---
 debian/changelog     |    2 ++
 lib/debian/deb822.py |    2 ++
 tests/test_deb822.py |   10 ++++++++++
 3 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index d1abfb1..4946437 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,8 @@ python-debian (0.1.22) UNRELEASED; urgency=low
   * arfile.ArFile.extractfile: Return a matching member even if it is
     not the first one in the archive.  Thanks to Mika Eloranta for the
     report and patch. (Closes: #689313)
+  * deb822.Deb822.iter_paragraphs: Actually work with string input.
+    Thanks to Stefano Rivera for the patch. (Closes: #647455)
 
  -- John Wright <jsw at debian.org>  Mon, 08 Oct 2012 00:41:32 -0700
 
diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py
index bd910d6..98bf9f3 100644
--- a/lib/debian/deb822.py
+++ b/lib/debian/deb822.py
@@ -376,6 +376,8 @@ class Deb822(Deb822Dict):
                     yield paragraph
 
         else:
+            if isinstance(sequence, six.string_types):
+                sequence = sequence.splitlines()
             iterable = iter(sequence)
             x = cls(iterable, fields, encoding=encoding)
             while len(x) != 0:
diff --git a/tests/test_deb822.py b/tests/test_deb822.py
index f665264..a989a32 100755
--- a/tests/test_deb822.py
+++ b/tests/test_deb822.py
@@ -841,6 +841,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):
 
-- 
1.7.2.5




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