Package google :: Package protobuf :: Module descriptor_pool :: Class DescriptorPool
[hide private]
[frames] | no frames]

Class DescriptorPool

source code

object --+
         |
        DescriptorPool

A collection of protobufs dynamically constructed by descriptor protos.

Instance Methods [hide private]
a new object with type S, a subtype of T
__new__(cls, descriptor_db=None) source code
 
__init__(self, descriptor_db=None)
Initializes a Pool of proto buffs.
source code
 
_CheckConflictRegister(self, desc, desc_name, file_name)
Check if the descriptor name conflicts with another of the same name.
source code
 
Add(self, file_desc_proto)
Adds the FileDescriptorProto and its types to this pool.
source code
 
AddSerializedFile(self, serialized_file_desc_proto)
Adds the FileDescriptorProto and its types to this pool.
source code
 
AddDescriptor(*args, **kwargs) source code
 
_AddDescriptor(self, desc)
Adds a Descriptor to the pool, non-recursively.
source code
 
AddEnumDescriptor(*args, **kwargs) source code
 
_AddEnumDescriptor(self, enum_desc)
Adds an EnumDescriptor to the pool.
source code
 
AddServiceDescriptor(*args, **kwargs) source code
 
_AddServiceDescriptor(self, service_desc)
Adds a ServiceDescriptor to the pool.
source code
 
AddExtensionDescriptor(*args, **kwargs) source code
 
_AddExtensionDescriptor(self, extension)
Adds a FieldDescriptor describing an extension to the pool.
source code
 
AddFileDescriptor(*args, **kwargs) source code
 
_InternalAddFileDescriptor(self, file_desc)
Adds a FileDescriptor to the pool, non-recursively.
source code
 
_AddFileDescriptor(self, file_desc)
Adds a FileDescriptor to the pool, non-recursively.
source code
 
FindFileByName(self, file_name)
Gets a FileDescriptor by file name.
source code
 
FindFileContainingSymbol(self, symbol)
Gets the FileDescriptor for the file containing the specified symbol.
source code
 
_InternalFindFileContainingSymbol(self, symbol)
Gets the already built FileDescriptor containing the specified symbol.
source code
 
FindMessageTypeByName(self, full_name)
Loads the named descriptor from the pool.
source code
 
FindEnumTypeByName(self, full_name)
Loads the named enum descriptor from the pool.
source code
 
FindFieldByName(self, full_name)
Loads the named field descriptor from the pool.
source code
 
FindOneofByName(self, full_name)
Loads the named oneof descriptor from the pool.
source code
 
FindExtensionByName(self, full_name)
Loads the named extension descriptor from the pool.
source code
 
FindExtensionByNumber(self, message_descriptor, number)
Gets the extension of the specified message with the specified number.
source code
 
FindAllExtensions(self, message_descriptor)
Gets all the known extension of a given message.
source code
 
_TryLoadExtensionFromDB(self, message_descriptor, number)
Try to Load extensions from decriptor db.
source code
 
FindServiceByName(self, full_name)
Loads the named service descriptor from the pool.
source code
 
FindMethodByName(self, full_name)
Loads the named service method descriptor from the pool.
source code
 
_FindFileContainingSymbolInDb(self, symbol)
Finds the file in descriptor DB containing the specified symbol.
source code
 
_ConvertFileProtoToFileDescriptor(self, file_proto)
Creates a FileDescriptor from a proto or returns a cached copy.
source code
 
_ConvertMessageDescriptor(self, desc_proto, package=None, file_desc=None, scope=None, syntax=None)
Adds the proto to the pool in the specified package.
source code
 
_ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None, containing_type=None, scope=None, top_level=False)
Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf.
source code
 
_MakeFieldDescriptor(self, field_proto, message_name, index, file_desc, is_extension=False)
Creates a field descriptor from a FieldDescriptorProto.
source code
 
_SetAllFieldTypes(self, package, desc_proto, scope)
Sets all the descriptor's fields's types.
source code
 
_SetFieldType(self, field_proto, field_desc, package, scope)
Sets the field's type, cpp_type, message_type and enum_type.
source code
 
_MakeEnumValueDescriptor(self, value_proto, index)
Creates a enum value descriptor object from a enum value proto.
source code
 
_MakeServiceDescriptor(self, service_proto, service_index, scope, package, file_desc)
Make a protobuf ServiceDescriptor given a ServiceDescriptorProto.
source code
 
_MakeMethodDescriptor(self, method_proto, service_name, package, scope, index)
Creates a method descriptor from a MethodDescriptorProto.
source code
 
_ExtractSymbols(self, descriptors)
Pulls out all the symbols from descriptor protos.
source code
 
_GetDeps(self, dependencies)
Recursively finds dependencies for file protos.
source code
 
_GetTypeFromScope(self, package, type_name, scope)
Finds a given type name in the current scope.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__new__(cls, descriptor_db=None)

source code 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__
(inherited documentation)

__init__(self, descriptor_db=None)
(Constructor)

source code 
Initializes a Pool of proto buffs.

The descriptor_db argument to the constructor is provided to allow
specialized file descriptor proto lookup code to be triggered on demand. An
example would be an implementation which will read and compile a file
specified in a call to FindFileByName() and not require the call to Add()
at all. Results from this database will be cached internally here as well.

Args:
  descriptor_db: A secondary source of file descriptors.

Overrides: object.__init__

_CheckConflictRegister(self, desc, desc_name, file_name)

source code 
Check if the descriptor name conflicts with another of the same name.

Args:
  desc: Descriptor of a message, enum, service, extension or enum value.
  desc_name: the full name of desc.
  file_name: The file name of descriptor.

Add(self, file_desc_proto)

source code 
Adds the FileDescriptorProto and its types to this pool.

Args:
  file_desc_proto: The FileDescriptorProto to add.

AddSerializedFile(self, serialized_file_desc_proto)

source code 
Adds the FileDescriptorProto and its types to this pool.

Args:
  serialized_file_desc_proto: A bytes string, serialization of the
    FileDescriptorProto to add.

AddDescriptor(*args, **kwargs)

source code 
Decorators:
  • @_Deprecated

_AddDescriptor(self, desc)

source code 
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.

AddEnumDescriptor(*args, **kwargs)

source code 
Decorators:
  • @_Deprecated

_AddEnumDescriptor(self, enum_desc)

source code 
Adds an EnumDescriptor to the pool.

This method also registers the FileDescriptor associated with the enum.

Args:
  enum_desc: An EnumDescriptor.

AddServiceDescriptor(*args, **kwargs)

source code 
Decorators:
  • @_Deprecated

_AddServiceDescriptor(self, service_desc)

source code 
Adds a ServiceDescriptor to the pool.

Args:
  service_desc: A ServiceDescriptor.

AddExtensionDescriptor(*args, **kwargs)

source code 
Decorators:
  • @_Deprecated

_AddExtensionDescriptor(self, extension)

source code 
Adds a FieldDescriptor describing an extension to the pool.

Args:
  extension: A FieldDescriptor.

Raises:
  AssertionError: when another extension with the same number extends the
    same message.
  TypeError: when the specified extension is not a
    descriptor.FieldDescriptor.

AddFileDescriptor(*args, **kwargs)

source code 
Decorators:
  • @_Deprecated

_InternalAddFileDescriptor(self, file_desc)

source code 
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.

_AddFileDescriptor(self, file_desc)

source code 
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.

FindFileByName(self, file_name)

source code 
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.

FindFileContainingSymbol(self, symbol)

source code 
Gets the FileDescriptor for the file 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 pool.

_InternalFindFileContainingSymbol(self, symbol)

source code 
Gets the already built FileDescriptor 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 pool.

FindMessageTypeByName(self, full_name)

source code 
Loads the named descriptor from the pool.

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

Returns:
  The descriptor for the named type.

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

FindEnumTypeByName(self, full_name)

source code 
Loads the named enum descriptor from the pool.

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

Returns:
  The enum descriptor for the named type.

Raises:
  KeyError: if the enum cannot be found in the pool.

FindFieldByName(self, full_name)

source code 
Loads the named field descriptor from the pool.

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

Returns:
  The field descriptor for the named field.

Raises:
  KeyError: if the field cannot be found in the pool.

FindOneofByName(self, full_name)

source code 
Loads the named oneof descriptor from the pool.

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

Returns:
  The oneof descriptor for the named oneof.

Raises:
  KeyError: if the oneof cannot be found in the pool.

FindExtensionByName(self, full_name)

source code 
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.

FindExtensionByNumber(self, message_descriptor, number)

source code 
Gets the extension of the specified message with the specified number.

Extensions have to be registered to this pool by calling
AddExtensionDescriptor.

Args:
  message_descriptor: descriptor of the extended message.
  number: integer, number of the extension field.

Returns:
  A FieldDescriptor describing the extension.

Raises:
  KeyError: when no extension with the given number is known for the
    specified message.

FindAllExtensions(self, message_descriptor)

source code 
Gets all the known extension of a given message.

Extensions have to be registered to this pool by calling
AddExtensionDescriptor.

Args:
  message_descriptor: descriptor of the extended message.

Returns:
  A list of FieldDescriptor describing the extensions.

_TryLoadExtensionFromDB(self, message_descriptor, number)

source code 
Try to Load extensions from decriptor db.

Args:
  message_descriptor: descriptor of the extended message.
  number: the extension number that needs to be loaded.

FindServiceByName(self, full_name)

source code 
Loads the named service descriptor from the pool.

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

Returns:
  The service descriptor for the named service.

Raises:
  KeyError: if the service cannot be found in the pool.

FindMethodByName(self, full_name)

source code 
Loads the named service method descriptor from the pool.

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

Returns:
  The method descriptor for the service method.

Raises:
  KeyError: if the method cannot be found in the pool.

_FindFileContainingSymbolInDb(self, symbol)

source code 
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.

_ConvertFileProtoToFileDescriptor(self, file_proto)

source code 
Creates a FileDescriptor from a proto or returns a cached copy.

This method also has the side effect of loading all the symbols found in
the file into the appropriate dictionaries in the pool.

Args:
  file_proto: The proto to convert.

Returns:
  A FileDescriptor matching the passed in proto.

_ConvertMessageDescriptor(self, desc_proto, package=None, file_desc=None, scope=None, syntax=None)

source code 
Adds the proto to the pool in the specified package.

Args:
  desc_proto: The descriptor_pb2.DescriptorProto protobuf message.
  package: The package the proto should be located in.
  file_desc: The file containing this message.
  scope: Dict mapping short and full symbols to message and enum types.
  syntax: string indicating syntax of the file ("proto2" or "proto3")

Returns:
  The added descriptor.

_ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None, containing_type=None, scope=None, top_level=False)

source code 
Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf.

Args:
  enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message.
  package: Optional package name for the new message EnumDescriptor.
  file_desc: The file containing the enum descriptor.
  containing_type: The type containing this enum.
  scope: Scope containing available types.
  top_level: If True, the enum is a top level symbol. If False, the enum
      is defined inside a message.

Returns:
  The added descriptor

_MakeFieldDescriptor(self, field_proto, message_name, index, file_desc, is_extension=False)

source code 
Creates a field descriptor from a FieldDescriptorProto.

For message and enum type fields, this method will do a look up
in the pool for the appropriate descriptor for that type. If it
is unavailable, it will fall back to the _source function to
create it. If this type is still unavailable, construction will
fail.

Args:
  field_proto: The proto describing the field.
  message_name: The name of the containing message.
  index: Index of the field
  file_desc: The file containing the field descriptor.
  is_extension: Indication that this field is for an extension.

Returns:
  An initialized FieldDescriptor object

_SetAllFieldTypes(self, package, desc_proto, scope)

source code 
Sets all the descriptor's fields's types.

This method also sets the containing types on any extensions.

Args:
  package: The current package of desc_proto.
  desc_proto: The message descriptor to update.
  scope: Enclosing scope of available types.

_SetFieldType(self, field_proto, field_desc, package, scope)

source code 
Sets the field's type, cpp_type, message_type and enum_type.

Args:
  field_proto: Data about the field in proto format.
  field_desc: The descriptor to modiy.
  package: The package the field's container is in.
  scope: Enclosing scope of available types.

_MakeEnumValueDescriptor(self, value_proto, index)

source code 
Creates a enum value descriptor object from a enum value proto.

Args:
  value_proto: The proto describing the enum value.
  index: The index of the enum value.

Returns:
  An initialized EnumValueDescriptor object.

_MakeServiceDescriptor(self, service_proto, service_index, scope, package, file_desc)

source code 
Make a protobuf ServiceDescriptor given a ServiceDescriptorProto.

Args:
  service_proto: The descriptor_pb2.ServiceDescriptorProto protobuf message.
  service_index: The index of the service in the File.
  scope: Dict mapping short and full symbols to message and enum types.
  package: Optional package name for the new message EnumDescriptor.
  file_desc: The file containing the service descriptor.

Returns:
  The added descriptor.

_MakeMethodDescriptor(self, method_proto, service_name, package, scope, index)

source code 
Creates a method descriptor from a MethodDescriptorProto.

Args:
  method_proto: The proto describing the method.
  service_name: The name of the containing service.
  package: Optional package name to look up for types.
  scope: Scope containing available types.
  index: Index of the method in the service.

Returns:
  An initialized MethodDescriptor object.

_ExtractSymbols(self, descriptors)

source code 
Pulls out all the symbols from descriptor protos.

Args:
  descriptors: The messages to extract descriptors from.
Yields:
  A two element tuple of the type name and descriptor object.

_GetDeps(self, dependencies)

source code 
Recursively finds dependencies for file protos.

Args:
  dependencies: The names of the files being depended on.

Yields:
  Each direct and indirect dependency.

_GetTypeFromScope(self, package, type_name, scope)

source code 
Finds a given type name in the current scope.

Args:
  package: The package the proto should be located in.
  type_name: The name of the type to be found in the scope.
  scope: Dict mapping short and full symbols to message and enum types.

Returns:
  The descriptor for the requested type.