diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-01-05 19:11:58 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-01-05 19:11:58 +0000 |
commit | 2bc1c28c44ff6e5ccbca793123488919864dcce3 (patch) | |
tree | b3074969fd79a15577103440537245cd157856bf /lib/sqlalchemy/ext/associationproxy.py | |
parent | f9fd5bfb8693c7ea877fd09ec4fd2c042eb6a689 (diff) | |
download | sqlalchemy-2bc1c28c44ff6e5ccbca793123488919864dcce3.tar.gz |
More overloads: fix cascades for += on a list relation, added operator support to association proxied lists.
Diffstat (limited to 'lib/sqlalchemy/ext/associationproxy.py')
-rw-r--r-- | lib/sqlalchemy/ext/associationproxy.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index c5a2b4d07..fefc289f8 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -402,6 +402,37 @@ class _AssociationList(object): def __ge__(self, other): return list(self) >= other def __cmp__(self, other): return cmp(list(self), other) + def __add__(self, iterable): + try: + other = list(iterable) + except TypeError: + return NotImplemented + return list(self) + other + __radd__ = __add__ + + def __mul__(self, n): + if not isinstance(n, int): + return NotImplemented + return list(self) * n + __rmul__ = __mul__ + + def __iadd__(self, iterable): + self.extend(iterable) + return self + + def __imul__(self, n): + # unlike a regular list *=, proxied __imul__ will generate unique + # backing objects for each copy. *= on proxied lists is a bit of + # a stretch anyhow, and this interpretation of the __imul__ contract + # is more plausibly useful than copying the backing objects. + if not isinstance(n, int): + return NotImplemented + if n == 0: + self.clear() + elif n > 1: + self.extend(list(self) * (n - 1)) + return self + def copy(self): return list(self) |