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


Python descriptor.FileDescriptor方法代碼示例

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


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

示例1: AddDescriptor

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import FileDescriptor [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

示例2: AddFileDescriptor

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

    If the FileDescriptor contains messages or enums, the caller must explicitly
    register them.

    Args:
      file_desc: A FileDescriptor.
    """

    self._AddFileDescriptor(file_desc)
    # TODO(jieluo): This is a temporary solution for FieldDescriptor.file.
    # FieldDescriptor.file is added in code gen. Remove this solution after
    # maybe 2020 for compatibility reason (with 3.4.1 only).
    for extension in list(file_desc.extensions_by_name.values()):
      self._file_desc_by_toplevel_extension[
          extension.full_name] = file_desc 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:19,代碼來源:descriptor_pool.py

示例3: _FindFileContainingSymbolInDb

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import FileDescriptor [as 別名]
def _FindFileContainingSymbolInDb(self, symbol):
    """Finds the file in descriptor DB containing the specified symbol.

    Args:
      symbol: The name of the symbol to search for.

    Returns:
      A FileDescriptor that contains the specified symbol.

    Raises:
      KeyError: if the file cannot be found in the descriptor database.
    """
    try:
      file_proto = self._internal_db.FindFileContainingSymbol(symbol)
    except KeyError as error:
      if self._descriptor_db:
        file_proto = self._descriptor_db.FindFileContainingSymbol(symbol)
      else:
        raise error
    if not file_proto:
      raise KeyError('Cannot find a file containing %s' % symbol)
    return self._ConvertFileProtoToFileDescriptor(file_proto) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:24,代碼來源:descriptor_pool.py

示例4: testFindFileContainingSymbol

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import FileDescriptor [as 別名]
def testFindFileContainingSymbol(self):
    file_desc1 = self.pool.FindFileContainingSymbol(
        'google.protobuf.python.internal.Factory1Message')
    self.assertIsInstance(file_desc1, descriptor.FileDescriptor)
    self.assertEqual('google/protobuf/internal/factory_test1.proto',
                     file_desc1.name)
    self.assertEqual('google.protobuf.python.internal', file_desc1.package)
    self.assertIn('Factory1Message', file_desc1.message_types_by_name)

    file_desc2 = self.pool.FindFileContainingSymbol(
        'google.protobuf.python.internal.Factory2Message')
    self.assertIsInstance(file_desc2, descriptor.FileDescriptor)
    self.assertEqual('google/protobuf/internal/factory_test2.proto',
                     file_desc2.name)
    self.assertEqual('google.protobuf.python.internal', file_desc2.package)
    self.assertIn('Factory2Message', file_desc2.message_types_by_name) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:18,代碼來源:descriptor_pool_test.py

示例5: testFindFileContainingSymbol

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import FileDescriptor [as 別名]
def testFindFileContainingSymbol(self):
    file_desc1 = self.pool.FindFileContainingSymbol(
        'google.protobuf.python.internal.Factory1Message')
    self.assertIsInstance(file_desc1, descriptor.FileDescriptor)
    self.assertEqual('google/protobuf/internal/factory_test1.proto',
                      file_desc1.name)
    self.assertEqual('google.protobuf.python.internal', file_desc1.package)
    self.assertIn('Factory1Message', file_desc1.message_types_by_name)

    file_desc2 = self.pool.FindFileContainingSymbol(
        'google.protobuf.python.internal.Factory2Message')
    self.assertIsInstance(file_desc2, descriptor.FileDescriptor)
    self.assertEqual('google/protobuf/internal/factory_test2.proto',
                      file_desc2.name)
    self.assertEqual('google.protobuf.python.internal', file_desc2.package)
    self.assertIn('Factory2Message', file_desc2.message_types_by_name) 
開發者ID:sklearn-theano,項目名稱:sklearn-theano,代碼行數:18,代碼來源:descriptor_pool_test.py

示例6: testFindFileContainingSymbol

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import FileDescriptor [as 別名]
def testFindFileContainingSymbol(self):
    file_desc1 = self.pool.FindFileContainingSymbol(
        'google.protobuf.python.internal.Factory1Message')
    self.assertIsInstance(file_desc1, descriptor.FileDescriptor)
    self.assertEquals('google/protobuf/internal/factory_test1.proto',
                      file_desc1.name)
    self.assertEquals('google.protobuf.python.internal', file_desc1.package)
    self.assertIn('Factory1Message', file_desc1.message_types_by_name)

    file_desc2 = self.pool.FindFileContainingSymbol(
        'google.protobuf.python.internal.Factory2Message')
    self.assertIsInstance(file_desc2, descriptor.FileDescriptor)
    self.assertEquals('google/protobuf/internal/factory_test2.proto',
                      file_desc2.name)
    self.assertEquals('google.protobuf.python.internal', file_desc2.package)
    self.assertIn('Factory2Message', file_desc2.message_types_by_name) 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:18,代碼來源:descriptor_pool_test.py

示例7: AddFileDescriptor

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

    If the FileDescriptor contains messages or enums, the caller must explicitly
    register them.

    Args:
      file_desc: A FileDescriptor.
    """

    self._AddFileDescriptor(file_desc)
    # TODO(jieluo): This is a temporary solution for FieldDescriptor.file.
    # Remove it when FieldDescriptor.file is added in code gen.
    for extension in file_desc.extensions_by_name.values():
      self._file_desc_by_toplevel_extension[
          extension.full_name] = file_desc 
開發者ID:apple,項目名稱:coremltools,代碼行數:18,代碼來源:descriptor_pool.py

示例8: _AddDescriptor

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import FileDescriptor [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

示例9: _InternalAddFileDescriptor

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

    If the FileDescriptor contains messages or enums, the caller must explicitly
    register them.

    Args:
      file_desc: A FileDescriptor.
    """

    self._AddFileDescriptor(file_desc)
    # TODO(jieluo): This is a temporary solution for FieldDescriptor.file.
    # FieldDescriptor.file is added in code gen. Remove this solution after
    # maybe 2020 for compatibility reason (with 3.4.1 only).
    for extension in file_desc.extensions_by_name.values():
      self._file_desc_by_toplevel_extension[
          extension.full_name] = file_desc 
開發者ID:luci,項目名稱:luci-py,代碼行數:19,代碼來源:descriptor_pool.py

示例10: _FindFileContainingSymbolInDb

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import FileDescriptor [as 別名]
def _FindFileContainingSymbolInDb(self, symbol):
    """Finds the file in descriptor DB containing the specified symbol.

    Args:
      symbol (str): The name of the symbol to search for.

    Returns:
      FileDescriptor: The file that contains the specified symbol.

    Raises:
      KeyError: if the file cannot be found in the descriptor database.
    """
    try:
      file_proto = self._internal_db.FindFileContainingSymbol(symbol)
    except KeyError as error:
      if self._descriptor_db:
        file_proto = self._descriptor_db.FindFileContainingSymbol(symbol)
      else:
        raise error
    if not file_proto:
      raise KeyError('Cannot find a file containing %s' % symbol)
    return self._ConvertFileProtoToFileDescriptor(file_proto) 
開發者ID:luci,項目名稱:luci-py,代碼行數:24,代碼來源:descriptor_pool.py

示例11: AddEnumDescriptor

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import FileDescriptor [as 別名]
def AddEnumDescriptor(self, enum_desc):
    """Adds an EnumDescriptor to the pool.

    This method also registers the FileDescriptor associated with the enum.

    Args:
      enum_desc: An EnumDescriptor.
    """

    if not isinstance(enum_desc, descriptor.EnumDescriptor):
      raise TypeError('Expected instance of descriptor.EnumDescriptor.')

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

示例12: _AddFileDescriptor

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

    If the FileDescriptor contains messages or enums, the caller must explicitly
    register them.

    Args:
      file_desc: A FileDescriptor.
    """

    if not isinstance(file_desc, descriptor.FileDescriptor):
      raise TypeError('Expected instance of descriptor.FileDescriptor.')
    self._file_descriptors[file_desc.name] = file_desc 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:15,代碼來源:descriptor_pool.py

示例13: FindFileByName

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import FileDescriptor [as 別名]
def FindFileByName(self, file_name):
    """Gets a FileDescriptor by file name.

    Args:
      file_name: The path to the file to get a descriptor for.

    Returns:
      A FileDescriptor for the named file.

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

    try:
      return self._file_descriptors[file_name]
    except KeyError:
      pass

    try:
      file_proto = self._internal_db.FindFileByName(file_name)
    except KeyError as error:
      if self._descriptor_db:
        file_proto = self._descriptor_db.FindFileByName(file_name)
      else:
        raise error
    if not file_proto:
      raise KeyError('Cannot find a file named %s' % file_name)
    return self._ConvertFileProtoToFileDescriptor(file_proto) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:30,代碼來源:descriptor_pool.py

示例14: FindExtensionByName

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

    Args:
      full_name: The full name of the extension descriptor to load.

    Returns:
      A FieldDescriptor, describing the named extension.

    Raises:
      KeyError: if the extension cannot be found in the pool.
    """
    full_name = _NormalizeFullyQualifiedName(full_name)
    try:
      # The proto compiler does not give any link between the FileDescriptor
      # and top-level extensions unless the FileDescriptorProto is added to
      # the DescriptorDatabase, but this can impact memory usage.
      # So we registered these extensions by name explicitly.
      return self._toplevel_extensions[full_name]
    except KeyError:
      pass
    message_name, _, extension_name = full_name.rpartition('.')
    try:
      # Most extensions are nested inside a message.
      scope = self.FindMessageTypeByName(message_name)
    except KeyError:
      # Some extensions are defined at file scope.
      scope = self._FindFileContainingSymbolInDb(full_name)
    return scope.extensions_by_name[extension_name] 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:31,代碼來源:descriptor_pool.py

示例15: testFindFileByName

# 需要導入模塊: from google.protobuf import descriptor [as 別名]
# 或者: from google.protobuf.descriptor import FileDescriptor [as 別名]
def testFindFileByName(self):
    name1 = 'google/protobuf/internal/factory_test1.proto'
    file_desc1 = self.pool.FindFileByName(name1)
    self.assertIsInstance(file_desc1, descriptor.FileDescriptor)
    self.assertEqual(name1, file_desc1.name)
    self.assertEqual('google.protobuf.python.internal', file_desc1.package)
    self.assertIn('Factory1Message', file_desc1.message_types_by_name)

    name2 = 'google/protobuf/internal/factory_test2.proto'
    file_desc2 = self.pool.FindFileByName(name2)
    self.assertIsInstance(file_desc2, descriptor.FileDescriptor)
    self.assertEqual(name2, file_desc2.name)
    self.assertEqual('google.protobuf.python.internal', file_desc2.package)
    self.assertIn('Factory2Message', file_desc2.message_types_by_name) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:16,代碼來源:descriptor_pool_test.py


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