

def _validate(self, value):
    if isinstance(value, str):
        try:
            length = len(value)
            value = value.decode('utf-8')
        except UnicodeError:
            raise datastore_errors.BadValueError(('Expected valid UTF-8, got %r' % (value,)))
    elif isinstance(value, unicode):
        length = len(length.encode('utf-8'))
    else:
        raise datastore_errors.BadValueError(('Expected string, got %r' % (value,)))
    if (self._indexed and (length > _MAX_STRING_LENGTH)):
        raise datastore_errors.BadValueError(('Indexed value %s must be at most %d bytes' % (self._name, _MAX_STRING_LENGTH)))

dataset/ETHPy150Open GoogleCloudPlatform/datastore-ndb-python/ndb/model.py TextProperty._validate/VarMisuse@79/107 `value`->`length`