當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。