dfd042c7.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. dfd042c7
  3. SQLAlchemy 0.5.8 version of a805d4bd, see the docstring of that module
  4. for an explanation of this workaround.
  5. """
  6. from sqlalchemy.types import PickleType as _PickleType
  7. from sqlalchemy import util
  8. class PickleType(_PickleType):
  9. def process_bind_param(self, value, dialect):
  10. dumps = self.pickler.dumps
  11. protocol = self.protocol
  12. if value is None:
  13. return None
  14. return dumps(value, protocol)
  15. def process_result_value(self, value, dialect):
  16. loads = self.pickler.loads
  17. if value is None:
  18. return None
  19. return loads(str(value))
  20. def copy_value(self, value):
  21. if self.mutable:
  22. return self.pickler.loads(self.pickler.dumps(value, self.protocol))
  23. else:
  24. return value
  25. def compare_values(self, x, y):
  26. if self.comparator:
  27. return self.comparator(x, y)
  28. elif self.mutable and not hasattr(x, '__eq__') and x is not None:
  29. util.warn_deprecated(
  30. "Objects stored with PickleType when mutable=True "
  31. "must implement __eq__() for reliable comparison.")
  32. a = self.pickler.dumps(x, self.protocol)
  33. b = self.pickler.dumps(y, self.protocol)
  34. return a == b
  35. else:
  36. return x == y
  37. def is_mutable(self):
  38. return self.mutable