本文整理汇总了Python中google.protobuf.descriptor_pb2.MessageOptions方法的典型用法代码示例。如果您正苦于以下问题:Python descriptor_pb2.MessageOptions方法的具体用法?Python descriptor_pb2.MessageOptions怎么用?Python descriptor_pb2.MessageOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.protobuf.descriptor_pb2
的用法示例。
在下文中一共展示了descriptor_pb2.MessageOptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validate_expression_mapped_no_value
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_validate_expression_mapped_no_value():
OutputType = DummyMessage(
fields={
"cephalopods": DummyField(
message=DummyMessage(
# Maps need 'key' AND 'value' attributes.
fields={"key": DummyField()},
type="CEPHALOPODS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)),
repeated=True,
)
},
type="MOLLUSC_TYPE"
)
method = DummyMethod(output=OutputType)
v = samplegen.Validator(method)
with pytest.raises(types.BadAttributeLookup):
v.validate_expression('$resp.cephalopods{"squid"}.mantle')
示例2: test_validate_expression_mapped_no_message
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_validate_expression_mapped_no_message():
OutputType = DummyMessage(
fields={
"cephalopods": DummyField(
message=DummyMessage(
fields={
"key": DummyField(),
# The value field needs a message.
"value": DummyField(),
},
type="CEPHALOPODS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)),
repeated=True,
)
},
type="MOLLUSC_TYPE"
)
method = DummyMethod(output=OutputType)
v = samplegen.Validator(method)
with pytest.raises(types.BadAttributeLookup):
v.validate_expression('$resp.cephalopods{"squid"}.mantle')
示例3: testHandWrittenReflection
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def testHandWrittenReflection(self):
# Hand written extensions are only supported by the pure-Python
# implementation of the API.
if api_implementation.Type() != 'python':
return
FieldDescriptor = descriptor.FieldDescriptor
foo_field_descriptor = FieldDescriptor(
name='foo_field', full_name='MyProto.foo_field',
index=0, number=1, type=FieldDescriptor.TYPE_INT64,
cpp_type=FieldDescriptor.CPPTYPE_INT64,
label=FieldDescriptor.LABEL_OPTIONAL, default_value=0,
containing_type=None, message_type=None, enum_type=None,
is_extension=False, extension_scope=None,
options=descriptor_pb2.FieldOptions())
mydescriptor = descriptor.Descriptor(
name='MyProto', full_name='MyProto', filename='ignored',
containing_type=None, nested_types=[], enum_types=[],
fields=[foo_field_descriptor], extensions=[],
options=descriptor_pb2.MessageOptions())
class MyProtoClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)):
DESCRIPTOR = mydescriptor
myproto_instance = MyProtoClass()
self.assertEqual(0, myproto_instance.foo_field)
self.assertTrue(not myproto_instance.HasField('foo_field'))
myproto_instance.foo_field = 23
self.assertEqual(23, myproto_instance.foo_field)
self.assertTrue(myproto_instance.HasField('foo_field'))
示例4: testGetOptions
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def testGetOptions(self):
self.assertEqual(self.my_enum.GetOptions(),
descriptor_pb2.EnumOptions())
self.assertEqual(self.my_enum.values[0].GetOptions(),
descriptor_pb2.EnumValueOptions())
self.assertEqual(self.my_message.GetOptions(),
descriptor_pb2.MessageOptions())
self.assertEqual(self.my_message.fields[0].GetOptions(),
descriptor_pb2.FieldOptions())
self.assertEqual(self.my_method.GetOptions(),
descriptor_pb2.MethodOptions())
self.assertEqual(self.my_service.GetOptions(),
descriptor_pb2.ServiceOptions())
示例5: testHandWrittenReflection
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def testHandWrittenReflection(self):
# Hand written extensions are only supported by the pure-Python
# implementation of the API.
if api_implementation.Type() != 'python':
return
FieldDescriptor = descriptor.FieldDescriptor
foo_field_descriptor = FieldDescriptor(
name='foo_field', full_name='MyProto.foo_field',
index=0, number=1, type=FieldDescriptor.TYPE_INT64,
cpp_type=FieldDescriptor.CPPTYPE_INT64,
label=FieldDescriptor.LABEL_OPTIONAL, default_value=0,
containing_type=None, message_type=None, enum_type=None,
is_extension=False, extension_scope=None,
options=descriptor_pb2.FieldOptions())
mydescriptor = descriptor.Descriptor(
name='MyProto', full_name='MyProto', filename='ignored',
containing_type=None, nested_types=[], enum_types=[],
fields=[foo_field_descriptor], extensions=[],
options=descriptor_pb2.MessageOptions())
class MyProtoClass(message.Message, metaclass=reflection.GeneratedProtocolMessageType):
DESCRIPTOR = mydescriptor
myproto_instance = MyProtoClass()
self.assertEqual(0, myproto_instance.foo_field)
self.assertTrue(not myproto_instance.HasField('foo_field'))
myproto_instance.foo_field = 23
self.assertEqual(23, myproto_instance.foo_field)
self.assertTrue(myproto_instance.HasField('foo_field'))
示例6: get_nanopb_suboptions
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def get_nanopb_suboptions(subdesc, options, name):
'''Get copy of options, and merge information from subdesc.'''
new_options = nanopb_pb2.NanoPBOptions()
new_options.CopyFrom(options)
if hasattr(subdesc, 'syntax') and subdesc.syntax == "proto3":
new_options.proto3 = True
# Handle options defined in a separate file
dotname = '.'.join(name.parts)
for namemask, options in Globals.separate_options:
if fnmatch(dotname, namemask):
Globals.matched_namemasks.add(namemask)
new_options.MergeFrom(options)
# Handle options defined in .proto
if isinstance(subdesc.options, descriptor.FieldOptions):
ext_type = nanopb_pb2.nanopb
elif isinstance(subdesc.options, descriptor.FileOptions):
ext_type = nanopb_pb2.nanopb_fileopt
elif isinstance(subdesc.options, descriptor.MessageOptions):
ext_type = nanopb_pb2.nanopb_msgopt
elif isinstance(subdesc.options, descriptor.EnumOptions):
ext_type = nanopb_pb2.nanopb_enumopt
else:
raise Exception("Unknown options type")
if subdesc.options.HasExtension(ext_type):
ext = subdesc.options.Extensions[ext_type]
new_options.MergeFrom(ext)
if Globals.verbose_options:
sys.stderr.write("Options for " + dotname + ": ")
sys.stderr.write(text_format.MessageToString(new_options) + "\n")
return new_options
# ---------------------------------------------------------------------------
# Command line interface
# ---------------------------------------------------------------------------
示例7: test_loop_map
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_loop_map():
loop = {
"loop": {
"map": "$resp.molluscs",
"key": "cls",
"value": "mollusc",
"body": [{"print": ["A %s is a %s", "mollusc", "cls"]}],
}
}
OutputType = DummyMessage(
fields={
"molluscs": DummyField(
message=DummyMessage(
fields={
"key": DummyField(),
"value": DummyField(
message=DummyMessage(
fields={},
type="MOLLUSC_TYPE"
)
)
},
type="MOLLUSCS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)
),
repeated=True
),
},
type="RESPONSE_TYPE"
)
v = samplegen.Validator(DummyMethod(output=OutputType))
v.validate_response([loop])
示例8: test_map_loop_lexical_scope_key
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_map_loop_lexical_scope_key():
statements = [
{
"loop": {
"map": "$resp.molluscs",
"key": "cls",
"value": "mollusc",
"body": [{"define": "tmp=cls"}],
}
},
# 'cls' is outside the visible lexical scope according to strict
# samplegen rules, even though it is valid python.
{"define": "last_cls=cls"},
]
OutputType = DummyMessage(
fields={
"molluscs": DummyField(
message=DummyMessage(
fields={
"key": DummyField(),
"value": DummyField(
message=DummyMessage(
fields={},
type="MOLLUSC_TYPE"
)
)
},
type="MOLLUSCS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)
),
repeated=True
),
},
type="RESPONSE_TYPE"
)
v = samplegen.Validator(DummyMethod(output=OutputType))
with pytest.raises(types.UndefinedVariableReference):
v.validate_response(statements)
示例9: test_map_loop_lexical_scope_value
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_map_loop_lexical_scope_value():
statements = [
{
"loop": {
"map": "$resp.molluscs",
"key": "cls",
"value": "mollusc",
"body": [{"define": "tmp=mollusc"}],
}
},
# 'mollusc' is outside the visible lexical scope according to strict
# samplegen rules, even though it is valid python.
{"define": "last_mollusc=mollusc"},
]
OutputType = DummyMessage(
fields={
"molluscs": DummyField(
message=DummyMessage(
fields={
"key": DummyField(),
"value": DummyField(
message=DummyMessage(
fields={},
type="MOLLUSC_TYPE"
)
)
},
type="MOLLUSCS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)
),
repeated=True
),
},
type="RESPONSE_TYPE"
)
v = samplegen.Validator(DummyMethod(output=OutputType))
with pytest.raises(types.UndefinedVariableReference):
v.validate_response(statements)
示例10: test_map_loop_lexical_scope_inline
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_map_loop_lexical_scope_inline():
statements = [
{
"loop": {
"map": "$resp.molluscs",
"key": "cls",
"value": "mollusc",
"body": [{"define": "tmp=mollusc"}],
}
},
# 'tmp' is outside the visible lexical scope according to strict
# samplegen rules, even though it is valid python.
{"define": "last_mollusc=tmp"},
]
OutputType = DummyMessage(
fields={
"molluscs": DummyField(
message=DummyMessage(
fields={
"key": DummyField(),
"value": DummyField(
message=DummyMessage(
fields={},
type="MOLLUSC_TYPE"
)
)
},
type="MOLLUSCS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)
),
repeated=True
),
},
type="RESPONSE_TYPE"
)
v = samplegen.Validator(DummyMethod(output=OutputType))
with pytest.raises(types.UndefinedVariableReference):
v.validate_response(statements)
示例11: test_loop_map_reserved_key
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_loop_map_reserved_key():
loop = {
"loop": {
"map": "$resp.molluscs",
# Can't use 'class' since it's a reserved keyword
"key": "class",
"value": "mollusc",
"body": [{"print": ["A %s is a %s", "mollusc", "class"]}],
}
}
OutputType = DummyMessage(
fields={
"molluscs": DummyField(
message=DummyMessage(
fields={
"key": DummyField(),
"value": DummyField(
message=DummyMessage(
fields={},
type="MOLLUSC_TYPE"
)
)
},
type="MOLLUSCS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)
),
repeated=True
),
},
type="RESPONSE_TYPE"
)
v = samplegen.Validator(DummyMethod(output=OutputType))
with pytest.raises(types.ReservedVariableName):
v.validate_response([loop])
示例12: test_loop_map_no_key
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_loop_map_no_key():
loop = {
"loop": {
"map": "$resp.molluscs",
"value": "mollusc",
"body": [{"print": ["Mollusc: %s", "mollusc"]}],
}
}
OutputType = DummyMessage(
fields={
"molluscs": DummyField(
message=DummyMessage(
fields={
"key": DummyField(),
"value": DummyField(
message=DummyMessage(
fields={},
type="CLASS_TYPE"
)
)
},
type="MOLLUSCS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)
),
repeated=True
),
},
type="RESPONSE_TYPE"
)
v = samplegen.Validator(DummyMethod(output=OutputType))
v.validate_response([loop])
示例13: test_loop_map_no_value
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_loop_map_no_value():
loop = {
"loop": {
"map": "$resp.molluscs",
"key": "mollusc",
"body": [{"print": ["Mollusc: %s", "mollusc"]}],
}
}
OutputType = DummyMessage(
fields={
"molluscs": DummyField(
message=DummyMessage(
fields={
"key": DummyField(),
"value": DummyField(
message=DummyMessage(
fields={},
type="CLASS_TYPE"
)
)
},
type="MOLLUSCS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)
),
repeated=True
),
},
type="RESPONSE_TYPE"
)
v = samplegen.Validator(DummyMethod(output=OutputType))
v.validate_response([loop])
示例14: test_loop_map_no_key_or_value
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_loop_map_no_key_or_value():
loop = {"loop": {"map": "$resp.molluscs",
# Need at least one of 'key' or 'value'
"body": [{"print": ["Dead loop"]}]}}
OutputType = DummyMessage(
fields={
"molluscs": DummyField(
message=DummyMessage(
fields={
"key": DummyField(),
"value": DummyField(
message=DummyMessage(
fields={},
type="CLASS_TYPE"
)
)
},
type="MOLLUSCS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)
),
repeated=True
),
},
type="RESPONSE_TYPE"
)
v = samplegen.Validator(DummyMethod(output=OutputType))
with pytest.raises(types.BadLoop):
v.validate_response([loop])
示例15: test_loop_map_redefined_key
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import MessageOptions [as 别名]
def test_loop_map_redefined_key():
statements = [
{"define": "mollusc=$resp.molluscs"},
{
"loop": {
"map": "$resp.molluscs",
# Can't redefine mollusc, which was defined one statement above.
"key": "mollusc",
"body": [{"print": ["Mollusc: %s", "mollusc"]}],
}
},
]
OutputType = DummyMessage(
fields={
"molluscs": DummyField(
message=DummyMessage(
fields={
"key": DummyField(),
"value": DummyField(
message=DummyMessage(
fields={},
type="CLASS_TYPE"
)
)
},
type="MOLLUSCS_TYPE",
options=namedtuple("MessageOptions", ["map_field"])(True)
),
repeated=True
),
},
type="RESPONSE_TYPE"
)
v = samplegen.Validator(DummyMethod(output=OutputType))
with pytest.raises(types.RedefinedVariable):
v.validate_response(statements)