[python-debian/master 2/3] copyright: make Copyright objects iterable
Stefano Zacchiroli
zack at upsilon.cc
Sat Sep 13 07:23:01 UTC 2014
iteration will be on all paragraphs, as per all_paragraphs()
---
lib/debian/copyright.py | 8 ++++++++
tests/test_copyright.py | 1 +
2 files changed, 9 insertions(+)
diff --git a/lib/debian/copyright.py b/lib/debian/copyright.py
index 708569f..36bce6e 100644
--- a/lib/debian/copyright.py
+++ b/lib/debian/copyright.py
@@ -148,6 +148,14 @@ class Copyright(object):
"""
return itertools.chain([self.header], (p for p in self.__paragraphs))
+ def __iter__(self):
+ """Iterate over all paragraphs
+
+ see all_paragraphs() for more information
+
+ """
+ return self.all_paragraphs()
+
def all_files_paragraphs(self):
"""Returns an iterator over the contained FilesParagraph objects."""
return (p for p in self.__paragraphs if isinstance(p, FilesParagraph))
diff --git a/tests/test_copyright.py b/tests/test_copyright.py
index 1174db5..1d3b748 100755
--- a/tests/test_copyright.py
+++ b/tests/test_copyright.py
@@ -270,6 +270,7 @@ class CopyrightTest(unittest.TestCase):
expected = [c.header] + list(c.all_files_paragraphs()) + \
list(c.all_license_paragraphs())
self.assertEqual(expected, list(c.all_paragraphs()))
+ self.assertEqual(expected, list(c))
def test_all_files_paragraphs(self):
c = copyright.Copyright(sequence=SIMPLE.splitlines())
--
1.9.1
More information about the pkg-python-debian-commits
mailing list