diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-25 07:12:50 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-25 07:12:50 +0000 |
commit | 72dd2b08beb9803269983aa220e75b44007e5158 (patch) | |
tree | 16f80b5f869ba68ae17e2fcbe9b18f1542b22e84 /lib/sqlalchemy/util.py | |
parent | 5b81c1a2d0915d95d9928ffaaf81af814cf4ec3e (diff) | |
download | sqlalchemy-72dd2b08beb9803269983aa220e75b44007e5158.tar.gz |
merged sql_rearrangement branch , refactors sql package to work standalone with
clause elements including tables and columns, schema package deals with "physical"
representations
Diffstat (limited to 'lib/sqlalchemy/util.py')
-rw-r--r-- | lib/sqlalchemy/util.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 301db0ec4..fccb2f3bd 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -4,7 +4,7 @@ # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -__all__ = ['OrderedProperties', 'OrderedDict', 'generic_repr', 'HashSet'] +__all__ = ['OrderedProperties', 'OrderedDict', 'generic_repr', 'HashSet', 'AttrProp'] import thread, weakref, UserList,string, inspect from exceptions import * @@ -23,7 +23,21 @@ def to_set(x): return HashSet(to_list(x)) else: return x - + +class AttrProp(object): + """a quick way to stick a property accessor on an object""" + def __init__(self, key): + self.key = key + def __set__(self, obj, value): + setattr(obj, self.key, value) + def __delete__(self, obj): + delattr(obj, self.key) + def __get__(self, obj, owner): + if obj is None: + return self + else: + return getattr(obj, self.key) + def generic_repr(obj, exclude=None): L = ['%s=%s' % (a, repr(getattr(obj, a))) for a in dir(obj) if not callable(getattr(obj, a)) and not a.startswith('_') and (exclude is None or not exclude.has_key(a))] return '%s(%s)' % (obj.__class__.__name__, ','.join(L)) @@ -65,9 +79,10 @@ class OrderedProperties(object): def __setattr__(self, key, object): if not hasattr(self, key): self._list.append(key) - self.__dict__[key] = object - + def clear(self): + for key in self._list[:]: + del self[key] class RecursionStack(object): """a thread-local stack used to detect recursive object traversals.""" def __init__(self): |