1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
Index: matplotlib-0.98.1/lib/matplotlib/cbook.py
===================================================================
--- matplotlib-0.98.1.orig/lib/matplotlib/cbook.py 2008-06-22 20:26:47.000000000 -0500
+++ matplotlib-0.98.1/lib/matplotlib/cbook.py 2008-09-13 19:46:39.000000000 -0500
@@ -6,6 +6,7 @@
import re, os, errno, sys, StringIO, traceback, locale
import time, datetime
import numpy as np
+from weakref import ref
major, minor1, minor2, s, tmp = sys.version_info
@@ -977,10 +978,20 @@
def __init__(self, init=[]):
mapping = self._mapping = {}
for x in init:
- mapping[x] = [x]
+ mapping[ref(x)] = [ref(x)]
def __contains__(self, item):
- return item in self._mapping
+ return ref(item) in self._mapping
+
+ def clean(self):
+ """
+ Clean dead weak references from the dictionary
+ """
+ mapping = self._mapping
+ for key, val in mapping.items():
+ if key() is None:
+ del mapping[key]
+ val.remove(key)
def join(self, a, *args):
"""
@@ -988,13 +999,13 @@
arguments.
"""
mapping = self._mapping
- set_a = mapping.setdefault(a, [a])
+ set_a = mapping.setdefault(ref(a), [ref(a)])
for arg in args:
- set_b = mapping.get(arg)
+ set_b = mapping.get(ref(arg))
if set_b is None:
- set_a.append(arg)
- mapping[arg] = set_a
+ set_a.append(ref(arg))
+ mapping[ref(arg)] = set_a
elif set_b is not set_a:
if len(set_b) > len(set_a):
set_a, set_b = set_b, set_a
@@ -1002,13 +1013,17 @@
for elem in set_b:
mapping[elem] = set_a
+ self.clean()
+
def joined(self, a, b):
"""
Returns True if *a* and *b* are members of the same set.
"""
+ self.clean()
+
mapping = self._mapping
try:
- return mapping[a] is mapping[b]
+ return mapping[ref(a)] is mapping[ref(b)]
except KeyError:
return False
@@ -1026,7 +1041,10 @@
"""
Returns all of the items joined with *a*, including itself.
"""
- return self._mapping.get(a, [a])
+ self.clean()
+
+ siblings = self._mapping.get(ref(a), [ref(a)])
+ return [x() for x in siblings]
def simple_linear_interpolation(a, steps):
|