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


Python messages.MessageField方法代码示例

本文整理汇总了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]) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:21,代码来源:msgprop_test.py

示例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]) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:22,代码来源:msgprop_test.py

示例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]) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:23,代码来源:msgprop_test.py

示例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']) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:24,代码来源:msgprop_test.py

示例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'))) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:19,代码来源:msgprop_test.py

示例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')])) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:19,代码来源:msgprop_test.py

示例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') 
开发者ID:google,项目名称:protorpc,代码行数:26,代码来源:definition_test.py

示例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) 
开发者ID:google,项目名称:protorpc,代码行数:19,代码来源:messages_test.py

示例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 
开发者ID:google,项目名称:protorpc,代码行数:19,代码来源:messages_test.py

示例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) 
开发者ID:google,项目名称:protorpc,代码行数:18,代码来源:messages_test.py

示例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, []) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:13,代码来源:msgprop_test.py

示例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 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:30,代码来源:msgprop.py

示例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()) 
开发者ID:google,项目名称:protorpc,代码行数:16,代码来源:messages_test.py

示例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)) 
开发者ID:google,项目名称:protorpc,代码行数:12,代码来源:messages_test.py

示例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) 
开发者ID:google,项目名称:protorpc,代码行数:13,代码来源:messages_test.py


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