The protorpc.definition
package provides the following functions:
- define_enum(enum_descriptor, module_name)
-
Defines an Enum class for a descriptor.
Arguments- enum_descriptor
- EnumDescriptor to use to build the Enum class.
- module_name
- Module name to give the new descriptor class.
Returns a new messages.Enum subclass as described by
enum_descriptor
. - define_field(field_descriptor)
-
Defines a Field instance from the provided descriptor.
Arguments- field_descriptor
- FieldDescriptor class to use to build the Field instance.
Returns a new field instance as described by
field_descriptor
. - define_message(message_descriptor, module_name)
-
Defines a Message class from the provided descriptor.
Arguments- message_descriptor
- MessageDescriptor to use to describe the message class.
- module_name
- The module name to give the new descriptor class.
Returns a new messages.Message sub-class as described by
message_descriptor
. - define_service(service_descriptor, module)
-
Defines a new service proxy.
Arguments- service_descriptor
- ServiceDescriptor class that describes the service.
- module
- The module to add the service to. Request and response types are found relative to this module.
Returns a class proxy capable of communicating with a remote server.
- define_file(file_descriptor, module=None)
-
Defines a module from the given file descriptor.
Arguments- file_descriptor
- FileDescriptor instance from which to describe the module.
- module=None
- Module to which to add contained objects. Module name overrides value in file_descriptor.package. Definitions are added to the existing module if provided.
If no module is provided, creates a new module with its name set to the file descriptor's package. If a module is provided, returns the same module.
- import_file(file_descriptor, modules=None)
-
Imports a FileDescriptor into a module space. Similar to define_file(), except that a new module and any required parent modules are created and added to the modules parameter, or sys.modules if not provided.
Arguments- file_descriptor
- FileDescriptor instance from which to describe the module.
- modulesmodules=None
- Dictionary of modules to update. Modules and their parents that
do not exist will be created. If an existing module is found that
matches
file_descriptor.package
, that module is updated with the FileDescriptor contents.
Returns matches to the
modules
argument, or a new module if no matches are found. - import_file_set(file_set, modules=None)
-
Arguments
- file_set
- Either a string or a FileSet instance. If a string, import_file_set() opens the file and reads the serialized FileSet. If a FileSet instance, imports definitions from this instance.
- modules
- Dictionary of modules to update. Modules and their parents that do not exist will be created. If an existing module is found that matches the
file_descriptor.package
, that module is updated with the FileDescriptor contents.