From a23e4255c9c159f6ac242ea8935ca5c8535b2936 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 7 Mar 2009 23:05:30 +0000 Subject: [PATCH] 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 --- pym/portage/util.py | 27 +++++++++++++++++++++++++-- 1 file 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 -- 2.26.2