diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-04-27 23:56:09 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-04-27 23:56:09 +0000 |
commit | a456fd54759fb99d6575c8abe85cbbba638b3179 (patch) | |
tree | 5edbe6eba8ec187d57f7fcd8c4e0016fb6c99000 /lib/sqlalchemy/attributes.py | |
parent | 60726abc1ca6762b0562941cdfd1f462a50bd335 (diff) | |
download | sqlalchemy-a456fd54759fb99d6575c8abe85cbbba638b3179.tar.gz |
the latest and greatest method to keep attributes from growing
Diffstat (limited to 'lib/sqlalchemy/attributes.py')
-rw-r--r-- | lib/sqlalchemy/attributes.py | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/lib/sqlalchemy/attributes.py b/lib/sqlalchemy/attributes.py index 98884df44..627cac4b6 100644 --- a/lib/sqlalchemy/attributes.py +++ b/lib/sqlalchemy/attributes.py @@ -79,8 +79,12 @@ class ManagedAttribute(object): ManagedAttribute objects associated with the instance via this dictionary.""" def __init__(self, obj, key): self.__obj = weakref.ref(obj) - #self.obj = obj self.key = key + def __getstate__(self): + return {'key':self.key, 'obj':self.obj} + def __setstate__(self, d): + self.key = d['key'] + self.__obj = weakref.ref(d['obj']) obj = property(lambda s:s.__obj()) def history(self, **kwargs): return self @@ -496,25 +500,4 @@ class AttributeManager(object): will be passed along to newly created ManagedAttribute.""" if not hasattr(class_, '_attribute_manager'): class_._attribute_manager = self - class_._managed_attributes = ObjectAttributeGateway() setattr(class_, key, self.create_prop(class_, key, uselist, callable_, **kwargs)) - -managed_attributes = weakref.WeakKeyDictionary() - -class ObjectAttributeGateway(object): - """handles the dictionary of ManagedAttributes for instances. this level of indirection - is to prevent circular references upon objects, as well as keeping them Pickle-compatible.""" - def __set__(self, obj, value): - managed_attributes[obj] = value - def __delete__(self, obj): - try: - del managed_attributes[obj] - except KeyError: - raise AttributeError() - def __get__(self, obj, owner): - if obj is None: - return self - try: - return managed_attributes[obj] - except KeyError: - raise AttributeError()
\ No newline at end of file |