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


Python messages.StringField方法代码示例

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


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

示例1: testNestedMessageField

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [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: testDefineField_Required

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testDefineField_Required(self):
    """Test defining a required field instance from a method descriptor."""
    field_descriptor = descriptor.FieldDescriptor()

    field_descriptor.name = 'a_field'
    field_descriptor.number = 1
    field_descriptor.variant = descriptor.FieldDescriptor.Variant.STRING
    field_descriptor.label = descriptor.FieldDescriptor.Label.REQUIRED

    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.StringField))
    self.assertEquals(1, field.number)
    self.assertEquals(descriptor.FieldDescriptor.Variant.STRING, field.variant)
    self.assertTrue(field.required)
    self.assertFalse(field.repeated) 
开发者ID:google,项目名称:protorpc,代码行数:21,代码来源:definition_test.py

示例3: testDefineField_Default_Str

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testDefineField_Default_Str(self):
    """Test defining a default value for a str."""
    field_descriptor = descriptor.FieldDescriptor()

    field_descriptor.name = 'a_field'
    field_descriptor.number = 1
    field_descriptor.variant = descriptor.FieldDescriptor.Variant.STRING
    field_descriptor.default_value = u'Test'

    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.StringField))
    self.assertEquals(1, field.number)
    self.assertEquals(descriptor.FieldDescriptor.Variant.STRING, field.variant)
    self.assertFalse(field.required)
    self.assertFalse(field.repeated)
    self.assertEqual(field.default, u'Test') 
开发者ID:google,项目名称:protorpc,代码行数:22,代码来源:definition_test.py

示例4: testDefineMessageFieldsOnly

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testDefineMessageFieldsOnly(self):
    """Test definition a message with only fields."""

    class AMessage(messages.Message):

      field1 = messages.IntegerField(1)
      field2 = messages.StringField(2)

    message_descriptor = descriptor.describe_message(AMessage)

    message_class = definition.define_message(message_descriptor, '__main__')

    self.assertEquals('AMessage', message_class.__name__)
    self.assertEquals('__main__', message_class.__module__)

    self.assertEquals(message_descriptor,
                      descriptor.describe_message(message_class)) 
开发者ID:google,项目名称:protorpc,代码行数:19,代码来源:definition_test.py

示例5: testDefineMessage

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testDefineMessage(self):
    """Test defining Message class from descriptor."""

    class AMessage(messages.Message):
      class NestedEnum(messages.Enum):
        pass

      field1 = messages.IntegerField(1)
      field2 = messages.StringField(2)

    message_descriptor = descriptor.describe_message(AMessage)

    message_class = definition.define_message(message_descriptor, '__main__')

    self.assertEquals('AMessage', message_class.__name__)
    self.assertEquals('__main__', message_class.__module__)

    self.assertEquals(message_descriptor,
                      descriptor.describe_message(message_class)) 
开发者ID:google,项目名称:protorpc,代码行数:21,代码来源:definition_test.py

示例6: setUp

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def setUp(self):
    """Set up mock and request classes."""
    self.module = types.ModuleType('stocks')

    class GetQuoteRequest(messages.Message):
      __module__ = 'stocks'

      symbols = messages.StringField(1, repeated=True)

    class GetQuoteResponse(messages.Message):
      __module__ = 'stocks'

      prices = messages.IntegerField(1, repeated=True)

    self.module.GetQuoteRequest = GetQuoteRequest
    self.module.GetQuoteResponse = GetQuoteResponse 
开发者ID:google,项目名称:protorpc,代码行数:18,代码来源:definition_test.py

示例7: testDefaultFields_Single

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testDefaultFields_Single(self):
    """Test default field is correct type (single)."""
    defaults = {messages.IntegerField: 10,
                messages.FloatField: 1.5,
                messages.BooleanField: False,
                messages.BytesField: b'abc',
                messages.StringField: u'abc',
               }

    def action(field_class):
      field_class(1, default=defaults[field_class])
    self.ActionOnAllFieldClasses(action)

    # Run defaults test again checking for str/unicode compatiblity.
    defaults[messages.StringField] = 'abc'
    self.ActionOnAllFieldClasses(action) 
开发者ID:google,项目名称:protorpc,代码行数:18,代码来源:messages_test.py

示例8: testGetAssignedValue

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testGetAssignedValue(self):
    """Test getting the assigned value of a field."""
    class SomeMessage(messages.Message):
      a_value = messages.StringField(1, default=u'a default')

    message = SomeMessage()
    self.assertEquals(None, message.get_assigned_value('a_value'))

    message.a_value = u'a string'
    self.assertEquals(u'a string', message.get_assigned_value('a_value'))

    message.a_value = u'a default'
    self.assertEquals(u'a default', message.get_assigned_value('a_value'))

    self.assertRaisesWithRegexpMatch(
        AttributeError,
        'Message SomeMessage has no field no_such_field',
        message.get_assigned_value,
        'no_such_field') 
开发者ID:google,项目名称:protorpc,代码行数:21,代码来源:messages_test.py

示例9: testDefault

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testDefault(self):
    for field_class, default, expected_default in (
        (messages.IntegerField, 200, '200'),
        (messages.FloatField, 1.5, '1.5'),
        (messages.FloatField, 1e6, '1000000.0'),
        (messages.BooleanField, True, 'true'),
        (messages.BooleanField, False, 'false'),
        (messages.BytesField, 'ab\xF1', 'ab\\xf1'),
        (messages.StringField, RUSSIA, RUSSIA),
        ):
      field = field_class(10, default=default)
      field.name = u'a_field'

      expected = descriptor.FieldDescriptor()
      expected.name = u'a_field'
      expected.number = 10
      expected.label = descriptor.FieldDescriptor.Label.OPTIONAL
      expected.variant = field_class.DEFAULT_VARIANT
      expected.default_value = expected_default

      described = descriptor.describe_field(field)
      described.check_initialized()
      self.assertEquals(expected, described) 
开发者ID:google,项目名称:protorpc,代码行数:25,代码来源:descriptor_test.py

示例10: testDefinitionWithFields

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testDefinitionWithFields(self):
    class MessageWithFields(messages.Message):
      field1 = messages.IntegerField(10)
      field2 = messages.StringField(30)
      field3 = messages.IntegerField(20)

    expected = descriptor.MessageDescriptor()
    expected.name = 'MessageWithFields'

    expected.fields = [
      descriptor.describe_field(MessageWithFields.field_by_name('field1')),
      descriptor.describe_field(MessageWithFields.field_by_name('field3')),
      descriptor.describe_field(MessageWithFields.field_by_name('field2')),
    ]

    described = descriptor.describe_message(MessageWithFields)
    described.check_initialized()
    self.assertEquals(expected, described) 
开发者ID:google,项目名称:protorpc,代码行数:20,代码来源:descriptor_test.py

示例11: testParameterPrefix

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testParameterPrefix(self):
    """Test using the 'prefix' parameter to encode_message."""
    class MyMessage(messages.Message):
      number = messages.IntegerField(1)
      names = messages.StringField(2, repeated=True)

    message = MyMessage()
    message.number = 10
    message.names = [u'Fred', u'Lisa']

    encoded_message = protourlencode.encode_message(message, prefix='prefix-')
    self.assertEquals({'prefix-number': ['10'],
                       'prefix-names-0': ['Fred'],
                       'prefix-names-1': ['Lisa'],
                      },
                      cgi.parse_qs(encoded_message))

    self.assertEquals(message, protourlencode.decode_message(MyMessage,
                                                             encoded_message,
                                                             prefix='prefix-')) 
开发者ID:google,项目名称:protorpc,代码行数:22,代码来源:protourlencode_test.py

示例12: setUp

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def setUp(self):
    super(MsgPropTests, self).setUp()
    global Greeting

    class Greeting(messages.Message):
      text = messages.StringField(1, required=True)
      when = messages.IntegerField(2)
      color = messages.EnumField(Color, 3) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:10,代码来源:msgprop_test.py

示例13: testRepeatedIndexedField

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testRepeatedIndexedField(self):
    class AltGreeting(messages.Message):
      lines = messages.StringField(1, repeated=True)
      when = messages.IntegerField(2)

    class Store(model.Model):
      altg = msgprop.MessageProperty(AltGreeting, indexed_fields=['lines'])
    s1 = Store(altg=AltGreeting(lines=['foo', 'bar'], when=123))
    s1.put()
    s2 = Store(altg=AltGreeting(lines=['baz', 'bletch'], when=456))
    s2.put()
    res = Store.query(Store.altg.lines == 'foo').fetch()
    self.assertEqual(res, [s1]) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:15,代码来源:msgprop_test.py

示例14: testRepeatedIndexedFieldInRepeatedMessageProperty

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testRepeatedIndexedFieldInRepeatedMessageProperty(self):
    class AltGreeting(messages.Message):
      lines = messages.StringField(1, repeated=True)
      when = messages.IntegerField(2)
    self.assertRaises(TypeError, msgprop.MessageProperty,
                      AltGreeting, indexed_fields=['lines'], repeated=True) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:8,代码来源:msgprop_test.py

示例15: testPropertyNameConflict

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import StringField [as 别名]
def testPropertyNameConflict(self):
    class MyMsg(messages.Message):
      blob_ = messages.StringField(1)
    msgprop.MessageProperty(MyMsg)  # Should be okay
    self.assertRaises(ValueError, msgprop.MessageProperty,
                      MyMsg, indexed_fields=['blob_']) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:8,代码来源:msgprop_test.py


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