diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-12 06:32:11 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-12 06:32:11 +0000 |
commit | 8c018ab8fa2a9a527030c0279e7c2c5f98d18cda (patch) | |
tree | 7f073b4b510638eb46487c1f6722bde82d9912ae /lib/sqlalchemy/util.py | |
parent | 703908caadfc2cb763e2838e4886074aef32c294 (diff) | |
download | sqlalchemy-8c018ab8fa2a9a527030c0279e7c2c5f98d18cda.tar.gz |
cleanup and organization of code mostly in properties, making SyncRules clearer,
also "foreignkey" property can be a list, particularly for a self-referential table with a multi-column join condition
Diffstat (limited to 'lib/sqlalchemy/util.py')
-rw-r--r-- | lib/sqlalchemy/util.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 45177f838..21866d390 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -15,6 +15,14 @@ def to_list(x): else: return x +def to_set(x): + if x is None: + return HashSet() + if not isinstance(x, HashSet): + return HashSet(to_list(x)) + else: + return x + 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)) @@ -171,7 +179,7 @@ class DictDecorator(dict): return self.decorate[key] class HashSet(object): """implements a Set.""" - def __init__(self, iter = None, ordered = False): + def __init__(self, iter=None, ordered=False): if ordered: self.map = OrderedDict() else: @@ -185,6 +193,8 @@ class HashSet(object): return self.map.has_key(item) def clear(self): self.map.clear() + def empty(self): + return len(self.map) == 0 def append(self, item): self.map[item] = item def remove(self, item): |