Google Code offered in: English - Español - 日本語 - 한국어 - Português - Pусский - 中文(简体) - 中文(繁體)
ProtoRPC is an experimental, innovative, and rapidly changing new feature for App Engine. Unfortunately, being on the bleeding edge means that we may make backwards-incompatible changes to ProtoRPC. We will inform the community when this feature is no longer experimental.
The descriptor.py
module contains message definitions and functions for converting ProtoRPC definitions into a transmittable message format.
Describing an Enum instance, Enum class, Field class, or Message class generates an appropriate descriptor object. A descriptor object is an object that describes other ProtoRPC definitions such as enums, messages, and services. You can use this message to transmit information to clients wishing to know the description of an enum value, enum, field or message without needing to download the source code. This format is also compatible with other, non-Python languages.
The descriptors are modeled to be binary compatible with http://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto
Note! The names of types and fields defined in descriptor.py
do not necessarily match those defined in descriptor.proto
. ProtoRPC is designed this way to make source code files that use these descriptors easier to read. For example, FieldDescriptors need to be prefixed with TYPE
in descriptor.proto
, but not in descriptor.py
.
The following code sample demonstrates use of the descriptor module to describe a class called Pixel
using the MessageDescriptor
class.
from protorpc import descriptor from protorpc import messages class Pixel(messages.Message): x = messages.IntegerField(1, required=True) y = messages.IntegerField(2, required=True) color = messages.BytesField(3) # Describe Pixel class using message descriptor. fields = [ descriptor.FieldDescriptor(name='x', number=1, label=descriptor.FieldDescriptor.Label.REQUIRED, variant=descriptor.FieldDescriptor.Variant.INT64), descriptor.FieldDescriptor(name='y', number=2, label=descriptor.FieldDescriptor.Label.REQUIRED, variant=descriptor.FieldDescriptor.Variant.INT64), descriptor.FieldDescriptor(name='color', number = 3, label=descriptor.FieldDescriptor.Label.OPTIONAL, variant=descriptor.FieldDescriptor.Variant.BYTES)] message = descriptor.MessageDescriptor(name='Pixel', fields=fields) # Describing is the equivalent of building the above message. message == definition.describe_message(Pixel)
The protorpc.descriptor
package provides the following functions:
Describes any value as a descriptor. You can use this helper function to describe any object with an appropriate descriptor object.
Arguments:
Returns a descriptor if the object is describable as a descriptor, else None.
Builds a descriptor from an Enum class.
Arguments:
Returns an initialized EnumDescriptor instance describing the Enum instance.
EnumDescriptor Class fields:
name
values
Builds a descriptor from an Enum instance.
Arguments:
Returns an initialized EnumValueDescriptor instance describing the Enum instance.
EnumValueDescriptor Class fields:
name
number
Builds a descriptor from a Field instance.
Arguments:
Returns an initialized FieldDescriptor instance describing the Field instance with a list of Enums and fields.
FieldDescriptor Class Enums:
Variant
Label
FieldDescriptor Class fields:
name
number
variant
type_name
default_value
Builds a file from a specified Python module.
Arguments:
Returns an initialized FileDescriptor instance describing the module.
FileDescriptor Class fields
package
message_types
enum_types
service_types
Builds a file set from the specified Python modules.
Arguments:
Returns an initialized FileSet instance describing the module.
FileSet Class fields:
files
Builds a descriptor from a Message class.
Arguments:
Returns an initialized MessageDescriptor instance describing the Message class.
MessageDescriptor Class fields:
name
fields
message_types
enum_types
Builds a descriptor from a remote service method.
Arguments:
Returns an initialized MethodDescriptor instance describing the remote service method.
MethodDescriptor fields:
name
request_type
response_type
Builds a descriptor from a Service class.
Arguments:
Returns an initialized ServiceDescriptor instance describing the service.
ServiceDescriptor fields:
name
methods
Finds objects by importing modules as needed. A definition loader is a function that resolves a definition name to a descriptor. The import finder resolves definitions to their names by importing modules when necessary.
Arguments:
Returns an appropriate descriptor from any describable type located by name.
Raises a DefinitionNotFoundError when a name does not refer to either a definition or a module.