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


Python descriptor_pb2.DescriptorProto方法代码示例

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


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

示例1: CopyToProto

# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import DescriptorProto [as 别名]
def CopyToProto(self, proto):
    """Copies this to a descriptor_pb2.DescriptorProto.

    Args:
      proto: An empty descriptor_pb2.DescriptorProto.
    """
    # This function is overridden to give a better doc comment.
    super(Descriptor, self).CopyToProto(proto)


# TODO(robinson): We should have aggressive checking here,
# for example:
#   * If you specify a repeated field, you should not be allowed
#     to specify a default value.
#   * [Other examples here as needed].
#
# TODO(robinson): for this and other *Descriptor classes, we
# might also want to lock things down aggressively (e.g.,
# prevent clients from setting the attributes).  Having
# stronger invariants here in general will reduce the number
# of runtime checks we must do in reflection.py... 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:23,代码来源:descriptor.py

示例2: testCopyToProto_ForeignNestedMessage

# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import DescriptorProto [as 别名]
def testCopyToProto_ForeignNestedMessage(self):
    TEST_FOREIGN_NESTED_ASCII = """
      name: 'TestForeignNested'
      field: <
        name: 'foreign_nested'
        number: 1
        label: 1  # Optional
        type: 11  # TYPE_MESSAGE
        type_name: '.protobuf_unittest.TestAllTypes.NestedMessage'
      >
      """

    self._InternalTestCopyToProto(
        unittest_pb2.TestForeignNested.DESCRIPTOR,
        descriptor_pb2.DescriptorProto,
        TEST_FOREIGN_NESTED_ASCII) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:18,代码来源:descriptor_test.py

示例3: testCopyToProto_SeveralExtensions

# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import DescriptorProto [as 别名]
def testCopyToProto_SeveralExtensions(self):
    TEST_MESSAGE_WITH_SEVERAL_EXTENSIONS_ASCII = """
      name: 'TestMultipleExtensionRanges'
      extension_range: <
        start: 42
        end: 43
      >
      extension_range: <
        start: 4143
        end: 4244
      >
      extension_range: <
        start: 65536
        end: 536870912
      >
      """

    self._InternalTestCopyToProto(
        unittest_pb2.TestMultipleExtensionRanges.DESCRIPTOR,
        descriptor_pb2.DescriptorProto,
        TEST_MESSAGE_WITH_SEVERAL_EXTENSIONS_ASCII) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:23,代码来源:descriptor_test.py

示例4: testJsonName

# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import DescriptorProto [as 别名]
def testJsonName(self):
    descriptor_proto = descriptor_pb2.DescriptorProto()
    descriptor_proto.name = 'TestJsonName'
    names = ['field_name', 'fieldName', 'FieldName',
             '_field_name', 'FIELD_NAME', 'json_name']
    json_names = ['fieldName', 'fieldName', 'FieldName',
                  'FieldName', 'FIELDNAME', '@type']
    for index in range(len(names)):
      field = descriptor_proto.field.add()
      field.number = index + 1
      field.name = names[index]
    field.json_name = '@type'
    result = descriptor.MakeDescriptor(descriptor_proto)
    for index in range(len(json_names)):
      self.assertEqual(result.fields[index].json_name,
                       json_names[index]) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:18,代码来源:descriptor_test.py

示例5: CopyToProto

# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import DescriptorProto [as 别名]
def CopyToProto(self, proto):
    """Copies this to a descriptor_pb2.DescriptorProto.

    Args:
      proto: An empty descriptor_pb2.DescriptorProto.
    """
    # This function is overriden to give a better doc comment.
    super(Descriptor, self).CopyToProto(proto)


# TODO(robinson): We should have aggressive checking here,
# for example:
#   * If you specify a repeated field, you should not be allowed
#     to specify a default value.
#   * [Other examples here as needed].
#
# TODO(robinson): for this and other *Descriptor classes, we
# might also want to lock things down aggressively (e.g.,
# prevent clients from setting the attributes).  Having
# stronger invariants here in general will reduce the number
# of runtime checks we must do in reflection.py... 
开发者ID:sklearn-theano,项目名称:sklearn-theano,代码行数:23,代码来源:descriptor.py

示例6: _type_names

# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import DescriptorProto [as 别名]
def _type_names(
    proto_file: FileDescriptorProto,
    message_type: DescriptorProto,
    parents: Optional[Deque[str]] = None,
) -> Iterator[Tuple[str, str]]:
    if parents is None:
        parents = deque()

    proto_name_parts = ['']
    if proto_file.package:
        proto_name_parts.append(proto_file.package)
    proto_name_parts.extend(parents)
    proto_name_parts.append(message_type.name)

    py_name_parts = [_proto2pb2_module_name(proto_file.name)]
    py_name_parts.extend(parents)
    py_name_parts.append(message_type.name)

    yield '.'.join(proto_name_parts), '.'.join(py_name_parts)

    parents.append(message_type.name)
    for nested in message_type.nested_type:
        yield from _type_names(proto_file, nested, parents=parents)
    parents.pop() 
开发者ID:vmagamedov,项目名称:grpclib,代码行数:26,代码来源:main.py

示例7: testCopyToProto_Options

# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import DescriptorProto [as 别名]
def testCopyToProto_Options(self):
    TEST_DEPRECATED_FIELDS_ASCII = """
      name: 'TestDeprecatedFields'
      field: <
        name: 'deprecated_int32'
        number: 1
        label: 1  # Optional
        type: 5  # TYPE_INT32
        options: <
          deprecated: true
        >
      >
      """

    self._InternalTestCopyToProto(
        unittest_pb2.TestDeprecatedFields.DESCRIPTOR,
        descriptor_pb2.DescriptorProto,
        TEST_DEPRECATED_FIELDS_ASCII) 
开发者ID:apple,项目名称:coremltools,代码行数:20,代码来源:descriptor_test.py

示例8: make_message

# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import DescriptorProto [as 别名]
def make_message(
    name: str,
    package: str = 'foo.bar.v1',
    module: str = 'baz',
    fields: typing.Sequence[wrappers.Field] = (),
    meta: metadata.Metadata = None,
    options: desc.MethodOptions = None,
) -> wrappers.MessageType:
    message_pb = desc.DescriptorProto(
        name=name,
        field=[i.field_pb for i in fields],
        options=options,
    )
    return wrappers.MessageType(
        message_pb=message_pb,
        fields=collections.OrderedDict((i.name, i) for i in fields),
        nested_messages={},
        nested_enums={},
        meta=meta or metadata.Metadata(address=metadata.Address(
            name=name,
            package=tuple(package.split('.')),
            module=module,
        )),
    ) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:26,代码来源:test_utils.py

示例9: test_mock_value_message

# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import DescriptorProto [as 别名]
def test_mock_value_message():
    subfields = collections.OrderedDict((
        ('foo', make_field(name='foo', type='TYPE_INT32')),
        ('bar', make_field(name='bar', type='TYPE_STRING'))
    ))
    message = wrappers.MessageType(
        fields=subfields,
        message_pb=descriptor_pb2.DescriptorProto(name='Message', field=[
            i.field_pb for i in subfields.values()
        ]),
        meta=metadata.Metadata(address=metadata.Address(
            module='bogus',
            name='Message',
        )),
        nested_enums={},
        nested_messages={},
    )
    field = make_field(
        type='TYPE_MESSAGE',
        type_name='bogus.Message',
        message=message,
    )
    assert field.mock_value == 'bogus.Message(foo=324)' 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:25,代码来源:test_field.py

示例10: testCopyToProto_EmptyMessage

# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import DescriptorProto [as 别名]
def testCopyToProto_EmptyMessage(self):
    self._InternalTestCopyToProto(
        unittest_pb2.TestEmptyMessage.DESCRIPTOR,
        descriptor_pb2.DescriptorProto,
        TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCII) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:7,代码来源:descriptor_test.py


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