Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 510ca38

Browse files
author
pwuertz
committed
backend_pgf: implement subset of WeakSet for supporting py2.6
1 parent 6957dbd commit 510ca38

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

lib/matplotlib/backends/backend_pgf.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,31 @@ def get_latex_manager():
223223
LatexManagerFactory.previous_instance = new_inst
224224
return new_inst
225225

226+
class WeakSet:
227+
# TODO: Poor man's weakref.WeakSet.
228+
# Remove this once python 2.6 support is dropped from matplotlib.
229+
230+
def __init__(self):
231+
self.weak_key_dict = weakref.WeakKeyDictionary()
232+
233+
def add(self, item):
234+
self.weak_key_dict[item] = None
235+
236+
def discard(self, item):
237+
if item in self.weak_key_dict:
238+
del self.weak_key_dict[item]
239+
240+
def __iter__(self):
241+
return self.weak_key_dict.iterkeys()
242+
226243

227244
class LatexManager:
228245
"""
229246
The LatexManager opens an instance of the LaTeX application for
230247
determining the metrics of text elements. The LaTeX environment can be
231248
modified by setting fonts and/or a custem preamble in the rc parameters.
232249
"""
233-
_unclean_instances = weakref.WeakSet()
250+
_unclean_instances = WeakSet()
234251

235252
@staticmethod
236253
def _build_latex_header():

0 commit comments

Comments
 (0)