本文整理汇总了Python中protorpc.messages.MessageField方法的典型用法代码示例。如果您正苦于以下问题:Python messages.MessageField方法的具体用法?Python messages.MessageField怎么用?Python messages.MessageField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类protorpc.messages
的用法示例。
在下文中一共展示了messages.MessageField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testNestedMessageField
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testNestedMessageField(self):
class Inner(messages.Message):
count = messages.IntegerField(1)
greet = messages.MessageField(Greeting, 2)
class Outer(messages.Message):
inner = messages.MessageField(Inner, 1)
extra = messages.StringField(2)
class Store(model.Model):
outer = msgprop.MessageProperty(Outer,
indexed_fields=['inner.greet.text'])
greet = Greeting(text='abc', when=123)
inner = Inner(count=42, greet=greet)
outer = Outer(inner=inner)
st = Store(outer=outer)
st.put()
res = Store.query(Store.outer.inner.greet.text == 'abc').fetch()
self.assertEqual(res, [st])
示例2: testRepeatedNestedMessageField
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testRepeatedNestedMessageField(self):
class Outer(messages.Message):
greeting = messages.MessageField(Greeting, 1)
extra = messages.IntegerField(2)
class Store(model.Model):
outers = msgprop.MessageProperty(Outer, repeated=True,
indexed_fields=['greeting.text'])
gr1 = Greeting(text='abc', when=123)
gr2 = Greeting(text='def', when=456)
outer1 = Outer(greeting=gr1, extra=1)
outer2 = Outer(greeting=gr2, extra=2)
store1 = Store(outers=[outer1])
store1.put()
store2 = Store(outers=[outer2])
store2.put()
store3 = Store(outers=[outer1, outer2])
store3.put()
res = Store.query(Store.outers.greeting.text == 'abc').fetch()
self.assertEqual(res, [store1, store3])
示例3: testNestedRepeatedMessageField
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testNestedRepeatedMessageField(self):
class Outer(messages.Message):
greetings = messages.MessageField(Greeting, 1, repeated=True)
extra = messages.IntegerField(2)
class Store(model.Model):
outer = msgprop.MessageProperty(Outer, indexed_fields=['greetings.text',
'extra'])
gr1 = Greeting(text='abc', when=123)
gr2 = Greeting(text='def', when=456)
outer1 = Outer(greetings=[gr1], extra=1)
outer2 = Outer(greetings=[gr2], extra=2)
outer3 = Outer(greetings=[gr1, gr2], extra=3)
store1 = Store(outer=outer1)
store1.put()
store2 = Store(outer=outer2)
store2.put()
store3 = Store(outer=outer3)
store3.put()
res = Store.query(Store.outer.greetings.text == 'abc').fetch()
self.assertEqual(res, [store1, store3])
示例4: testNestedFieldErrors
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testNestedFieldErrors(self):
class Outer(messages.Message):
greetings = messages.MessageField(Greeting, 1, repeated=True)
extra = messages.IntegerField(2)
# Parent/child conflicts.
self.assertRaises(ValueError, msgprop.MessageProperty,
Outer, indexed_fields=['greetings.text', 'greetings'])
self.assertRaises(ValueError, msgprop.MessageProperty,
Outer, indexed_fields=['greetings', 'greetings.text'])
# Duplicate inner field.
self.assertRaises(ValueError, msgprop.MessageProperty,
Outer, indexed_fields=['greetings.text',
'greetings.text'])
# Can't index MessageField.
self.assertRaises(ValueError, msgprop.MessageProperty,
Outer, indexed_fields=['greetings'])
# Can't specify subfields for non-MessageField.
self.assertRaises(ValueError, msgprop.MessageProperty,
Outer, indexed_fields=['extra.foobar'])
# Non-existent subfield.
self.assertRaises(ValueError, msgprop.MessageProperty,
Outer, indexed_fields=['greetings.foobar'])
示例5: testProjectionQueries
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testProjectionQueries(self):
class Wrapper(messages.Message):
greet = messages.MessageField(Greeting, 1)
class Storage(model.Model):
wrap = msgprop.MessageProperty(Wrapper, indexed_fields=['greet.text',
'greet.when'])
gr1 = Greeting(text='abc', when=123)
wr1 = Wrapper(greet=gr1)
st1 = Storage(wrap=wr1)
st1.put()
res1 = Storage.query().get(projection=['wrap.greet.text',
Storage.wrap.greet.when])
self.assertNotEqual(res1, st1)
self.assertEqual(res1.wrap, st1.wrap)
res2 = Storage.query().get(projection=['wrap.greet.text'])
self.assertEqual(res2.wrap, Wrapper(greet=Greeting(text='abc')))
示例6: testProjectionQueriesRepeatedField
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testProjectionQueriesRepeatedField(self):
class Wrapper(messages.Message):
greets = messages.MessageField(Greeting, 1, repeated=True)
class Storage(model.Model):
wrap = msgprop.MessageProperty(Wrapper, indexed_fields=['greets.text',
'greets.when'])
gr1 = Greeting(text='abc', when=123)
wr1 = Wrapper(greets=[gr1])
st1 = Storage(wrap=wr1)
st1.put()
res1 = Storage.query().get(projection=['wrap.greets.text',
Storage.wrap.greets.when])
self.assertNotEqual(res1, st1)
self.assertEqual(res1.wrap, st1.wrap)
res2 = Storage.query().get(projection=['wrap.greets.text'])
self.assertEqual(res2.wrap, Wrapper(greets=[Greeting(text='abc')]))
示例7: testDefineField_Message
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testDefineField_Message(self):
"""Test defining a message field."""
field_descriptor = descriptor.FieldDescriptor()
field_descriptor.name = 'a_field'
field_descriptor.number = 1
field_descriptor.variant = descriptor.FieldDescriptor.Variant.MESSAGE
field_descriptor.type_name = 'something.yet.to.be.Defined'
field_descriptor.label = descriptor.FieldDescriptor.Label.REPEATED
field = definition.define_field(field_descriptor)
# Name will not be set from the original descriptor.
self.assertFalse(hasattr(field, 'name'))
self.assertTrue(isinstance(field, messages.MessageField))
self.assertEquals(1, field.number)
self.assertEquals(descriptor.FieldDescriptor.Variant.MESSAGE, field.variant)
self.assertFalse(field.required)
self.assertTrue(field.repeated)
self.assertRaisesWithRegexpMatch(messages.DefinitionNotFoundError,
'Could not find definition for '
'something.yet.to.be.Defined',
getattr, field, 'type')
示例8: testMessageField
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testMessageField(self):
"""Test the construction of message fields."""
self.assertRaises(messages.FieldDefinitionError,
messages.MessageField,
str,
10)
self.assertRaises(messages.FieldDefinitionError,
messages.MessageField,
messages.Message,
10)
class MyMessage(messages.Message):
pass
field = messages.MessageField(MyMessage, 10)
self.assertEquals(MyMessage, field.type)
示例9: testMessageField_WrongType
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testMessageField_WrongType(self):
"""Test that forward referencing the wrong type raises an error."""
global AnEnum
try:
class AnEnum(messages.Enum):
pass
class AnotherMessage(messages.Message):
a_field = messages.MessageField('AnEnum', 1)
self.assertRaises(messages.FieldDefinitionError,
getattr,
AnotherMessage.field_by_name('a_field'),
'type')
finally:
del AnEnum
示例10: testMessageFieldValueToMessageWrongType
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testMessageFieldValueToMessageWrongType(self):
class MyMessage(messages.Message):
pass
class MyOtherMessage(messages.Message):
pass
class HasMessage(messages.Message):
field = messages.MessageField(MyMessage, 1)
instance = MyOtherMessage()
self.assertRaisesWithRegexpMatch(
messages.EncodeError,
'Expected type MyMessage, got MyOtherMessage: <MyOtherMessage>',
HasMessage.field.value_to_message, instance)
示例11: testNestedMessageFieldIsNone
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testNestedMessageFieldIsNone(self):
class Outer(messages.Message):
greeting = messages.MessageField(Greeting, 1)
class Store(model.Model):
outer = msgprop.MessageProperty(Outer, indexed_fields=['greeting.text'])
outer1 = Outer(greeting=None)
store1 = Store(outer=outer1)
store1.put()
res = Store.query(Store.outer.greeting.text == 'abc').fetch()
self.assertEqual(res, [])
示例12: _projected_entity_to_message
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def _projected_entity_to_message(ent, message_type):
"""Recursive helper for _from_base_type() to convert an entity to a message.
Args:
ent: A Model instance.
message_type: A Message subclass.
Returns:
An instance of message_type.
"""
msg = message_type()
analyzed = _analyze_indexed_fields(ent._projection)
for name, sublist in analyzed.iteritems():
prop = ent._properties[name]
val = prop._get_value(ent)
assert isinstance(prop, model.StructuredProperty) == bool(sublist)
if sublist:
field = message_type.field_by_name(name)
assert isinstance(field, messages.MessageField)
assert prop._repeated == field.repeated
if prop._repeated:
assert isinstance(val, list)
val = [_projected_entity_to_message(v, field.type) for v in val]
else:
assert isinstance(val, prop._modelclass)
val = _projected_entity_to_message(val, field.type)
setattr(msg, name, val)
return msg
示例13: testMessageFieldValidate
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testMessageFieldValidate(self):
"""Test validation on message field."""
class MyMessage(messages.Message):
pass
class AnotherMessage(messages.Message):
pass
field = messages.MessageField(MyMessage, 10)
field.validate(MyMessage())
self.assertRaises(messages.ValidationError,
field.validate,
AnotherMessage())
示例14: testMessageFieldValueFromMessage
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testMessageFieldValueFromMessage(self):
class MyMessage(messages.Message):
pass
class HasMessage(messages.Message):
field = messages.MessageField(MyMessage, 1)
instance = MyMessage()
self.assertTrue(instance is HasMessage.field.value_from_message(instance))
示例15: testMessageFieldValueFromMessageWrongType
# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import MessageField [as 别名]
def testMessageFieldValueFromMessageWrongType(self):
class MyMessage(messages.Message):
pass
class HasMessage(messages.Message):
field = messages.MessageField(MyMessage, 1)
self.assertRaisesWithRegexpMatch(
messages.DecodeError,
'Expected type MyMessage, got int: 10',
HasMessage.field.value_from_message, 10)