diff options
author | Marius Mauch <genone@gentoo.org> | 2007-01-25 15:49:26 +0000 |
---|---|---|
committer | Marius Mauch <genone@gentoo.org> | 2007-01-25 15:49:26 +0000 |
commit | 3b08c21101b0801d7c5d6c145a27bef5cd42078c (patch) | |
tree | 2eea73b311d67b567410670630335796bf0a272c /pym/cache/mappings.py | |
parent | b4eed9540e19ee7038ac875f0e084f8256675580 (diff) | |
download | portage-3b08c21101b0801d7c5d6c145a27bef5cd42078c.tar.gz portage-3b08c21101b0801d7c5d6c145a27bef5cd42078c.tar.bz2 portage-3b08c21101b0801d7c5d6c145a27bef5cd42078c.zip |
Namespace sanitizing, step 1
svn path=/main/trunk/; revision=5778
Diffstat (limited to 'pym/cache/mappings.py')
-rw-r--r-- | pym/cache/mappings.py | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/pym/cache/mappings.py b/pym/cache/mappings.py deleted file mode 100644 index 9aa5a21e2..000000000 --- a/pym/cache/mappings.py +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright: 2005 Gentoo Foundation -# Author(s): Brian Harring (ferringb@gentoo.org) -# License: GPL2 -# $Id$ - -import UserDict - -class ProtectedDict(UserDict.DictMixin): - """ - given an initial dict, this wraps that dict storing changes in a secondary dict, protecting - the underlying dict from changes - """ - __slots__=("orig","new","blacklist") - - def __init__(self, orig): - self.orig = orig - self.new = {} - self.blacklist = {} - - - def __setitem__(self, key, val): - self.new[key] = val - if key in self.blacklist: - del self.blacklist[key] - - - def __getitem__(self, key): - if key in self.new: - return self.new[key] - if key in self.blacklist: - raise KeyError(key) - return self.orig[key] - - - def __delitem__(self, key): - if key in self.new: - del self.new[key] - elif key in self.orig: - if key not in self.blacklist: - self.blacklist[key] = True - return - raise KeyError(key) - - - def __iter__(self): - for k in self.new.iterkeys(): - yield k - for k in self.orig.iterkeys(): - if k not in self.blacklist and k not in self.new: - yield k - - - def keys(self): - return list(self.__iter__()) - - - def has_key(self, key): - return key in self.new or (key not in self.blacklist and key in self.orig) - - -class LazyLoad(UserDict.DictMixin): - """ - Lazy loading of values for a dict - """ - __slots__=("pull", "d") - - def __init__(self, pull_items_func, initial_items=[]): - self.d = {} - for k, v in initial_items: - self.d[k] = v - self.pull = pull_items_func - - def __getitem__(self, key): - if key in self.d: - return self.d[key] - elif self.pull != None: - self.d.update(self.pull()) - self.pull = None - return self.d[key] - - - def __iter__(self): - return iter(self.keys()) - - def keys(self): - if self.pull != None: - self.d.update(self.pull()) - self.pull = None - return self.d.keys() - - - def has_key(self, key): - return key in self - - - def __contains__(self, key): - if key in self.d: - return True - elif self.pull != None: - self.d.update(self.pull()) - self.pull = None - return key in self.d - |