summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-03-07 23:05:30 +0000
committerZac Medico <zmedico@gentoo.org>2009-03-07 23:05:30 +0000
commita23e4255c9c159f6ac242ea8935ca5c8535b2936 (patch)
tree24e0351b13452da795ede7c52a690f40a1af9913
parent42965e0444ad4f281038341129ffae40456295dc (diff)
downloadportage-a23e4255c9c159f6ac242ea8935ca5c8535b2936.tar.gz
portage-a23e4255c9c159f6ac242ea8935ca5c8535b2936.tar.bz2
portage-a23e4255c9c159f6ac242ea8935ca5c8535b2936.zip
In LazyItemsDict.__deepcopy__(), enable deepcopy of lazy items as it was
before. This requires _LazyItem.__deepcopy__() to be overridden since the default implementation can fail silently, leaving some attributes unset. svn path=/main/trunk/; revision=12780
-rw-r--r--pym/portage/util.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/pym/portage/util.py b/pym/portage/util.py
index d5c7955fc..a881bd77f 100644
--- a/pym/portage/util.py
+++ b/pym/portage/util.py
@@ -1172,10 +1172,13 @@ class LazyItemsDict(dict):
k_copy = deepcopy(k, memo)
if k in self.lazy_items:
lazy_item = self.lazy_items[k]
- if lazy_item.singleton:
+ try:
+ result.lazy_items[k_copy] = deepcopy(lazy_item, memo)
+ except TypeError:
+ if not lazy_item.singleton:
+ raise
dict.__setitem__(result, k_copy, deepcopy(self[k], memo))
else:
- result.lazy_items[k_copy] = deepcopy(lazy_item, memo)
dict.__setitem__(result, k_copy, None)
else:
dict.__setitem__(result, k_copy, deepcopy(self[k], memo))
@@ -1197,6 +1200,26 @@ class LazyItemsDict(dict):
self.kwargs = kwargs
self.singleton = singleton
+ def __copy__(self):
+ return self.__class__(self.func, self.pargs,
+ self.kwargs, self.singleton)
+
+ def __deepcopy__(self, memo=None):
+ """
+ Override this since the default implementation can fail silently,
+ leaving some attributes unset.
+ """
+ if memo is None:
+ memo = {}
+ from copy import deepcopy
+ result = self.__copy__()
+ memo[id(self)] = result
+ result.func = deepcopy(self.func, memo)
+ result.pargs = deepcopy(self.pargs, memo)
+ result.kwargs = deepcopy(self.kwargs, memo)
+ result.singleton = deepcopy(self.singleton, memo)
+ return result
+
class ConfigProtect(object):
def __init__(self, myroot, protect_list, mask_list):
self.myroot = myroot