summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-04-14 06:30:52 +0000
committerZac Medico <zmedico@gentoo.org>2006-04-14 06:30:52 +0000
commit86e08bdaf036b7b455514b3b6cde47523e9759f5 (patch)
tree050a51442fe0da782b7b856006e6fa0f3fda838e
parent0241a10d9fd597ff534446d82619fc42b2880a36 (diff)
downloadportage-86e08bdaf036b7b455514b3b6cde47523e9759f5.tar.gz
portage-86e08bdaf036b7b455514b3b6cde47523e9759f5.tar.bz2
portage-86e08bdaf036b7b455514b3b6cde47523e9759f5.zip
Add an initial_items parameter to the LazyItemsDict constructor in order to facilitate integration with existing dict based code.
svn path=/main/trunk/; revision=3143
-rw-r--r--pym/portage.py10
-rw-r--r--pym/portage_util.py6
2 files changed, 7 insertions, 9 deletions
diff --git a/pym/portage.py b/pym/portage.py
index 4f8c9423c..547085c24 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -1414,14 +1414,8 @@ class config:
global db, root
self._use = autouse(db[root]["vartree"], *self._pargs, **self._kwargs)
return self._use
- if isinstance(self.configdict["auto"],
- portage_util.LazyItemsDict):
- lazy_values = self.configdict["auto"]
- else:
- lazy_values = portage_util.LazyItemsDict()
- lazy_values.update(self.configdict["auto"])
- lazy_values.addLazyItem("USE", LazyAutouse(use_cache=use_cache))
- self.configdict["auto"] = lazy_values
+ self.configdict["auto"] = portage_util.LazyItemsDict(self.configdict["auto"])
+ self.configdict["auto"].addLazyItem("USE", LazyAutouse(use_cache=use_cache))
else:
self.configdict["auto"]["USE"]=""
else:
diff --git a/pym/portage_util.py b/pym/portage_util.py
index 6fd76090c..cd69733ba 100644
--- a/pym/portage_util.py
+++ b/pym/portage_util.py
@@ -715,9 +715,13 @@ class LazyItemsDict(dict):
"""A mapping object that behaves like a standard dict except that it allows
for lazy initialization of values via callable objects. Lazy items can be
overwritten and deleted just as normal items."""
- def __init__(self):
+ def __init__(self, initial_items=None):
dict.__init__(self)
self.lazy_items = {}
+ if initial_items is not None:
+ self.update(initial_items)
+ if isinstance(initial_items, LazyItemsDict):
+ self.lazy_items.update(initial_items.lazy_items)
def addLazyItem(self, item_key, value_callable):
"""Add a lazy item for the given key. When the item is requested,
value_callable will be called with no arguments."""