Created
January 27, 2014 06:40
-
-
Save loic/8644072 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WeakKeyDictionary | |
Traceback (most recent call last): | |
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 260, in remove | |
del self.data[k] | |
KeyError: <weakref at 0x10be01a48; dead> | |
self.data: | |
{} | |
k: | |
<weakref at 0x10be01a48; dead> | |
Exception KeyError: KeyError(<weakref at 0x10be01a48; dead>,) in <function remove at 0x1056f8aa0> ignored | |
WeakKeyDictionary | |
Traceback (most recent call last): | |
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 260, in remove | |
del self.data[k] | |
KeyError: <weakref at 0x10be01940; dead> | |
self.data: | |
{} | |
k: | |
<weakref at 0x10be01940; dead> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WeakValueDictionary(UserDict.UserDict): | |
def __init__(self, *args, **kw): | |
def remove(wr, selfref=ref(self)): | |
try: | |
self = selfref() | |
if self is not None: | |
del self.data[wr.key] | |
except: | |
print "WeakValueDictionary:" | |
import traceback | |
traceback.print_exc() | |
print "self.data:" | |
print self.data | |
print "wr.key:" | |
print wr.key | |
raise | |
self._remove = remove | |
UserDict.UserDict.__init__(self, *args, **kw) | |
class WeakKeyDictionary(UserDict.UserDict): | |
def __init__(self, dict=None): | |
self.data = {} | |
def remove(k, selfref=ref(self)): | |
try: | |
self = selfref() | |
if self is not None: | |
del self.data[k] | |
except: | |
print "WeakKeyDictionary" | |
import traceback | |
traceback.print_exc() | |
print "self.data:" | |
print self.data | |
print "k:" | |
print k | |
raise | |
self._remove = remove | |
if dict is not None: self.update(dict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment