summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-09-22 15:55:02 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-09-22 15:55:02 +0000
commit7f6bf93da869a5b59c53d0d10a50da3c23c4b738 (patch)
treed166f0ed44e4b1b51de1ad28f2bfc56d8b565cfd /lib/sqlalchemy
parent927d5d8929ad865182d6c6815dd5df8875777ceb (diff)
downloadsqlalchemy-7f6bf93da869a5b59c53d0d10a50da3c23c4b738.tar.gz
- added 'comparator' keyword argument to PickleType. By default, "mutable"
PickleType does a "deep compare" of objects using their dumps() representation. But this doesn't work for dictionaries. Pickled objects which provide an adequate __eq__() implementation can be set up with "PickleType(comparator=operator.eq)" [ticket:560]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/types.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index 833d2cf15..71b4bbec1 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -421,10 +421,11 @@ class Binary(TypeEngine):
class PickleType(MutableType, TypeDecorator):
impl = Binary
- def __init__(self, protocol=pickle.HIGHEST_PROTOCOL, pickler=None, mutable=True):
+ def __init__(self, protocol=pickle.HIGHEST_PROTOCOL, pickler=None, mutable=True, comparator=None):
self.protocol = protocol
self.pickler = pickler or pickle
self.mutable = mutable
+ self.comparator = comparator
super(PickleType, self).__init__()
def bind_processor(self, dialect):
@@ -455,7 +456,9 @@ class PickleType(MutableType, TypeDecorator):
return value
def compare_values(self, x, y):
- if self.mutable:
+ if self.comparator:
+ return self.comparator(x, y)
+ elif self.mutable:
return self.pickler.dumps(x, self.protocol) == self.pickler.dumps(y, self.protocol)
else:
return x is y