本文整理匯總了Python中google.appengine.ext.ndb.BlobProperty方法的典型用法代碼示例。如果您正苦於以下問題:Python ndb.BlobProperty方法的具體用法?Python ndb.BlobProperty怎麽用?Python ndb.BlobProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.appengine.ext.ndb
的用法示例。
在下文中一共展示了ndb.BlobProperty方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _db_set_value
# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import BlobProperty [as 別名]
def _db_set_value(self, v, p, value):
# From BlobProperty.
p.set_meaning(ndb.google_imports.entity_pb.Property.BYTESTRING)
v.set_stringvalue(value)
示例2: test_simple_properties
# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import BlobProperty [as 別名]
def test_simple_properties(self):
"""Simple properties are unmodified in to_serializable_dict()."""
class Entity(ndb.Model, serializable.SerializableModelMixin):
blob_prop = ndb.BlobProperty()
bool_prop = ndb.BooleanProperty()
float_prop = ndb.FloatProperty()
int_prop = ndb.IntegerProperty()
json_prop = ndb.JsonProperty()
pickle_prop = ndb.PickleProperty()
str_prop = ndb.StringProperty()
text_prop = ndb.TextProperty()
# Test data in simple dict form.
as_serializable_dict = {
'blob_prop': 'blob',
'bool_prop': True,
'float_prop': 3.14,
'int_prop': 42,
'json_prop': ['a list', 'why', 'not?'],
'pickle_prop': {'some': 'dict'},
'str_prop': 'blah-blah',
'text_prop': 'longer blah-blah',
}
# Same data but in entity form. Constructing entity directly from
# |as_serializable_dict| works only if it contains only simple properties
# (that look the same in serializable dict and entity form).
as_entity = Entity(**as_serializable_dict)
# Ensure all simple properties (from _SIMPLE_PROPERTIES) are covered.
self.assertEqual(
set(serializable._SIMPLE_PROPERTIES),
set(prop.__class__ for prop in Entity._properties.values()))
# Check entity -> serializable dict conversion.
self.assertEqual(
as_serializable_dict,
as_entity.to_serializable_dict())
# Check serializable dict -> Entity conversion.
self.assertEqual(
as_entity,
Entity.from_serializable_dict(as_serializable_dict))
示例3: get_historical_copy_class
# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import BlobProperty [as 別名]
def get_historical_copy_class(cls):
"""Returns entity class for historical copies of original entity.
Has all the same properties, but unindexed (not needed), unvalidated
(original entity is already validated) and not cached.
The name of the new entity class is "<original name>History" (to make sure
it doesn't show up in indexes for original entity class).
"""
existing = getattr(cls, '_auth_db_historical_copy_cls', None)
if existing:
return existing
props = {}
for name, prop in cls._properties.items():
# Whitelist supported property classes. Better to fail loudly when
# encountering something new, rather than silently produce (possibly)
# incorrect result. Note that all AuthDB classes are instantiated in
# unit tests, so there should be no unexpected asserts in production.
assert prop.__class__ in (
datastore_utils.ProtobufProperty,
IdentityGlobProperty,
IdentityProperty,
ndb.BlobProperty,
ndb.BooleanProperty,
ndb.DateTimeProperty,
ndb.IntegerProperty,
ndb.LocalStructuredProperty,
ndb.StringProperty,
ndb.TextProperty,
), prop.__class__
kwargs = {
'name': prop._name,
'indexed': False,
'required': False,
'repeated': prop._repeated,
}
if prop.__class__ == datastore_utils.ProtobufProperty:
kwargs.update({
'message_class': prop._message_class,
'compressed': prop._compressed,
})
elif prop.__class__ == ndb.LocalStructuredProperty:
kwargs['modelclass'] = prop._modelclass
props[name] = prop.__class__(**kwargs)
new_cls = type(
'%sHistory' % cls.__name__, (_AuthDBHistoricalEntity,), props)
cls._auth_db_historical_copy_cls = new_cls
return new_cls