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


Python descriptor_pb2.MessageOptions方法代码示例

本文整理汇总了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') 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:20,代码来源:test_samplegen.py

示例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') 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:23,代码来源:test_samplegen.py

示例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')) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:30,代码来源:reflection_test.py

示例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()) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:15,代码来源:descriptor_test.py

示例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')) 
开发者ID:katharosada,项目名称:botchallenge,代码行数:30,代码来源:reflection_test.py

示例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
# --------------------------------------------------------------------------- 
开发者ID:google,项目名称:myelin-acorn-electron-hardware,代码行数:43,代码来源:nanopb_generator.py

示例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]) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:34,代码来源:test_samplegen.py

示例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) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:41,代码来源:test_samplegen.py

示例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) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:41,代码来源:test_samplegen.py

示例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) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:40,代码来源:test_samplegen.py

示例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]) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:37,代码来源:test_samplegen.py

示例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]) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:34,代码来源:test_samplegen.py

示例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]) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:34,代码来源:test_samplegen.py

示例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]) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:31,代码来源:test_samplegen.py

示例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) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:39,代码来源:test_samplegen.py


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