Skip to content

Instantly share code, notes, and snippets.

@darwin
Created November 25, 2008 16:31
Show Gist options
  • Save darwin/28971 to your computer and use it in GitHub Desktop.
Save darwin/28971 to your computer and use it in GitHub Desktop.
class PickleProperty(db.TextProperty):
def get_value_for_datastore(self, model_instance):
value = self.__get__(model_instance, model_instance.__class__)
return db.Text(self._deflate(value))
def validate(self, value):
return value
def make_value_from_datastore(self, value):
return self._inflate(value)
def _inflate(self, value):
try:
val = pickle.loads(base64.decodestring(unicode(value)))
except:
val = ""
return val
def _deflate(self, value):
val = pickle.dumps(value)
return base64.encodestring(val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment