Created
November 25, 2008 16:31
-
-
Save darwin/28971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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