aboutsummaryrefslogtreecommitdiffstats
path: root/debian/lib/python/debian_linux/utils.py
diff options
context:
space:
mode:
authorBastian Blank <waldi@debian.org>2009-04-12 10:27:59 +0000
committerBastian Blank <waldi@debian.org>2009-04-12 10:27:59 +0000
commit90009cd8db86d02d3d48eb189186e55ed38717dd (patch)
tree70eba2b75103faefdd6a531a850dba0cad2cc42d /debian/lib/python/debian_linux/utils.py
parent36c8fe1c19095d17c2df27b082385329e6071add (diff)
downloadkernel_replicant_linux-90009cd8db86d02d3d48eb189186e55ed38717dd.tar.gz
kernel_replicant_linux-90009cd8db86d02d3d48eb189186e55ed38717dd.tar.bz2
kernel_replicant_linux-90009cd8db86d02d3d48eb189186e55ed38717dd.zip
debian/lib/python/debian_linux/utils.py
- Don't implement the complete dict interface. - Fix get behaviour on non-existant entries. svn path=/dists/trunk/linux-2.6/; revision=13397
Diffstat (limited to 'debian/lib/python/debian_linux/utils.py')
-rw-r--r--debian/lib/python/debian_linux/utils.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/debian/lib/python/debian_linux/utils.py b/debian/lib/python/debian_linux/utils.py
index b0ff1a6e2617..077d7008e95a 100644
--- a/debian/lib/python/debian_linux/utils.py
+++ b/debian/lib/python/debian_linux/utils.py
@@ -33,15 +33,17 @@ class SortedDict(dict):
for i in iter(self._list):
yield self[i]
-class Templates(dict):
+class Templates(object):
def __init__(self, dirs = ["debian/templates"]):
self.dirs = dirs
- def __getitem__(self, key):
- return self.get(key)
+ self._cache = {}
- def __setitem__(self, key, value):
- raise NotImplemented()
+ def __getitem__(self, key):
+ ret = self.get(key)
+ if ret is not None:
+ return ret
+ raise KeyError(key)
def _read(self, name):
prefix, id = name.split('.', 1)
@@ -89,16 +91,13 @@ class Templates(dict):
return entries
- def get(self, key, default = _marker):
- ret = super(Templates, self).get(key, _marker)
- if ret is not _marker:
- return ret
- value = self._read(key)
+ def get(self, key, default=None):
+ if key in self._cache:
+ return self._cache[key]
+
+ value = self._cache.setdefault(key, self._read(key))
if value is None:
- if default is _marker:
- raise KeyError(key)
return default
- super(Templates, self).__setitem__(key, value)
return value
class TextWrapper(textwrap.TextWrapper):