本文整理汇总了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...
示例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)
示例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)
示例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])
示例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...
示例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()
示例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)
示例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,
)),
)
示例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)'
示例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)