summaryrefslogtreecommitdiff
path: root/apt/package.py
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-04-17 18:01:30 +0200
committerJulian Andres Klode <jak@debian.org>2009-04-17 18:01:30 +0200
commit6bc61a050bd278b28e883b91cfa5999a7cf76d9d (patch)
tree524ed3313f0b87a67cb947c727021deea2d55d51 /apt/package.py
parent79cba28b2346909a12e4ce225bc25b164c33f062 (diff)
downloadpython-apt-6bc61a050bd278b28e883b91cfa5999a7cf76d9d.tar.gz
* apt/package.py: Where possible, derive apt.package.Record from collections.Mapping.
This works on Python 2.6 and newer and enhances the Record class with some new methods on these platforms, e.g. keys().
Diffstat (limited to 'apt/package.py')
-rw-r--r--apt/package.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/apt/package.py b/apt/package.py
index 1a2626fa..411f9635 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -28,6 +28,11 @@ import socket
import subprocess
import urllib2
import warnings
+try:
+ from collections import Mapping
+except ImportError:
+ # (for Python < 2.6) pylint: disable-msg=C0103
+ Mapping = object
import apt_pkg
import apt.progress
@@ -145,7 +150,7 @@ class Origin(object):
self.site, self.trusted)
-class Record(object):
+class Record(Mapping):
"""Represent a pkgRecord.
It can be accessed like a dictionary and can also give the original package
@@ -155,6 +160,9 @@ class Record(object):
def __init__(self, record_str):
self._rec = apt_pkg.ParseSection(record_str)
+ def __hash__(self):
+ return hash(self._rec)
+
def __str__(self):
return str(self._rec)
@@ -183,6 +191,9 @@ class Record(object):
"""deprecated form of ``key in x``."""
return key in self._rec
+ def __len__(self):
+ return len(self._rec)
+
class Version(object):
"""Representation of a package version.