当前位置: 首页>>代码示例>>Python>>正文


Python datastore_errors.BadValueError方法代码示例

本文整理汇总了Python中google.appengine.api.datastore_errors.BadValueError方法的典型用法代码示例。如果您正苦于以下问题:Python datastore_errors.BadValueError方法的具体用法?Python datastore_errors.BadValueError怎么用?Python datastore_errors.BadValueError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.api.datastore_errors的用法示例。


在下文中一共展示了datastore_errors.BadValueError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def create(self, request):
    """Creates a new tag and inserts the instance into datastore."""
    self.check_xsrf_token(self.request_state)
    try:
      tag_model.Tag.create(
          user_email=user.get_user_email(),
          name=request.tag.name,
          hidden=request.tag.hidden,
          color=request.tag.color,
          protect=request.tag.protect,
          description=request.tag.description)
    except datastore_errors.BadValueError as err:
      raise endpoints.BadRequestException(
          'Tag creation failed due to: %s' % err)

    return message_types.VoidMessage() 
开发者ID:google,项目名称:loaner,代码行数:18,代码来源:tag_api.py

示例2: update

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def update(self, request):
    """Updates an existing tag."""
    self.check_xsrf_token(self.request_state)
    key = api_utils.get_ndb_key(urlsafe_key=request.tag.urlsafe_key)
    tag = key.get()
    if tag.protect:
      raise endpoints.BadRequestException(
          'Cannot update tag %s because it is protected.' % tag.name)
    try:
      tag.update(
          user_email=user.get_user_email(),
          name=request.tag.name,
          hidden=request.tag.hidden,
          protect=request.tag.protect,
          color=request.tag.color,
          description=request.tag.description)
    except datastore_errors.BadValueError as err:
      raise endpoints.BadRequestException(
          'Tag update failed due to: %s' % str(err))
    return message_types.VoidMessage() 
开发者ID:google,项目名称:loaner,代码行数:22,代码来源:tag_api.py

示例3: enroll

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def enroll(self, request):
    """Enrolls a shelf in the program."""
    user_email = user.get_user_email()
    self.check_xsrf_token(self.request_state)
    try:
      shelf_model.Shelf.enroll(
          user_email=user_email,
          friendly_name=request.friendly_name,
          location=request.location,
          latitude=request.latitude,
          longitude=request.longitude,
          altitude=request.altitude,
          capacity=request.capacity,
          audit_notification_enabled=request.audit_notification_enabled,
          responsible_for_audit=request.responsible_for_audit,
          audit_interval_override=request.audit_interval_override,
      )
    except (shelf_model.EnrollmentError, datastore_errors.BadValueError) as err:
      raise endpoints.BadRequestException(str(err))

    return message_types.VoidMessage() 
开发者ID:google,项目名称:loaner,代码行数:23,代码来源:shelf_api.py

示例4: create

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def create(cls, name, title=None, body=None):
    """Creates a model and entity."""
    if not name:
      raise datastore_errors.BadValueError(
          'The Template name must not be empty.')
    entity = cls(title=title,
                 body=body)
    template = cls.get_by_id(name)
    if template is not None:
      raise datastore_errors.BadValueError(
          'Create template: A Template entity with name %r already exists.' %
          name)
    entity.key = ndb.Key(cls, name)
    entity.put()
    logging.info('Creating a new template with name %r.', name)
    cls.cached_templates = []
    return entity 
开发者ID:google,项目名称:loaner,代码行数:19,代码来源:template_model.py

示例5: update

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def update(self, user_email, **kwargs):
    """Updates an existing tag.

    Args:
      user_email: str, email of the user creating the tag.
      **kwargs: kwargs for the update API.

    Raises:
      datastore_errors.BadValueError: If the tag name is an empty string.
    """
    if not kwargs['name']:
      raise datastore_errors.BadValueError('The tag name must not be empty.')

    if kwargs['name'] != self.name:
      logging.info(
          'Renaming the tag with name %r to %r.', self.name, kwargs['name'])

    self.populate(**kwargs)
    self.put()
    logging.info(
        'Updating a tag with urlsafe key %r and name %r.',
        self.key.urlsafe(), self.name)
    self.stream_to_bq(
        user_email, 'Updated a tag with name %r.' % self.name) 
开发者ID:google,项目名称:loaner,代码行数:26,代码来源:tag_model.py

示例6: get_datastore_cursor

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def get_datastore_cursor(urlsafe_cursor):
  """Builds a datastore.Cursor from a urlsafe cursor.

  Args:
    urlsafe_cursor: str, The urlsafe representation of a datastore.Cursor.

  Returns:
    datastore.Cursor instance.

  Raises:
    endpoints.BadRequestException: if the creation of the datastore.Cursor
        fails.
  """
  try:
    return datastore_query.Cursor(urlsafe=urlsafe_cursor)
  except datastore_errors.BadValueError:
    raise endpoints.BadRequestException(_MALFORMED_PAGE_TOKEN_MSG) 
开发者ID:google,项目名称:loaner,代码行数:19,代码来源:api_utils.py

示例7: validate

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def validate(self, value):
    """Validate value.

    Args:
      value: model value.

    Returns:
      Whether the specified value is valid data type value.

    Raises:
      BadValueError: when value is not of self.data_type type.
    """
    if value is not None and not isinstance(value, self.data_type):
      raise datastore_errors.BadValueError(
          "Property %s must be convertible to a %s instance (%s)" %
          (self.name, self.data_type, value))
    return super(JsonProperty, self).validate(value) 
开发者ID:elsigh,项目名称:browserscope,代码行数:19,代码来源:model.py

示例8: validate

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def validate(self, value):
    """Validate value.

    Args:
      value: model value.

    Returns:
      Whether the specified value is valid data type value.

    Raises:
      BadValueError: when value is not of self.data_type type.
    """
    if value is not None and not isinstance(value, self.data_type):
      raise datastore_errors.BadValueError(
          "Property %s must be convertible to a %s instance (%s)" % 
          (self.name, self.data_type, value))
    return super(JsonProperty, self).validate(value) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:19,代码来源:json_util.py

示例9: _pre_put_hook

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def _pre_put_hook(self):
    super(BqState, self)._pre_put_hook()
    if bool(self.recent) != bool(self.oldest):
      raise datastore_errors.BadValueError(
          'Internal error; recent and oldest must both be set')
    if self.oldest:
      if self.oldest >= self.recent:
        raise datastore_errors.BadValueError('Internal error; oldest >= recent')
      if self.oldest.second or self.oldest.microsecond:
        raise datastore_errors.BadValueError(
            'Internal error; oldest has seconds')
      if self.recent.second or self.recent.microsecond:
        raise datastore_errors.BadValueError(
            'Internal error; recent has seconds')


### Private APIs. 
开发者ID:luci,项目名称:luci-py,代码行数:19,代码来源:bq_state.py

示例10: test_BqState

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def test_BqState(self):
    now = datetime.datetime(2020, 1, 2, 3, 4)
    bq_state.BqState(id='foo').put()
    bq_state.BqState(
        id='foo', recent=now,
        oldest=now - datetime.timedelta(seconds=60)).put()
    with self.assertRaises(datastore_errors.BadValueError):
      bq_state.BqState(id='foo', oldest=now).put()
    with self.assertRaises(datastore_errors.BadValueError):
      bq_state.BqState(id='foo', recent=now).put()
    with self.assertRaises(datastore_errors.BadValueError):
      bq_state.BqState(id='foo', recent=now, oldest=now).put()
    with self.assertRaises(datastore_errors.BadValueError):
      bq_state.BqState(id='foo', recent=now, oldest=now).put()
    with self.assertRaises(datastore_errors.BadValueError):
      bq_state.BqState(
          id='foo',
          recent=now - datetime.timedelta(seconds=60.1),
          oldest=now - datetime.timedelta(seconds=60)).put() 
开发者ID:luci,项目名称:luci-py,代码行数:21,代码来源:bq_state_test.py

示例11: test_new_run_result_duration_no_exit_code

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def test_new_run_result_duration_no_exit_code(self):
    request = _gen_request()
    to_run = task_to_run.new_task_to_run(request, 0)
    actual = task_result.new_run_result(request, to_run, u'localhost', u'abc', {
        u'id': [u'localhost'],
        u'foo': [u'bar', u'biz']
    })
    actual.completed_ts = self.now
    actual.modified_ts = self.now
    actual.started_ts = self.now
    actual.duration = 1.
    actual.state = task_result.State.COMPLETED
    # Trigger _pre_put_hook().
    with self.assertRaises(datastore_errors.BadValueError):
      actual.put()
    actual.state = task_result.State.TIMED_OUT
    actual.put()
    expected = self._gen_result(
        completed_ts=self.now,
        duration=1.,
        modified_ts=self.now,
        failure=True,
        started_ts=self.now,
        state=task_result.State.TIMED_OUT)
    self.assertEqual(expected, actual.to_dict()) 
开发者ID:luci,项目名称:luci-py,代码行数:27,代码来源:task_result_test.py

示例12: test_BotTaskDimensions

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def test_BotTaskDimensions(self):
    cls = task_queues.BotTaskDimensions
    now = datetime.datetime(2010, 1, 2, 3, 4, 5)
    with self.assertRaises(datastore_errors.BadValueError):
      cls(dimensions_flat=['a:b']).put()
    with self.assertRaises(datastore_errors.BadValueError):
      cls(valid_until_ts=now).put()
    with self.assertRaises(datastore_errors.BadValueError):
      cls(valid_until_ts=now, dimensions_flat=['a:b', 'a:b']).put()
    with self.assertRaises(datastore_errors.BadValueError):
      cls(valid_until_ts=now, dimensions_flat=['c:d', 'a:b']).put()

    a = cls(valid_until_ts=now, dimensions_flat=['a:b'])
    a.put()
    self.assertEqual(True, a.is_valid({'a': ['b']}))
    self.assertEqual(True, a.is_valid({'a': ['b', 'c']}))
    self.assertEqual(False, a.is_valid({'x': ['c']})) 
开发者ID:luci,项目名称:luci-py,代码行数:19,代码来源:task_queues_test.py

示例13: test_TaskDimensions

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def test_TaskDimensions(self):
    cls = task_queues.TaskDimensions
    setcls = task_queues.TaskDimensionsSet
    now = datetime.datetime(2010, 1, 2, 3, 4, 5)
    with self.assertRaises(datastore_errors.BadValueError):
      cls().put()
    with self.assertRaises(datastore_errors.BadValueError):
      cls(sets=[setcls(valid_until_ts=now)]).put()
    with self.assertRaises(datastore_errors.BadValueError):
      cls(sets=[setcls(dimensions_flat=['a:b'])]).put()
    with self.assertRaises(datastore_errors.BadValueError):
      cls(sets=[
        setcls(valid_until_ts=now, dimensions_flat=['a:b', 'a:b'])]).put()
    with self.assertRaises(datastore_errors.BadValueError):
      cls(sets=[
        setcls(valid_until_ts=now, dimensions_flat=['c:d', 'a:b'])]).put()
    with self.assertRaises(datastore_errors.BadValueError):
      cls(sets=[
        setcls(valid_until_ts=now, dimensions_flat=['a:b', 'c:d']),
        setcls(valid_until_ts=now, dimensions_flat=['a:b', 'c:d']),
        ]).put()
    cls(sets=[setcls(valid_until_ts=now, dimensions_flat=['a:b'])]).put() 
开发者ID:luci,项目名称:luci-py,代码行数:24,代码来源:task_queues_test.py

示例14: test_request_bad_named_cache_and_cipd_input

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def test_request_bad_named_cache_and_cipd_input(self):
    # A CIPD package and named caches cannot be mapped to the same path.
    req = _gen_request(
        properties=_gen_properties(
            caches=[
              task_request.CacheEntry(name='git_chromium', path='git_cache'),
            ],
            cipd_input=_gen_cipd_input(
                packages=[
                  task_request.CipdPackage(
                      package_name='foo', path='git_cache', version='latest'),
                ])))
    with self.assertRaises(datastore_errors.BadValueError):
      req.put()
    req = _gen_request(
        properties=_gen_properties(
            caches=[
                task_request.CacheEntry(name='git_chromium', path='git_cache1'),
            ],
            cipd_input=_gen_cipd_input(packages=[
                task_request.CipdPackage(
                    package_name='foo', path='git_cache2', version='latest'),
            ]))).put() 
开发者ID:luci,项目名称:luci-py,代码行数:25,代码来源:task_request_test.py

示例15: test_request_bad_execution_timeout

# 需要导入模块: from google.appengine.api import datastore_errors [as 别名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 别名]
def test_request_bad_execution_timeout(self):
    # When used locally, it is set to 1, which means it's impossible to test
    # below _MIN_TIMEOUT_SECS but above 0.
    self.mock(task_request, '_MIN_TIMEOUT_SECS', 30)
    p = _gen_request(properties=_gen_properties(execution_timeout_secs=0))
    with self.assertRaises(datastore_errors.BadValueError):
      # Only termination task may have 0.
      p.put()
    with self.assertRaises(datastore_errors.BadValueError):
      _gen_request(
          properties=_gen_properties(
            execution_timeout_secs=task_request._MIN_TIMEOUT_SECS-1))
    _gen_request(
        properties=_gen_properties(
          execution_timeout_secs=task_request._MIN_TIMEOUT_SECS))
    with self.assertRaises(datastore_errors.BadValueError):
      _gen_request(
          properties=_gen_properties(
              execution_timeout_secs=task_request.MAX_TIMEOUT_SECS+1))
    _gen_request(
        properties=_gen_properties(
            execution_timeout_secs=task_request.MAX_TIMEOUT_SECS)).put() 
开发者ID:luci,项目名称:luci-py,代码行数:24,代码来源:task_request_test.py


注:本文中的google.appengine.api.datastore_errors.BadValueError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。