Beispiel #1
0
 def _validate(self, value):
     if not isinstance(value, str):
         raise errors.BadValueError('Expected str, got %r' % (value, ))
     if (self._indexed and not isinstance(self, TextProperty)
             and len(value) > _MAX_STRING_LENGTH):
         raise errors.BadValueError(
             'Indexed value %s must be at most %d bytes' %
             (self._name, _MAX_STRING_LENGTH))
Beispiel #2
0
 def _validate(self, value):
     if not isinstance(value, Key):
         raise errors.BadValueError('Expected Key, got %r' % (value, ))
     # Reject incomplete keys.
     if not value.id():
         raise errors.BadValueError('Expected complete Key, got %r' %
                                    (value, ))
     if self._kind is not None:
         if value.kind() != self._kind:
             raise errors.BadValueError(
                 'Expected Key with kind=%r, got %r' % (self._kind, value))
Beispiel #3
0
 def _validate(self, value):
     if isinstance(value, dict):
         # A dict is assumed to be the result of a _to_dict() call.
         return self._modelclass(**value)
     if not isinstance(value, self._modelclass):
         raise errors.BadValueError('Expected %s instance, got %r' %
                                    (self._modelclass.__name__, value))
Beispiel #4
0
 def _validate(self, value):
     if isinstance(value, str):
         # Decode from UTF-8 -- if this fails, we can't write it.
         try:
             length = len(value)
             value = value.decode('utf-8')
         except UnicodeError:
             raise errors.BadValueError('Expected valid UTF-8, got %r' %
                                        (value, ))
     elif isinstance(value, unicode):
         length = len(value.encode('utf-8'))
     else:
         raise errors.BadValueError('Expected string, got %r' % (value, ))
     if self._indexed and length > _MAX_STRING_LENGTH:
         raise errors.BadValueError(
             'Indexed value %s must be at most %d bytes' %
             (self._name, _MAX_STRING_LENGTH))
Beispiel #5
0
 def _validate(self, value):
     if self._indexed:
         if isinstance(value, unicode):
             value = value.encode('utf-8')
         if isinstance(value,
                       basestring) and len(value) > _MAX_STRING_LENGTH:
             raise errors.BadValueError(
                 'Indexed value %s must be at most %d bytes' %
                 (self._name, _MAX_STRING_LENGTH))
Beispiel #6
0
 def _validate(self, value):
     if not isinstance(value, (int, long, float)):
         raise errors.BadValueError('Expected float, got %r' % (value, ))
     return float(value)
Beispiel #7
0
 def _validate(self, value):
     if not isinstance(value, (int, long)):
         raise errors.BadValueError('Expected integer, got %r' % (value, ))
     return int(value)
Beispiel #8
0
 def _validate(self, value):
     if not isinstance(value, datetime.time):
         raise errors.BadValueError('Expected time, got %r' % (value, ))
Beispiel #9
0
 def _validate(self, value):
     if not isinstance(value, datastore_types.BlobKey):
         raise errors.BadValueError('Expected BlobKey, got %r' % (value, ))
Beispiel #10
0
 def _validate(self, value):
     if not isinstance(value, bool):
         raise errors.BadValueError('Expected bool, got %r' % (value, ))
     return value
Beispiel #11
0
 def _validate(self, value):
     if not isinstance(value, users.User):
         raise errors.BadValueError('Expected User, got %r' % (value, ))
Beispiel #12
0
 def _validate(self, value):
     if not isinstance(value, GeoPt):
         raise errors.BadValueError('Expected GeoPt, got %r' % (value, ))
Beispiel #13
0
 def _comparison(self, op, value):
     if value is not None:
         return super(ModelKey, self)._comparison(op, value)
     raise errors.BadValueError(
         "__key__ filter query can't be compared to None")