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


Python ndb.LocalStructuredProperty方法代码示例

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


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

示例1: _test_repeated_structured_properties_class

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import LocalStructuredProperty [as 别名]
def _test_repeated_structured_properties_class(self, structured_cls):
    """Common testing for StructuredProperty and LocalStructuredProperty."""
    class Inner(ndb.Model):
      a = ndb.IntegerProperty()

    class Outter(ndb.Model, serializable.SerializableModelMixin):
      inner = structured_cls(Inner, repeated=True)

    # Repeated structured property -> list of dicts.
    entity = Outter()
    entity.inner.extend([Inner(a=1), Inner(a=2)])
    self.assertEqual(
        {'inner': [{'a': 1}, {'a': 2}]},
        entity.to_serializable_dict())

    # Reverse also works.
    self.assertEqual(
        entity,
        Outter.from_serializable_dict({'inner': [{'a': 1}, {'a': 2}]})) 
开发者ID:luci,项目名称:luci-py,代码行数:21,代码来源:serializable_test.py

示例2: get_property_converter

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import LocalStructuredProperty [as 别名]
def get_property_converter(self, prop):
    """Returns callable that can convert values corresponding to ndb property.

    Args:
      prop: instance of ndb.Property subclass that defines typing information.

    Returns:
      Callable (property instance, incoming value) -> converter values.
    """
    # For structured properties, recursively call convert_dict.
    if isinstance(prop, (ndb.StructuredProperty, ndb.LocalStructuredProperty)):
      return lambda prop, x: self.convert_dict(prop._modelclass, x)
    # For other properties consult the registry of converters.
    for prop_cls, include_subclasses, conv in self.property_converters:
      # pylint: disable=unidiomatic-typecheck
      if (include_subclasses and isinstance(prop, prop_cls) or
          not include_subclasses and type(prop) == prop_cls):
        return conv
    # Give up.
    raise TypeError('Don\'t know how to work with %s' % type(prop).__name__)


### Public API. 
开发者ID:luci,项目名称:luci-py,代码行数:25,代码来源:serializable.py

示例3: __init__

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import LocalStructuredProperty [as 别名]
def __init__(self, **kwargs):
    # This is the recommended way to use ndb.LocalStructuredProperty inside a
    # snapshot.
    #
    # Warning: The only reason it works is because Snapshot is itself inside a
    # ndb.LocalStructuredProperty.
    kwargs.setdefault('inner', InnerSnapshot())
    super(Snapshot, self).__init__(**kwargs) 
开发者ID:luci,项目名称:luci-py,代码行数:10,代码来源:stats_framework_test.py

示例4: test_local_structured_properties

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import LocalStructuredProperty [as 别名]
def test_local_structured_properties(self):
    """Test handling of LocalStructuredProperty."""
    self._test_structured_properties_class(ndb.LocalStructuredProperty) 
开发者ID:luci,项目名称:luci-py,代码行数:5,代码来源:serializable_test.py

示例5: test_repeated_local_structured_properties

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import LocalStructuredProperty [as 别名]
def test_repeated_local_structured_properties(self):
    """Test handling of LocalStructuredProperty(repeated=True)."""
    self._test_repeated_structured_properties_class(ndb.LocalStructuredProperty) 
开发者ID:luci,项目名称:luci-py,代码行数:5,代码来源:serializable_test.py

示例6: _pre_put_hook

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import LocalStructuredProperty [as 别名]
def _pre_put_hook(self):
    if not self.server:
      raise datastore_errors.BadValueError('cipd server is required')
    if not self.client_package:
      raise datastore_errors.BadValueError('client_package is required')
    if self.client_package.path:
      raise datastore_errors.BadValueError('client_package.path must be unset')
    # _pre_put_hook() doesn't recurse correctly into
    # ndb.LocalStructuredProperty. Call the function manually.
    self.client_package._pre_put_hook()

    if not self.packages:
      raise datastore_errors.BadValueError(
          'cipd_input cannot have an empty package list')
    if len(self.packages) > 64:
      raise datastore_errors.BadValueError(
          'Up to 64 CIPD packages can be listed for a task')

    # Make sure we don't install multiple versions of the same package at the
    # same path.
    package_path_names = set()
    for p in self.packages:
      # _pre_put_hook() doesn't recurse correctly into
      # ndb.LocalStructuredProperty. Call the function manually.
      p._pre_put_hook()
      if not p.path:
        raise datastore_errors.BadValueError(
            'package %s:%s: path is required' % (p.package_name, p.version))
      path_name = (p.path, p.package_name)
      if path_name in package_path_names:
        raise datastore_errors.BadValueError(
           'package %r is specified more than once in path %r'
          % (p.package_name, p.path))
      package_path_names.add(path_name)
    self.packages.sort(key=lambda p: (p.path, p.package_name)) 
开发者ID:luci,项目名称:luci-py,代码行数:37,代码来源:task_request.py

示例7: to_dict

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import LocalStructuredProperty [as 别名]
def to_dict(self):
    # to_dict() doesn't recurse correctly into ndb.LocalStructuredProperty! It
    # will call the default method and not the overridden one. :(
    out = super(TaskSlice, self).to_dict(exclude=['properties'])
    out['properties'] = self.properties.to_dict()
    return out 
开发者ID:luci,项目名称:luci-py,代码行数:8,代码来源:task_request.py

示例8: _test_structured_properties_class

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import LocalStructuredProperty [as 别名]
def _test_structured_properties_class(self, structured_cls):
    """Common testing for StructuredProperty and LocalStructuredProperty."""
    # Plain ndb.Model.
    class InnerSimple(ndb.Model):
      a = ndb.IntegerProperty()

    # With SerializableModelMixin.
    class InnerSmart(ndb.Model, serializable.SerializableModelMixin):
      serializable_properties = {
        'a': serializable.READABLE | serializable.WRITABLE,
      }
      a = ndb.IntegerProperty()
      b = ndb.IntegerProperty()

    class Outter(ndb.Model, serializable.SerializableModelMixin):
      simple = structured_cls(InnerSimple)
      smart = structured_cls(InnerSmart)

    # InnerSimple gets serialized entirely, while only readable fields
    # on InnerSmart are serialized.
    entity = Outter()
    entity.simple = InnerSimple(a=1)
    entity.smart = InnerSmart(a=2, b=3)
    self.assertEqual(
        {'simple': {'a': 1}, 'smart': {'a': 2}},
        entity.to_serializable_dict())

    # Works backwards as well. Note that 'convert_serializable_dict' returns
    # a dictionary that can be fed to entity's 'populate' or constructor. Entity
    # by itself is smart enough to transform subdicts into structured
    # properties.
    self.assertEqual(
        Outter(simple=InnerSimple(a=1), smart=InnerSmart(a=2)),
        Outter.from_serializable_dict({'simple': {'a': 1}, 'smart': {'a': 2}})) 
开发者ID:luci,项目名称:luci-py,代码行数:36,代码来源:serializable_test.py

示例9: _generate_stats_day_cls

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import LocalStructuredProperty [as 别名]
def _generate_stats_day_cls(snapshot_cls):
  class StatsDay(ndb.Model):
    """Statistics for the whole day.

    The Key format is YYYY-MM-DD with 0 prefixes so the key sort naturally.
    Ancestor is StatsRoot.

    This entity is updated every time a new self.stats_hour_cls is sealed, so ~1
    update per hour.
    """
    # Disable ndb in-process cache.
    _use_cache = False

    created = ndb.DateTimeProperty(indexed=False, auto_now=True)
    modified = ndb.DateTimeProperty(indexed=False, auto_now_add=True)

    # Statistics for the day.
    values_compressed = ndb.LocalStructuredProperty(
        snapshot_cls, compressed=True, name='values_c')
    # This is needed for backward compatibility
    values_uncompressed = ndb.LocalStructuredProperty(
        snapshot_cls, name='values')

    # Hours that have been summed. A complete day will be set to (1<<24)-1, e.g.
    # 0xFFFFFF, e.g. 24 bits or 6x4 bits.
    hours_bitmap = ndb.IntegerProperty(default=0)

    # Used for queries.
    SEALED_BITMAP = 0xFFFFFF

    # The span of this snapshot.
    span = datetime.timedelta(seconds=24*60*60)

    @property
    def values(self):
      return self.values_compressed or self.values_uncompressed

    @property
    def timestamp(self):
      """Returns a datetime.datetime representing the start of the period
      covered.
      """
      year, month, day = self.key.id().split('-', 2)
      return datetime.datetime(int(year), int(month), int(day))

    @property
    def timestamp_str(self):
      """Returns the timestamp as a string."""
      return self.key.string_id()

    def to_dict(self):
      out = self.values.to_dict()
      out['key'] = self.timestamp_str
      return out

    def _pre_put_hook(self):
      if bool(self.values_compressed) == bool(self.values_uncompressed):
        raise datastore_errors.BadValueError('Invalid object')

  return StatsDay 
开发者ID:luci,项目名称:luci-py,代码行数:62,代码来源:__init__.py


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