本文整理匯總了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])
示例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)
示例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')
示例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))
示例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))
示例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
示例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)
示例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')
示例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)
示例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)
示例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-'))
示例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)
示例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])
示例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)
示例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_'])