Created
May 27, 2013 14:01
-
-
Save fredrikbonander/5657223 to your computer and use it in GitHub Desktop.
Ndb StringProperty validation
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
def _validate(self, value): | |
if isinstance(value, str): | |
# Decode from UTF-8 -- if this fails, we can't write it. | |
try: | |
value = unicode(value, 'utf-8') | |
except UnicodeError: | |
raise datastore_errors.BadValueError('Expected valid UTF-8, got %r' % | |
(value,)) | |
elif not isinstance(value, unicode): | |
raise datastore_errors.BadValueError('Expected string, got %r' % | |
(value,)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment