Bug#487797: python-debian: file arg in Changelog should expect file object

Tilman Koschnick til at subnetz.org
Tue Jun 24 08:28:53 UTC 2008

Package: python-debian
Version: 0.1.10~bpo40+1
Severity: wishlist
Tags: patch


I repeatedly stumble over the 'file' arg to changelog.Changelog(),
expecting it should be an open file object and not a string. It's just a
minor thing, but I find 

  f = open('/path/to/changelog')
  cl = changelog.Changelog(f)

more intuitive than

  cl = changelog.Changelog(f.read())

It corresponds better with how files are treated in deb822 as well.

Patch attached (strings are still supported, as to not break existing

Cheers, Til
-------------- next part --------------
--- changelog.py.orig	2008-06-24 09:33:13.307114680 +0200
+++ changelog.py	2008-06-24 10:25:14.884034626 +0200
@@ -195,7 +195,7 @@
   def __init__(self, file=None, max_blocks=None, allow_empty_author=False):
-    """Set up the Changelog for use. file is the contects of the changelog.
+    """Set up the Changelog for use. file is an open filehandle to a changelog file.
     self._blocks = []
     if file is not None:
@@ -217,9 +217,13 @@
       author = None
       date = None
-      self._file = file
+      if isinstance(file, open):  # open is an alias for file, which is hidden by the file variable
+        self._file = file
+      else:
+        self._file = file.split('\n')
       state = before
-      for line in self._file.split('\n'):
+      for line in self._file:
+        line = line.rstrip('\n')
         if state == before:
           m = topline.match(line)
           if m is not None:

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