Bug#710541: python-apt: "key in apt.debfile.DebPackage(...)" doesn't work
Package: python-apt
Version: 0.8.9
Severity: normal
Tags: patch
User: ubuntu-devel@lists.ubuntu.com
Usertags: origin-ubuntu ubuntu-patch saucy
>>> import apt.debfile
>>> deb = apt.debfile.DebPackage("man-db_2.6.3-6_i386.deb")
>>> deb["Version"]
'2.6.3-6'
>>> "Version" in deb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/apt/debfile.py", line 73, in __getitem__
return self._sections[key]
TypeError: Argument must be str.
This is pretty surprising; it turns out that, lacking __contains__,
Python falls back to trying to treat the object as a sequence, but
deb[0] of course doesn't work. Patch follows.
=== modified file 'apt/debfile.py'
--- apt/debfile.py 2012-10-01 14:32:35 +0000
+++ apt/debfile.py 2013-05-31 17:54:59 +0000
@@ -72,6 +72,9 @@ class DebPackage(object):
def __getitem__(self, key):
return self._sections[key]
+ def __contains__(self, key):
+ return key in self._sections
+
@property
def filelist(self):
"""return the list of files in the deb."""
=== modified file 'tests/test_debfile.py'
--- tests/test_debfile.py 2012-11-20 08:44:23 +0000
+++ tests/test_debfile.py 2013-05-31 17:14:57 +0000
@@ -133,6 +133,10 @@ Description: testpackage for gdebi - con
# we need to support python2.6
self.assertTrue(raised)
+ def test_contains(self):
+ deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb")
+ self.assertTrue("Package" in deb)
+
if __name__ == "__main__":
#logging.basicConfig(level=logging.DEBUG)
Thanks,
--
Colin Watson [cjwatson@ubuntu.com]
Reply to: