[python-debian/jsw/apt-pkg-without-shared-storage] Implement Deb822Dict.__contains__
John Wright
jsw at debian.org
Tue Nov 4 21:46:13 UTC 2008
By using the internal __dict object's __contains__ method, rather than
making DictMixin look through all the elements of the __keys list, we
significantly speed up operations that require looking to see if the
Deb822Dict already has a particular key (such as __setitem__). This, in
turn, speeds up the operation of Deb822.iter_paragraphs with
shared_storage=False, so that, except for raw Deb822 paragraphs, the
speed gained by using shared_storage=True is marginal.
So, I also set the default shared_storage parameter for
Deb822.iter_paragraphs to False. This results in reasonably fast
parsing most of the time, and has less potential for confusion than with
shared_storage=True.
---
debian_bundle/deb822.py | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/debian_bundle/deb822.py b/debian_bundle/deb822.py
index 4527ac7..2ad9115 100644
--- a/debian_bundle/deb822.py
+++ b/debian_bundle/deb822.py
@@ -102,6 +102,9 @@ class Deb822Dict(object, UserDict.DictMixin):
return self.__parsed[key]
else:
raise
+
+ def __contains__(self, key):
+ return key in self.__dict
def __delitem__(self, key):
key = _strI(key)
@@ -168,7 +171,7 @@ class Deb822(Deb822Dict):
self.gpg_info = None
def iter_paragraphs(cls, sequence, fields=None, use_apt_pkg=True,
- shared_storage=True):
+ shared_storage=False):
"""Generator that yields a Deb822 object for each paragraph in sequence.
:param sequence: same as in __init__.
@@ -178,12 +181,15 @@ 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() and use_apt_pkg is True,
- yielded objects will share storage, so they can't be kept across
- iterations. (Also, PGP signatures won't be stripped.) Set this
- parameter to False to make a copy of the parsed data through each
- iteration. This parameter has no effect if use_apt_pkg is False or
- apt_pkg is not available.
+ :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.
"""
if _have_apt_pkg and use_apt_pkg and isinstance(sequence, file):
--
1.5.5.GIT
More information about the pkg-python-debian-commits
mailing list