From: Zac Medico Date: Wed, 11 Mar 2009 06:48:36 +0000 (-0000) Subject: In LazyItemsDict.__deepcopy__(), enable deepcopy of lazy items as it was X-Git-Tag: v2.1.6.8~53 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=64a97f9375e49276adb0d5b8e4bd0f3b1ac54998;p=portage.git 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. (trunk r12780) svn path=/main/branches/2.1.6/; revision=13024 --- 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