當前位置: 首頁>>代碼示例>>Python>>正文


Python descriptor.Descriptor方法代碼示例

本文整理匯總了Python中google.protobuf.descriptor.Descriptor方法的典型用法代碼示例。如果您正苦於以下問題:Python descriptor.Descriptor方法的具體用法?Python descriptor.Descriptor怎麽用?Python descriptor.Descriptor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.protobuf.descriptor的用法示例。


在下文中一共展示了descriptor.Descriptor方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _CheckConflictRegister

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import Descriptor [as 別名]
def _CheckConflictRegister(self, desc):
    """Check if the descriptor name conflicts with another of the same name.

    Args:
      desc: Descriptor of a message, enum, service or extension.
    """
    desc_name = desc.full_name
    for register, descriptor_type in [
        (self._descriptors, descriptor.Descriptor),
        (self._enum_descriptors, descriptor.EnumDescriptor),
        (self._service_descriptors, descriptor.ServiceDescriptor),
        (self._toplevel_extensions, descriptor.FieldDescriptor)]:
      if desc_name in register:
        file_name = register[desc_name].file.name
        if not isinstance(desc, descriptor_type) or (
            file_name != desc.file.name):
          warn_msg = ('Conflict register for file "' + desc.file.name +
                      '": ' + desc_name +
                      ' is already defined in file "' +
                      file_name + '"')
          warnings.warn(warn_msg, RuntimeWarning)
        return 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:24,代碼來源:descriptor_pool.py

示例2: AddDescriptor

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import Descriptor [as 別名]
def AddDescriptor(self, desc):
    """Adds a Descriptor to the pool, non-recursively.

    If the Descriptor contains nested messages or enums, the caller must
    explicitly register them. This method also registers the FileDescriptor
    associated with the message.

    Args:
      desc: A Descriptor.
    """
    if not isinstance(desc, descriptor.Descriptor):
      raise TypeError('Expected instance of descriptor.Descriptor.')

    self._CheckConflictRegister(desc)

    self._descriptors[desc.full_name] = desc
    self._AddFileDescriptor(desc.file) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:19,代碼來源:descriptor_pool.py

示例3: testMakeClassWithNestedDescriptor

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import Descriptor [as 別名]
def testMakeClassWithNestedDescriptor(self):
    leaf_desc = descriptor.Descriptor('leaf', 'package.parent.child.leaf', '',
                                      containing_type=None, fields=[],
                                      nested_types=[], enum_types=[],
                                      extensions=[])
    child_desc = descriptor.Descriptor('child', 'package.parent.child', '',
                                       containing_type=None, fields=[],
                                       nested_types=[leaf_desc], enum_types=[],
                                       extensions=[])
    sibling_desc = descriptor.Descriptor('sibling', 'package.parent.sibling',
                                         '', containing_type=None, fields=[],
                                         nested_types=[], enum_types=[],
                                         extensions=[])
    parent_desc = descriptor.Descriptor('parent', 'package.parent', '',
                                        containing_type=None, fields=[],
                                        nested_types=[child_desc, sibling_desc],
                                        enum_types=[], extensions=[])
    message_class = reflection.MakeClass(parent_desc)
    self.assertIn('child', message_class.__dict__)
    self.assertIn('sibling', message_class.__dict__)
    self.assertIn('leaf', message_class.child.__dict__) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:23,代碼來源:reflection_test.py

示例4: AddSerializedFile

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import Descriptor [as 別名]
def AddSerializedFile(self, serialized_file_desc_proto):
    """Adds the FileDescriptorProto and its types to this pool.

    Args:
      serialized_file_desc_proto (bytes): A bytes string, serialization of the
        :class:`FileDescriptorProto` to add.
    """

    # pylint: disable=g-import-not-at-top
    from google.protobuf import descriptor_pb2
    file_desc_proto = descriptor_pb2.FileDescriptorProto.FromString(
        serialized_file_desc_proto)
    self.Add(file_desc_proto)

  # Add Descriptor to descriptor pool is dreprecated. Please use Add()
  # or AddSerializedFile() to add a FileDescriptorProto instead. 
開發者ID:luci,項目名稱:luci-py,代碼行數:18,代碼來源:descriptor_pool.py

示例5: _AddDescriptor

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import Descriptor [as 別名]
def _AddDescriptor(self, desc):
    """Adds a Descriptor to the pool, non-recursively.

    If the Descriptor contains nested messages or enums, the caller must
    explicitly register them. This method also registers the FileDescriptor
    associated with the message.

    Args:
      desc: A Descriptor.
    """
    if not isinstance(desc, descriptor.Descriptor):
      raise TypeError('Expected instance of descriptor.Descriptor.')

    self._CheckConflictRegister(desc, desc.full_name, desc.file.name)

    self._descriptors[desc.full_name] = desc
    self._AddFileDescriptor(desc.file)

  # Add EnumDescriptor to descriptor pool is dreprecated. Please use Add()
  # or AddSerializedFile() to add a FileDescriptorProto instead. 
開發者ID:luci,項目名稱:luci-py,代碼行數:22,代碼來源:descriptor_pool.py

示例6: FindExtensionByNumber

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import Descriptor [as 別名]
def FindExtensionByNumber(self, message_descriptor, number):
    """Gets the extension of the specified message with the specified number.

    Extensions have to be registered to this pool by calling :func:`Add` or
    :func:`AddExtensionDescriptor`.

    Args:
      message_descriptor (Descriptor): descriptor of the extended message.
      number (int): Number of the extension field.

    Returns:
      FieldDescriptor: The descriptor for the extension.

    Raises:
      KeyError: when no extension with the given number is known for the
        specified message.
    """
    try:
      return self._extensions_by_number[message_descriptor][number]
    except KeyError:
      self._TryLoadExtensionFromDB(message_descriptor, number)
      return self._extensions_by_number[message_descriptor][number] 
開發者ID:luci,項目名稱:luci-py,代碼行數:24,代碼來源:descriptor_pool.py

示例7: FindAllExtensions

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import Descriptor [as 別名]
def FindAllExtensions(self, message_descriptor):
    """Gets all the known extensions of a given message.

    Extensions have to be registered to this pool by build related
    :func:`Add` or :func:`AddExtensionDescriptor`.

    Args:
      message_descriptor (Descriptor): Descriptor of the extended message.

    Returns:
      list[FieldDescriptor]: Field descriptors describing the extensions.
    """
    # Fallback to descriptor db if FindAllExtensionNumbers is provided.
    if self._descriptor_db and hasattr(
        self._descriptor_db, 'FindAllExtensionNumbers'):
      full_name = message_descriptor.full_name
      all_numbers = self._descriptor_db.FindAllExtensionNumbers(full_name)
      for number in all_numbers:
        if number in self._extensions_by_number[message_descriptor]:
          continue
        self._TryLoadExtensionFromDB(message_descriptor, number)

    return list(self._extensions_by_number[message_descriptor].values()) 
開發者ID:luci,項目名稱:luci-py,代碼行數:25,代碼來源:descriptor_pool.py

示例8: FindMessageTypeByName

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import Descriptor [as 別名]
def FindMessageTypeByName(self, full_name):
    """Loads the named descriptor from the pool.

    Args:
      full_name (str): The full name of the descriptor to load.

    Returns:
      Descriptor: The descriptor for the named type.

    Raises:
      KeyError: if the message cannot be found in the pool.
    """

    full_name = _NormalizeFullyQualifiedName(full_name)
    if full_name not in self._descriptors:
      self._FindFileContainingSymbolInDb(full_name)
    return self._descriptors[full_name] 
開發者ID:luci,項目名稱:luci-py,代碼行數:19,代碼來源:descriptor_pool.py


注:本文中的google.protobuf.descriptor.Descriptor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。