summaryrefslogtreecommitdiffstats
path: root/Lib/weakref.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-05-15 17:04:50 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-05-15 17:04:50 (GMT)
commit6e61006cc2dfa6c07fa84126622685769bac635d (patch)
tree4ec0f42d852421dac3776e533f51278f5259791e /Lib/weakref.py
parentbd3da6b9804fafe6a730883d96bada52388e9835 (diff)
downloadcpython-6e61006cc2dfa6c07fa84126622685769bac635d.zip
cpython-6e61006cc2dfa6c07fa84126622685769bac635d.tar.gz
cpython-6e61006cc2dfa6c07fa84126622685769bac635d.tar.bz2
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. ........
Diffstat (limited to 'Lib/weakref.py')
-rw-r--r--Lib/weakref.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py
index 6663c26..0276dfd 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)