From 6e61006cc2dfa6c07fa84126622685769bac635d Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Fri, 15 May 2009 17:04:50 +0000 Subject: Merged revisions 72669 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r72669 | antoine.pitrou | 2009-05-15 18:54:52 +0200 (ven., 15 mai 2009) | 3 lines Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing. ........ --- Lib/weakref.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Lib/weakref.py') diff --git a/Lib/weakref.py b/Lib/weakref.py index 6663c262d1..0276dfd117 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -85,6 +85,17 @@ class WeakValueDictionary(collections.MutableMapping): new[key] = o return new + __copy__ = copy + + def __deepcopy__(self, memo): + from copy import deepcopy + new = self.__class__() + for key, wr in self.data.items(): + o = wr() + if o is not None: + new[deepcopy(key, memo)] = o + return new + def get(self, key, default=None): try: wr = self.data[key] @@ -251,6 +262,17 @@ class WeakKeyDictionary(collections.MutableMapping): new[o] = value return new + __copy__ = copy + + def __deepcopy__(self, memo): + from copy import deepcopy + new = self.__class__() + for key, value in self.data.items(): + o = key() + if o is not None: + new[o] = deepcopy(value, memo) + return new + def get(self, key, default=None): return self.data.get(ref(key),default) -- cgit v1.2.1