Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



The EnumField Class

The EnumField class provides definitions for enum values. Enum fields may have default values that are delayed until the associated enum type is resolved. This is necessary to support certain circular references. For example:

from protorpc import messages

class Message1(messages.Message):

    class Color(messages.Enum):  
        RED = 1
        GREEN = 2
        BLUE = 3

    # Validate this field's default value when default is accessed.
    animal = messages.EnumField('Message2.Animal', 1, default='HORSE')

class Message2(messages.Message):

    class Animal(messages.Enum):
        DOG = 1
        CAT = 2
        HORSE = 3

    # This fields default value will be validated right away since Color is
    # already fully resolved.
    color = messages.EnumField(Message1.Color, 1, default='RED')

EnumField is provided by the protorpc.messages module.

  1. EnumField()
  2. Class Properties
  3. Instance Methods

Constructor

The constructor of the EnumField class is defined as follows:

class EnumField ( enum_type , number , required , repeated , variant , default )

Provides a field definition for Enum values.

Arguments

enum_type
The Enum type for a field. Must be a subclass of Enum .
number
The number of the field. Must be unique per message class.
required
Whether or not this field is required. Mutually exclusive with the repeated argument; do not specify repeated if you use required .
repeated
Whether or not this field is repeated. Mutually exclusive with the required argument; do not specify required if you use repeated .
variant
Further specifies the type of field. Some field types are further restrained based on the underlying wire format. Best practice is to use the default value, but developers can use this field to declare an integer field as a 32-bit integer vs. the default 64 bit.
default
Default value to use for the field if it is not found in stream.

Raises a FieldDefinitionError when enum_type is invalid.

Class Properties

The EnumField class provides the following class properties:

type ()
Enum type used for the field.
default ()
Default for the enum field. If the default value is unresolved, uses Enum type as the default.

Instance Methods

EnumField instances have the following method:

validate_default_element ( value )
Validates the default element of the Enum field. Enum fields allow for delayed resolution of default values when the type of the field has not been resolved. The default value of a field may be a string or an integer. If the Enum type of the field has been resolved, the default value is validated against that type.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.