當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。