[python-debian/master] deb822: Use apt_pkg's TagFile iterator API

John Wright john.wright at hp.com
Fri Mar 5 02:08:28 UTC 2010


This frees us from having to jump through hoops to avoid using shared
storage while still using apt_pkg for added speed.  (Said hoop-jumping
has caused us problems with recent python-apt versions, so this also
Closes: #571470.)

This requires python-apt >= 0.7.94.  Since it's currently just in
Recommends, that requires a Conflicts with previous versions.
---
 debian/changelog        |    3 +++
 debian/control          |    2 +-
 debian_bundle/deb822.py |   38 +++++++++++---------------------------
 3 files changed, 15 insertions(+), 28 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 6d2c864..cb12806 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -28,6 +28,9 @@ python-debian (0.1.15) UNRELEASED; urgency=low
     method if the encoding of a file you are reading in is not utf-8.
     (The dump method also takes an encoding argument, if you wish the
     output not to be utf-8-encoded.) (Closes: #495272)
+  * Use the apt_pkg.TagFile iterator interface instead of hacking its
+    offset.  As of python-apt version 0.7.94, that interface doesn't use
+    shared storage. (Closes: #571470)
 
  -- Filippo Giunchedi <filippo at debian.org>  Sun, 09 Aug 2009 13:01:16 +0100
 
diff --git a/debian/control b/debian/control
index f1ddbdf..7fc528f 100644
--- a/debian/control
+++ b/debian/control
@@ -20,7 +20,7 @@ Depends: ${python:Depends}
 Recommends: python-apt
 Suggests: gpgv
 Provides: python-deb822
-Conflicts: python-deb822, python-apt (< 0.7.11.1)
+Conflicts: python-deb822, python-apt (< 0.7.94~)
 Replaces: python-deb822
 Description: Python modules to work with Debian-related data formats
  This package provides Python modules that abstract many formats of Debian 
diff --git a/debian_bundle/deb822.py b/debian_bundle/deb822.py
index d78d18a..15eb056 100644
--- a/debian_bundle/deb822.py
+++ b/debian_bundle/deb822.py
@@ -37,21 +37,21 @@ import sys
 import StringIO
 import UserDict
 
-class TagFileWrapper(object, UserDict.DictMixin):
-    """Wrap a TagFile object, using its Section.FindRaw method instead of Find
+class TagSectionWrapper(object, UserDict.DictMixin):
+    """Wrap a TagSection object, using its find_raw method to get field values
 
     This allows us to pick which whitespace to strip off the beginning and end
     of the data, so we don't lose leading newlines.
     """
 
-    def __init__(self, parser):
-        self.__parser = parser
+    def __init__(self, section):
+        self.__section = section
 
     def keys(self):
-        return self.__parser.Section.keys()
+        return self.__section.keys()
 
     def __getitem__(self, key):
-        s = self.__parser.Section.FindRaw(key)
+        s = self.__section.find_raw(key)
 
         if s is None:
             raise KeyError(key)
@@ -269,15 +269,8 @@ class Deb822(Deb822Dict):
         :param use_apt_pkg: if sequence is a file(), apt_pkg will be used 
             if available to parse the file, since it's much much faster.  Set
             this parameter to False to disable using apt_pkg.
-        :param shared_storage: if sequence is a file(), use_apt_pkg is True,
-            and shared_storage is True, yielded objects will share storage, so
-            they can't be kept across iterations.  (Also, PGP signatures won't
-            be stripped.)  By default, this parameter is False, causing a copy
-            of the parsed data to be made through each iteration.  Except for
-            with raw Deb822 paragraphs (as opposed to _multivalued subclasses),
-            the speed gained by setting shared_storage=True is marginal.  This
-            parameter has no effect if use_apt_pkg is False or apt_pkg is not
-            available.
+        :param shared_storage: not used, here for historical reasons.  Deb822
+            objects never use shared storage anymore.
         :param encoding: Interpret the paragraphs in this encoding.
             (All values are given back as unicode objects, so an encoding is
             necessary in order to properly interpret the strings.)
@@ -285,18 +278,9 @@ class Deb822(Deb822Dict):
 
         if _have_apt_pkg and use_apt_pkg and isinstance(sequence, file):
             parser = apt_pkg.TagFile(sequence)
-            while parser.Step() == 1:
-                x = cls(fields=fields, _parsed=TagFileWrapper(parser),
-                        encoding=encoding)
-                if len(x) != 0:
-                    yield x
-
-                if not shared_storage:
-                    # Make a new parser, starting it right before the next
-                    # section
-                    offset = parser.Offset() - 1
-                    parser = apt_pkg.TagFile(sequence)
-                    parser.Jump(offset)
+            for section in parser:
+                yield cls(fields=fields, _parsed=TagSectionWrapper(section),
+                          encoding=encoding)
 
         else:
             iterable = iter(sequence)
-- 
1.6.3.3




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