[python-debian/master] changelog: Consistently parse different types of inputs
John Wright
john at johnwright.org
Thu Jul 30 17:44:51 UTC 2009
The previous implementation added extra newlines when given a file as
input, rather than the result of str.splitlines().
Closes: #539316
---
debian/changelog | 4 ++++
debian_bundle/changelog.py | 19 ++++++++++++++++---
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index fe95309..781a8f5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,10 @@ python-debian (0.1.15) UNRELEASED; urgency=low
* deb822: Don't ignore leading newlines on field data with apt_pkg
(Closes: #466753)
+ * changelog: Consistently parse different types of inputs. The
+ previous implementation added extra newlines when given a file
+ object as input, rather than the result of str.splitlines().
+ (Closes: #539316)
-- John Wright <jsw at debian.org> Thu, 30 Jul 2009 01:03:49 +0200
diff --git a/debian_bundle/changelog.py b/debian_bundle/changelog.py
index 07fe4fa..ae72a90 100644
--- a/debian_bundle/changelog.py
+++ b/debian_bundle/changelog.py
@@ -298,10 +298,12 @@ class Changelog(object):
self._parse_error('Empty changelog file.', strict)
return
- if file[-1] != '\n':
- file += '\n'
- file = file.split('\n')[:-1]
+ file = file.splitlines()
for line in file:
+ # Support both lists of lines without the trailing newline and
+ # those with trailing newlines (e.g. when given a file object
+ # directly)
+ line = line.rstrip('\n')
if state == first_heading or state == next_heading_or_eof:
top_match = topline.match(line)
blank_match = blankline.match(line)
@@ -645,6 +647,17 @@ class ChangelogTests(unittest.TestCase):
self.assertEqual(c.full_version, '1.2.3')
self.assertEqual(str(c.version), c.full_version)
+ def test_str_consistent(self):
+ # The parsing of the changelog (including the string representation)
+ # should be consistent whether we give a single string, a list of
+ # lines, or a file object to the Changelog initializer
+ cl_data = open('test_changelog').read()
+ c1 = Changelog(open('test_changelog'))
+ c2 = Changelog(cl_data)
+ c3 = Changelog(cl_data.splitlines())
+ for c in (c1, c2, c3):
+ self.assertEqual(str(c), cl_data)
+
class VersionTests(unittest.TestCase):
def _test_version(self, full_version, epoch, upstream, debian):
--
1.5.6.5
More information about the pkg-python-debian-commits
mailing list