
                           S r SSKrSSKrSSKrSSKJr  / SQr\R                  r " S S\5      r " S S\5      r	 " S	 S
\	5      r
 " S S\	5      r " S S\	5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\" / SQ5      r\" / SQ5      r\" S/5      rSrSrSrS r " S! S"\5      r " S# S$\5      r " S% S&\R<                  " \\5      5      r  " S' S(\ 5      r! " S) S*\5      r" " S+ S,\R<                  " \"\5      5      r# " S- S.\$5      r% " S/ S0\5      r& " S1 S2\R<                  " \&\5      5      r' " S3 S4\'5      r( " S5 S6\'5      r) " S7 S8\'5      r* " S9 S:\'5      r+ " S; S<\'5      r, " S= S>\'5      r- " S? S@\'5      r.\R^                  " SA5      S\04SB j5       r1g)Ca  Stand-alone implementation of in memory protocol messages.

Public Classes:
  Enum: Represents an enumerated type.
  Variant: Hint for wire format to determine how to serialize.
  Message: Base class for user defined messages.
  IntegerField: Field for integer values.
  FloatField: Field for float values.
  BooleanField: Field for boolean values.
  BytesField: Field for binary string values.
  StringField: Field for UTF-8 string values.
  MessageField: Field for other message type values.
  EnumField: Field for enumerated type values.

Public Exceptions (indentation indications class hierarchy):
  EnumDefinitionError: Raised when enumeration is incorrectly defined.
  FieldDefinitionError: Raised when field is incorrectly defined.
    InvalidVariantError: Raised when variant is not compatible with field type.
    InvalidDefaultError: Raised when default is not compatiable with field.
    InvalidNumberError: Raised when field number is out of range or reserved.
  MessageDefinitionError: Raised when message is incorrectly defined.
    DuplicateNumberError: Raised when field has duplicate number with another.
  ValidationError: Raised when a message or field is not valid.
  DefinitionNotFoundError: Raised when definition not found.
    N)util)MAX_ENUM_VALUEMAX_FIELD_NUMBERFIRST_RESERVED_FIELD_NUMBERLAST_RESERVED_FIELD_NUMBEREnumField	FieldListVariantMessageIntegerField
FloatFieldBooleanField
BytesFieldStringFieldMessageField	EnumFieldfind_definitionErrorDecodeErrorEncodeErrorEnumDefinitionErrorFieldDefinitionErrorInvalidVariantErrorInvalidDefaultErrorInvalidNumberErrorMessageDefinitionErrorDuplicateNumberErrorValidationErrorDefinitionNotFoundErrorc                       \ rS rSrSrSrg)r   _   zEnumeration definition error. N__name__
__module____qualname____firstlineno____doc____static_attributes__r#       6lib/third_party/apitools/base/protorpclite/messages.pyr   r   _   s    'r+   r   c                       \ rS rSrSrSrg)r   c   zField definition error.r#   Nr$   r#   r+   r,   r   r   c   s    !r+   r   c                       \ rS rSrSrSrg)r   g   z"Invalid variant provided to field.r#   Nr$   r#   r+   r,   r   r   g       ,r+   r   c                       \ rS rSrSrSrg)r   k   z"Invalid default provided to field.r#   Nr$   r#   r+   r,   r   r   k   r1   r+   r   c                       \ rS rSrSrSrg)r   o   z!Invalid number provided to field.r#   Nr$   r#   r+   r,   r   r   o   s    +r+   r   c                       \ rS rSrSrSrg)r   s   zMessage definition error.r#   Nr$   r#   r+   r,   r   r   s   s    #r+   r   c                       \ rS rSrSrSrg)r   w   z#Duplicate number assigned to field.r#   Nr$   r#   r+   r,   r   r   w   s    -r+   r   c                       \ rS rSrSrSrg)r    {   z$Raised when definition is not found.r#   Nr$   r#   r+   r,   r    r    {   s    .r+   r    c                       \ rS rSrSrSrg)r      z/Error found decoding message from encoded form.r#   Nr$   r#   r+   r,   r   r      s    9r+   r   c                       \ rS rSrSrSrg)r      z"Error found when encoding message.r#   Nr$   r#   r+   r,   r   r      r1   r+   r   c                       \ rS rSrSrS rSrg)r      z Invalid value for message error.c                 ,    [         R                  U 5      $ )z6Prints string with field name if present on exception.)r   __str__selfs    r,   rC   ValidationError.__str__   s    }}T""r+   r#   N)r%   r&   r'   r(   r)   rC   r*   r#   r+   r,   r   r      s
    *#r+   r   )r&   r)   r'   r*   r(   )name_message_definition_MessageField__type_EnumField__type_EnumField__resolved_defaultrH   ii8J  iN  c                   F    \ rS rSrSrSrS rS rS rS r	S r
S	 rS
 rSrg)_DefinitionClass   a]  Base meta-class used for definition meta-classes.

The Enum and Message definition classes share some basic functionality.
Both of these classes may be contained by a Message definition.  After
initialization, neither class may have attributes changed
except for the protected _message_definition attribute, and that attribute
may change only once.
Fc                 j    [         R                  XX#5        U R                  [        4:w  a  SU l        gg)zConstructor.TN)type__init__	__bases__object_DefinitionClass__initializedclsrG   basesdcts       r,   rQ   _DefinitionClass.__init__   s+    c,==VI% $C &r+   c                 D     U R                  5       $ ! [         a     gf = f)zGet outer Message definition that contains this definition.

Returns:
  Containing Message definition if definition is contained within one,
  else None.
NrH   AttributeErrorrV   s    r,   message_definition#_DefinitionClass.message_definition   s(    	**,, 		    
c                     U R                   (       a  U[        ;  a  [        SU-  5      e[        R	                  XU5        g)a  Overridden to avoid setting variables after init.

Setting attributes on a class must work during the period of
initialization to set the enumation value class variables and
build the name/number maps. Once __init__ has set the
__initialized flag to True prohibits setting any more values
on the class. The class is in effect frozen.

Args:
  name: Name of value to set.
  value: Value to set.

zMay not change values: %sN)rT   _POST_INIT_ATTRIBUTE_NAMESr\   rP   __setattr__)rV   rG   values      r,   rc   _DefinitionClass.__setattr__   s6     -G!G !<t!CDDS.r+   c                     [        S5      e)zAOverridden so that cannot delete varaibles on definition classes.z-May not delete attributes on definition class	TypeErrorrV   rG   s     r,   __delattr___DefinitionClass.__delattr__   s    GHHr+   c                     U R                  5       nUc   [        R                  " U R                  5      $ U< SU R                  < 3$ )aT  Helper method for creating definition name.

Names will be generated to include the classes package name,
scope (if the class is nested in another definition) and class
name.

By default, the package name for a definition is derived from
its module name. However, this value can be overriden by
placing a 'package' attribute in the module that contains the
definition class. For example:

  package = 'some.alternate.package'

  class MyMessage(Message):
    ...

  >>> MyMessage.definition_name()
  some.alternate.package.MyMessage

Returns:
  Dot-separated fully qualified name of definition.

.)outer_definition_namesix	text_typer%   )rV   rn   s     r,   definition_name _DefinitionClass.definition_name   s;    0 !$ 9 9 ; (==..0#,,??r+   c                     U R                  5       nU(       d   [        R                  " U R                  5      $ UR	                  5       $ )zHelper method for creating outer definition name.

Returns:
  If definition is nested, will return the outer definitions
  name, else the package name.

)r^   r   get_package_for_moduler&   rq   rV   outer_definitions     r,   rn   &_DefinitionClass.outer_definition_name   s:     113..s~~>>//11r+   c                     U R                  5       nU(       d   [        R                  " U R                  5      $ UR	                  5       $ )zyHelper method for creating creating the package of a definition.

Returns:
  Name of package that definition belongs to.
)r^   r   rt   r&   definition_packageru   s     r,   ry   #_DefinitionClass.definition_package  s:     113..s~~>>2244r+   r#   N)r%   r&   r'   r(   r)   rT   rQ   r^   rc   rj   rq   rn   ry   r*   r#   r+   r,   rM   rM      s3     M%
/&I@:2	5r+   rM   c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)
_EnumClassi  a  Meta-class used for defining the Enum base class.

Meta-class enables very specific behavior for any defined Enum
class.  All attributes defined on an Enum sub-class must be integers.
Each attribute defined on an Enum sub-class is translated
into an instance of that sub-class, with the name of the attribute
as its name, and the number provided as its value.  It also ensures
that only one level of Enum class hierarchy is possible.  In other
words it is not possible to delcare sub-classes of sub-classes of
Enum.

This class also defines some functions in order to restrict the
behavior of the Enum class and its sub-classes.  It is not possible
to change the behavior of the Enum class in later classes since
any new classes may be defined with only integer values, and no methods.
c                    U[         4:X  d  U[        4:X  d  [        SU-  5      e0 U l        0 U l        U[         4:w  Ga%  UR                  5        GH  u  pEU[        ;   a  M  [        U[        R                  5      (       d  [        SU< SU< 35      eUS:  a  [        SXE4-  5      eU[        :  a  [        S[        XE4-  5      eXPR                  ;   a'  [        SXEU R                  U   R                  4-  5      e[         R                  U 5      nU R                  XdU5        X`R                  UR                  '   X`R                  UR                  '   [        XU5        GM     [         R                  XX#5        g )Nz'Enum type %s may only inherit from Enumz3May only use integers in Enum definitions.  Found:  = r   z2Must use non-negative enum values.  Found: %s = %dz;Must use enum values less than or equal %d.  Found: %s = %dz(Value for %s = %d is already defined: %s)rS   r   r   _EnumClass__by_number_EnumClass__by_nameitems_RESERVED_ATTRIBUTE_NAMES
isinstancero   integer_typesr   rG   __new__rQ   numbersetattrrM   )rV   rG   rW   rX   	attributerd   instances          r,   rQ   _EnumClass.__init__+  s{   &"ew&6%9D@B B  VI$'IIK 	  99 "%):):;;- #E+, , 19-L"*+, , >)-)':;< <
 OO+-B"3??5+A+F+FGHI I
 ">>#.X%8/7hmm,3;01K %0N 	!!#U8r+   c                 H    [        U R                  R                  5       5      $ )zhIterate over all values of enum.

Yields:
  Enumeration instances of the Enum class in arbitrary order.
)iterr   valuesr]   s    r,   __iter___EnumClass.__iter__`  s     COO**,--r+   c                 6    U R                   R                  5       $ )zaGet all names for Enum.

Returns:
  An iterator for names of the enumeration in arbitrary order.
)r   keysr]   s    r,   names_EnumClass.namesh  s     }}!!##r+   c                 6    U R                   R                  5       $ )ziGet all numbers for Enum.

Returns:
  An iterator for all numbers of the enumeration in arbitrary order.
)r   r   r]   s    r,   numbers_EnumClass.numbersp  s     ##%%r+   c                      U R                   U   $ )znLook up Enum by name.

Args:
  name: Name of enum to find.

Returns:
  Enum sub-class instance of that value.
)r   ri   s     r,   lookup_by_name_EnumClass.lookup_by_namex  s     }}T""r+   c                      U R                   U   $ )ztLook up Enum by number.

Args:
  number: Number of enum to find.

Returns:
  Enum sub-class instance of that value.
)r   rV   r   s     r,   lookup_by_number_EnumClass.lookup_by_number  s     v&&r+   c                 ,    [        U R                  5      $ N)lenr   r]   s    r,   __len___EnumClass.__len__  s    3==!!r+   r#   N)r%   r&   r'   r(   r)   rQ   r   r   r   r   r   r   r*   r#   r+   r,   r|   r|     s+    "39j.$&	#	'"r+   r|   c                       \ rS rSrSr\" S5      rS rSS jrS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS r\S 5       r\S 5       rSrg)r   i  z$Base class for all enumerated types.rG   r   c                 d   [        X5      (       a  U$ [        U[        R                  5      (       a   U R                  U5      $ [        U[        R
                  5      (       a   U R                  U5      $ [        SU< SU R                  < 35      e! [         a     NZf = f! [         a     N9f = f)a  Acts as look-up routine after class is initialized.

The purpose of overriding __new__ is to provide a way to treat
Enum subclasses as casting types, similar to how the int type
functions.  A program can pass a string or an integer and this
method with "convert" that value in to an appropriate Enum instance.

Args:
  index: Name or number to look up.  During initialization
    this is always the name of the new enum value.

Raises:
  TypeError: When an inappropriate index value is passed provided.
zNo such value for z	 in Enum )	r   ro   r   r   KeyErrorstring_typesr   rh   r%   )rV   indexs     r,   r   Enum.__new__  s      e!!L eS..//++E22
 eS--..))%00 . / 	/    s#   B $B" 
BB"
B/.B/Nc                     [        [        U 5      S5      (       a  g[        R                  U SU5        [        R                  U SU5        g)zInitialize new Enum instance.

Since this should only be called during class initialization any
calls that happen after the class is frozen raises an exception.
rT   NrG   r   )getattrrP   rS   rc   )rE   rG   r   s      r,   rQ   Enum.__init__  s=     4:>??4.462r+   c                     [        S5      e)NzMay not change enum valuesrg   rE   rG   rd   s      r,   rc   Enum.__setattr__  s    455r+   c                     U R                   $ r   )rG   rD   s    r,   rC   Enum.__str__  s    yyr+   c                     U R                   $ r   r   rD   s    r,   __int__Enum.__int__  s    {{r+   c                 `    S[        U 5      R                  U R                  U R                  4-  $ )Nz
%s(%s, %d))rP   r%   rG   r   rD   s    r,   __repr__Enum.__repr__  s&    tDz22DIIt{{KKKr+   c                 4    U R                   U R                  44$ )z}Enable pickling.

Returns:
  A 2-tuple containing the class and __new__ args to be used
  for restoring a pickled instance.

)	__class__r   rD   s    r,   
__reduce__Enum.__reduce__  s     ~~~--r+   c                     [        U[        U 5      5      (       a   [        U R                  UR                  5      $ [        $ zOrder is by number.)r   rP   cmpr   NotImplementedrE   others     r,   __cmp__Enum.__cmp__  s.    eT$Z((t{{ELL11r+   c                 t    [        U[        U 5      5      (       a  U R                  UR                  :  $ [        $ r   r   rP   r   r   r   s     r,   __lt__Enum.__lt__  ,    eT$Z((;;--r+   c                 t    [        U[        U 5      5      (       a  U R                  UR                  :*  $ [        $ r   r   r   s     r,   __le__Enum.__le__  ,    eT$Z((;;%,,..r+   c                 t    [        U[        U 5      5      (       a  U R                  UR                  :H  $ [        $ r   r   r   s     r,   __eq__Enum.__eq__  r   r+   c                 t    [        U[        U 5      5      (       a  U R                  UR                  :g  $ [        $ r   r   r   s     r,   __ne__Enum.__ne__  r   r+   c                 t    [        U[        U 5      5      (       a  U R                  UR                  :  $ [        $ r   r   r   s     r,   __ge__Enum.__ge__  r   r+   c                 t    [        U[        U 5      5      (       a  U R                  UR                  :  $ [        $ r   r   r   s     r,   __gt__Enum.__gt__  r   r+   c                 ,    [        U R                  5      $ )zHash by number.)hashr   rD   s    r,   __hash__Enum.__hash__	  s    DKK  r+   c                 8    [        S [        U 5       5       5      $ )zMake dictionary version of enumerated class.

Dictionary created this way can be used with def_num.

Returns:
  A dict (name) -> number
c              3   P   #    U  H  oR                   UR                  4v   M     g 7fr   r   ).0items     r,   	<genexpr>Enum.to_dict.<locals>.<genexpr>  s     CYY,s   $&)dictr   r]   s    r,   to_dictEnum.to_dict  s     CcCCCr+   c                 &    [        U[        4U 5      $ )zqDefine enum class from dictionary.

Args:
  dct: Dictionary of enumerated values for type.
  name: Name of enum.
)rP   r   )rX   rG   s     r,   def_enumEnum.def_enum  s     D4'3''r+   r#   r   )r%   r&   r'   r(   r)   set	__slots__r   rQ   rc   rC   r   r   r   r   r   r   r   r   r   r   r   classmethodr   staticmethodr   r*   r#   r+   r,   r   r     s    .&'I"/H36L.! D D ( (r+   r   c                   L    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrSrSrg)r   i%  a  Wire format variant.

Used by the 'protobuf' wire format to determine how to transmit
a single piece of data.  May be used by other formats.

See: http://code.google.com/apis/protocolbuffers/docs/encoding.html

Values:
  DOUBLE: 64-bit floating point number.
  FLOAT: 32-bit floating point number.
  INT64: 64-bit signed integer.
  UINT64: 64-bit unsigned integer.
  INT32: 32-bit signed integer.
  BOOL: Boolean value (True or False).
  STRING: String of UTF-8 encoded text.
  MESSAGE: Embedded message as byte string.
  BYTES: String of 8-bit bytes.
  UINT32: 32-bit unsigned integer.
  ENUM: Enum value as integer.
  SINT32: 32-bit signed integer.  Uses "zig-zag" encoding.
  SINT64: 64-bit signed integer.  Uses "zig-zag" encoding.
                  	                     r#   N)r%   r&   r'   r(   r)   DOUBLEFLOATINT64UINT64INT32BOOLSTRINGMESSAGEBYTESUINT32ENUMSINT32SINT64r*   r#   r+   r,   r   r   %  sJ    , FEEFEDFGEFDFFr+   r   c                   $    \ rS rSrSrS rS rSrg)_MessageClassiK  a  Meta-class used for defining the Message base class.

For more details about Message classes, see the Message class docstring.
Information contained there may help understanding this class.

Meta-class enables very specific behavior for any defined Message
class. All attributes defined on an Message sub-class must be
field instances, Enum class definitions or other Message class
definitions. Each field attribute defined on an Message sub-class
is added to the set of field definitions and the attribute is
translated in to a slot. It also ensures that only one level of
Message class hierarchy is possible. In other words it is not
possible to declare sub-classes of sub-classes of Message.

This class also defines some functions in order to restrict the
behavior of the Message class and its sub-classes. It is not
possible to change the behavior of the Message class in later
classes since any new classes may be defined with only field,
Enums and Messages, and no methods.

c                 6   0 n0 n0 nU[         4:w  Gaj  U[        4:w  a  [        S5      e/ n/ nUR                  5        GH  u  pU	[        ;   a  M  [        U
[        5      (       a(  [        U
[        5      (       a  UR                  U	5        MO  [        U
[        5      (       a1  [        U
[        5      (       a  U
[        La  UR                  U	5        M  [        U
5      [        L d  [        U
[        5      (       d  [        SU	< SU
< 35      eU
R                  U;   a  [        SU
R                  U4-  5      eXl        XU	'   XU
R                  '   GM     U(       a  [        U5      US'   U(       a  [        U5      US'   XCS'   XSS'   [        R!                  XX#5      $ )	zCreate new Message class instance.

The __new__ method of the _MessageClass type is overridden so as to
allow the translation of Field instances to slots.
z+Message types may only inherit from Messagez4May only use fields in message definitions.  Found: r~   z2Field with number %d declared more than once in %s	__enums____messages___Message__by_number_Message__by_name)rS   r   r   r   r   r   rP   
issubclassr   appendr	   r   r   rG   sortedrM   r   )rV   rG   rW   rX   	by_numberby_namevariant_mapenumsmessageskeyfields              r,   r   _MessageClass.__new__c  s    	VI
",AC C EH "iik
33eT**z%/F/FLL%ud++"5'22W,OOC( ;%'z%/G/G0 e%& &
 <<9,.Lt,-. . !
  %*/%,,'A *F #)%=K  &,X&6N#%.!"#* ''5>>r+   c                 R   U[         4:w  a  UR                  5        H@  n[        U[        5      (       d  M  U[        Ld  M%  [
        R                  " U 5      Ul        MB     U R                  5        H  n[
        R                  " U 5      Ul        M      [        R                  XX#5        g)z7Initializer required to assign references to new class.N)
rS   r   r   rM   r   weakrefrefrH   
all_fieldsrQ   )rV   rG   rW   rX   vr  s         r,   rQ   _MessageClass.__init__  sx    VIZZ\a!122q7G,3KK,<A) " ),3KK,<) * 	!!#U8r+   r#   N)r%   r&   r'   r(   r)   r   rQ   r*   r#   r+   r,   r
  r
  K  s    .B?H
9r+   r
  c                       \ rS rSrSrS rS rS r\S 5       r	\S 5       r
\S 5       rS	 rS
 rS r  SS jrS rS rS rS rS rSrg)r   i  a  Base class for user defined message objects.

Used to define messages for efficient transmission across network or
process space.  Messages are defined using the field classes (IntegerField,
FloatField, EnumField, etc.).

Messages are more restricted than normal classes in that they may
only contain field attributes and other Message and Enum
definitions. These restrictions are in place because the structure
of the Message class is intentended to itself be transmitted
across network or process space and used directly by clients or
even other servers. As such methods and non-field attributes could
not be transmitted with the structural information causing
discrepancies between different languages and implementations.

Initialization and validation:

  A Message object is considered to be initialized if it has all required
  fields and any nested messages are also initialized.

  Calling 'check_initialized' will raise a ValidationException if it is not
  initialized; 'is_initialized' returns a boolean value indicating if it is
  valid.

  Validation automatically occurs when Message objects are created
  and populated.  Validation that a given value will be compatible with
  a field that it is assigned to can be done through the Field instances
  validate() method.  The validate method used on a message will check that
  all values of a message and its sub-messages are valid.  Assingning an
  invalid value to a field will raise a ValidationException.

Example:

  # Trade type.
  class TradeType(Enum):
    BUY = 1
    SELL = 2
    SHORT = 3
    CALL = 4

  class Lot(Message):
    price = IntegerField(1, required=True)
    quantity = IntegerField(2, required=True)

  class Order(Message):
    symbol = StringField(1, required=True)
    total_quantity = IntegerField(2, required=True)
    trade_type = EnumField(TradeType, 3, required=True)
    lots = MessageField(Lot, 4, repeated=True)
    limit = IntegerField(5)

  order = Order(symbol='GOOG',
                total_quantity=10,
                trade_type=TradeType.BUY)

  lot1 = Lot(price=304,
             quantity=7)

  lot2 = Lot(price = 305,
             quantity=3)

  order.lots = [lot1, lot2]

  # Now object is initialized!
  order.check_initialized()

c                 D   0 U l         0 U l        [        5       nUR                  5        H"  u  p4[	        XU5        UR                  U5        M$     U R                  5        H>  nUR                  (       d  M  UR                  U;  d  M(  [	        XR                  / 5        M@     g)a  Initialize internal messages state.

Args:
  A message can be initialized via the constructor by passing
  in keyword arguments corresponding to fields. For example:

    class Date(Message):
      day = IntegerField(1)
      month = IntegerField(2)
      year = IntegerField(3)

  Invoking:

    date = Date(day=6, month=6, year=1911)

  is the same as doing:

    date = Date()
    date.day = 6
    date.month = 6
    date.year = 1911

N)	_Message__tags_Message__unrecognized_fieldsr   r   r   addr  repeatedrG   )rE   kwargsassignedrG   rd   r  s         r,   rQ   Message.__init__  sw    2 %'"5!<<>KDD&LL *
 __&E~~~%**H"<jj"- 'r+   c                    U R                   R                  5        H  u  p[        X5      nUc9  UR                  (       a&  [	        S[        U 5      R                  < SU< 35      eML   [        U[        5      (       a  [        UR                  [        5      (       a`  UR                  (       a,  U H$  nUR                  U5      nUR                  5         M&     M  UR                  U5      nUR                  5         M  M  M     g! [         a1  n[        US5      (       d  [        U 5      R                  Ul        e SnAff = f)zCheck class for initialization status.

Check that all required fields are initialized

Raises:
  ValidationError: If message is not initialized.
NMessage z is missing required field message_name)r  r   r   requiredr   rP   r%   r   r   r  message_typer   r&  value_to_messagecheck_initializedhasattrr,  )rE   rG   r  rd   r   item_message_valuemessage_valueerrs           r,   r0  Message.check_initialized  s     >>//1KDD'E}>>)d,,d45 5 "
"5,77&u'9'97CC >>(-5:5K5K$(6* 2 2 D D F ).
 -2,B,B5,IM);;= D 8 2& ' "377+/:+>+>(s   (A/D!D
D>,D99D>c                 F     U R                  5         g! [         a     gf = f)zMGet initialization status.

Returns:
  True if message is valid, else False.
TF)r0  r   rD   s    r,   is_initializedMessage.is_initialized?  s,    	""$   		s    
  c                 6    U R                   R                  5       $ )zsGet all field definition objects.

Ordering is arbitrary.

Returns:
  Iterator over all values in arbitrary order.
)r  r   r]   s    r,   r  Message.all_fieldsL  s     }}##%%r+   c                      U R                   U   $ )zvGet field by name.

Returns:
  Field object associated with name.

Raises:
  KeyError if no field found by that name.
)r  ri   s     r,   field_by_nameMessage.field_by_nameW  s     }}T""r+   c                      U R                   U   $ )z|Get field by number.

Returns:
  Field object associated with number.

Raises:
  KeyError if no field found by that number.
)r  r   s     r,   field_by_numberMessage.field_by_numberc  s     v&&r+   c                     [        U 5      n UR                  U5      nU R
                  R                  UR                  5      $ ! [         a    [        SUR                  < SU< 35      ef = f)a   Get the assigned value of an attribute.

Get the underlying value of an attribute. If value has not
been set, will not return the default for the field.

Args:
  name: Name of attribute to get.

Returns:
  Value of attribute, None if it has not been set.

r+   has no field )rP   r<  r   r\   r%   r#  getr   rE   rG   r.  r  s       r,   get_assigned_valueMessage.get_assigned_valueo  si     Dz	. ..t4E {{u||,,  	. %%t"- . .	.s   A (A+c                 l   [        U 5      n UR                  U5      nWR                  (       a$  [        U/ 5      U R                  UR                  '   gU R                  R                  UR                  S5        g! [         a/    XR                  ;  a  [	        SUR
                  < SU< 35      e Nf = f)zReset assigned value for field.

Resetting a field will return it to its default value or None.

Args:
  name: Name of field to reset.
r+  rB  N)rP   r<  r   r  r\   r%   r&  r
   r#  r   poprD  s       r,   resetMessage.reset  s     Dz	2 ..t4E
 >>(1%(<DKK%KKOOELL$/  	2111$ ))4&1 2 2 2	2s   A: :6B32B3c                 H    [        U R                  R                  5       5      $ )z9Get the names of all unrecognized fields in this message.)listr$  r   rD   s    r,   all_unrecognized_fieldsMessage.all_unrecognized_fields  s    D..33566r+   Nc                 F    U R                   R                  XU45      u  pEXE4$ )ar  Get the value and variant of an unknown field in this message.

Args:
  key: The name or number of the field to retrieve.
  value_default: Value to be returned if the key isn't found.
  variant_default: Value to be returned as variant if the key isn't
    found.

Returns:
  (value, variant), where value and variant are whatever was passed
  to set_unrecognized_field.
)r$  rC  )rE   r  value_defaultvariant_defaultrd   variants         r,   get_unrecognized_field_info#Message.get_unrecognized_field_info  s0     3377>M>O P~r+   c                 j    [        U[        5      (       d  [        SU-  5      eX#4U R                  U'   g)a<  Set an unrecognized field, used when decoding a message.

Args:
  key: The name or number used to refer to this unknown value.
  value: The value of the field.
  variant: Type information needed to interpret the value or re-encode
    it.

Raises:
  TypeError: If the variant is not an instance of messages.Variant.
zVariant type %s is not valid.N)r   r   rh   r$  )rE   r  rd   rR  s       r,   set_unrecognized_fieldMessage.set_unrecognized_field  s4     '7++;gEFF*/.""3'r+   c                     XR                   ;   d  UR                  S5      (       a  [        R                  XU5        g[	        SU< S[        U 5      R                  < 35      e)a  Change set behavior for messages.

Messages may only be assigned values that are fields.

Does not try to validate field when set.

Args:
  name: Name of field to assign to.
  value: Value to assign to field.

Raises:
  AttributeError when trying to assign value that is not a field.

_Message__zMay not assign arbitrary value z to message N)r  
startswithrS   rc   r\   rP   r%   r   s      r,   rc   Message.__setattr__  sP     >>!T__\%B%Bt51 48$t*:M:M"O P Pr+   c           	      P   S[        U 5      R                  /n[        U R                  5       S S9 HQ  nUR                  nU R                  UR                  5      nUc  M/  UR                  SU< S[        U5      < 35        MS     UR                  S5        SR                  U5      $ )a  Make string representation of message.

Example:

  class MyMessage(messages.Message):
    integer_value = messages.IntegerField(1)
    string_value = messages.StringField(2)

  my_message = MyMessage()
  my_message.integer_value = 42
  my_message.string_value = u'A string'

  print my_message
  >>> <MyMessage
  ...  integer_value: 42
  ...  string_value: u'A string'>

Returns:
  String representation of message, including the values
  of all fields and repr of all sub-messages.
<c                     U R                   $ r   r   )fs    r,   <lambda>"Message.__repr__.<locals>.<lambda>  s    !((r+   )r  z
 : > )	rP   r%   r  r  rG   rE  r  reprjoin)rE   bodyr  r   rd   s        r,   r   Message.__repr__  s    , T$Z(()DOO- 24E

I++EJJ7E 9d5kBC4 	Cwwt}r+   c                 n    XL a  g[        U 5      [        U5      La  gU R                  UR                  :H  $ )aL  Equality operator.

Does field by field comparison with other message.  For
equality, must be same type and values of all fields must be
equal.

Messages not required to be initialized for comparison.

Does not attempt to determine equality for values that have
default values that are not set.  In other words:

  class HasDefault(Message):

    attr1 = StringField(1, default='default value')

  message1 = HasDefault()
  message2 = HasDefault()
  message2.attr1 = 'default value'

  message1 != message2

Does not compare unknown values.

Args:
  other: Other message to compare with.
TF)rP   r#  r   s     r,   r   Message.__eq__  s2    : =:T%[({{ell**r+   c                 .    U R                  U5      (       + $ )a.  Not equals operator.

Does field by field comparison with other message.  For
non-equality, must be different type or any value of a field must be
non-equal to the same field in the other instance.

Messages not required to be initialized for comparison.

Args:
  other: Other message to compare with.
)r   r   s     r,   r   Message.__ne__  s     ;;u%%%r+   )__tags__unrecognized_fields)NN)r%   r&   r'   r(   r)   rQ   r0  r7  r   r  r<  r?  rE  rI  rM  rS  rV  rc   r   r   r   r*   r#   r+   r,   r   r     s    BH$.L@ & & 	# 	# 	' 	'-*0(7 >B48$9 P(@#+J&r+   r   c                   X    \ rS rSrSrS rS rS r\S 5       r	S r
S rS	 rS
 rS rSrg)r
   i&  a
  List implementation that validates field values.

This list implementation overrides all methods that add values in
to a list in order to validate those new elements. Attempting to
add or set list values that are not of the correct type will raise
ValidationError.

c                     UR                   (       d  [        S5      eXl        U R                  R                  U5        [        R                  X5        g)zConstructor.

Args:
  field_instance: Instance of field that validates the list.
  sequence: List or tuple to construct list from.
z)FieldList may only accept repeated fieldsN)r&  r   _FieldList__fieldvalidaterL  rQ   )rE   field_instancesequences      r,   rQ   FieldList.__init__0  s@     &&&;= =%h'd%r+   c                     U R                   R                  5       nUc  U R                   SS4$ SXR                   R                  4$ )a  Enable pickling.

The assigned field instance can't be pickled if it belongs to
a Message definition (message_definition uses a weakref), so
the Message class and field number are returned in that case.

Returns:
  A 3-tuple containing:
    - The field instance, or None if it belongs to a Message class.
    - The Message class that the field instance belongs to, or None.
    - The field instance number of the Message class it belongs to, or
        None.

N)rq  r^   r   )rE   message_classs     r,   __getstate__FieldList.__getstate__>  sB     779 <<t++]LL$7$777r+   c                 N    Uu  p#nUc  UR                  U5      U l        gX l        g)a  Enable unpickling.

Args:
  state: A 3-tuple containing:
    - The field instance, or None if it belongs to a Message class.
    - The Message class that the field instance belongs to, or None.
    - The field instance number of the Message class it belongs to, or
        None.
N)r?  rq  )rE   staters  rw  r   s        r,   __setstate__FieldList.__setstate__R  s+     16-v!(88@DL)Lr+   c                     U R                   $ )zField that validates list.)rq  rD   s    r,   r  FieldList.fieldb  s     ||r+   c                 f    U R                   R                  U5        [        R                  XX#5        g)z"Validate slice assignment to list.N)rq  rr  rL  __setslice__)rE   ijrt  s       r,   r  FieldList.__setslice__g  s$    h'$1/r+   c                     [        U[        5      (       a  U R                  R                  U5        OU R                  R	                  U5        [
        R                  XU5        g)z!Validate item assignment to list.N)r   slicerq  rr  validate_elementrL  __setitem__rE   r   rd   s      r,   r  FieldList.__setitem__l  sC    eU##LL!!%(LL))%0e,r+   c                     [        U SS5      (       a  U R                  R                  U5        [        R	                  X5      $ )z Validate item appending to list.rq  N)r   rq  r  rL  r  rE   rd   s     r,   r  FieldList.appendt  s3    4,d33LL))%0{{4''r+   c                     [        U SS5      (       a  U R                  R                  U5        [        R	                  X5      $ )zValidate extension of list.rq  N)r   rq  rr  rL  extend)rE   rt  s     r,   r  FieldList.extendz  s3    4,d33LL!!(+{{4**r+   c                 d    U R                   R                  U5        [        R                  XU5      $ )z Validate item insertion to list.)rq  r  rL  insertr  s      r,   r  FieldList.insert  s%    %%e,{{4..r+   )__fieldN)r%   r&   r'   r(   r)   rQ   rx  r|  propertyr  r  r  r  r  r  r*   r#   r+   r,   r
   r
   &  sC    &8(*   0
-(+/r+   r
   c                       \ rS rSrS rSrg)
_FieldMetai  c                    ^  [        T S5      R                  U 4S jUR                  S/ 5       5       5        [        R	                  T XU5        g )N_Field__variant_to_typec              3   *   >#    U  H  oT4v   M
     g 7fr   r#   )r   rR  rV   s     r,   r   &_FieldMeta.__init__.<locals>.<genexpr>  s      7C*AwcN*As   VARIANTS)r   updaterC  rP   rQ   rU   s   `   r,   rQ   _FieldMeta.__init__  sD    ./66 7C*-''*b*A7C 	Cc4,r+   r#   N)r%   r&   r'   r(   rQ   r*   r#   r+   r,   r  r    s    -r+   r  c                       \ rS rSrSrSr0 r\R                  " S5          SS j5       r	S r
S rS	 rS
 rS rS rS rS rS r\S 5       r\S 5       rSrg)r	   i  zDefinition for message field.Fr   Nc           
      B   [        U[        5      (       a  SUs=::  a
  [        ::  d  O  [        SU[        4-  5      e[        Us=::  a
  [
        ::  a  O  O[        SU[        [
        4-  5      eU(       a  U(       a  [        S5      eUc  U R                  nU(       a  Ub  [        S5      eX@R                  ;  a=  [        SU< S[        U 5      R                  < S	[        U R                  5      < 35      eXl        X l        X0l        X@l        Ub   U R#                  U5        XPl        SU l        g! [$         ab  n U R&                  n[)        S
U< SU< SU< 35      e! [*         a,    [)        SU R,                  R                  < SU< SU< 35      ef = fSnAff = f)a  Constructor.

The required and repeated parameters are mutually exclusive.
Setting both to True will raise a FieldDefinitionError.

Sub-class Attributes:
  Each sub-class of Field must define the following:
    VARIANTS: Set of variant types accepted by that field.
    DEFAULT_VARIANT: Default variant type if not specified in
      constructor.

Args:
  number: Number of field.  Must be unique per message class.
  required: Whether or not field is required.  Mutually exclusive with
    'repeated'.
  repeated: Whether or not field is repeated.  Mutually exclusive with
    'required'.
  variant: Wire-format variant hint.
  default: Default value for field if not found in stream.

Raises:
  InvalidVariantError when invalid variant for field is provided.
  InvalidDefaultError when invalid default for field is provided.
  FieldDefinitionError when invalid number provided or mutually
    exclusive fields are used.
  InvalidNumberError when the field number is out of range or reserved.

r   zGInvalid number for field: %s
Number must be 1 or greater and %d or lesszATag number %d is a reserved number.
Numbers %d to %d are reservedz%Cannot set both repeated and requiredNz%Repeated fields may not have defaultszInvalid variant: z
Valid variants for z are z Invalid default value for field rb  zInvalid default value for T)r   intr   r   r   r   r   DEFAULT_VARIANTr  r   rP   r%   r  r   r-  r&  rR  validate_defaultr   rG   r   r\   r   _Field__default_Field__initialized)rE   r   r-  r&  rR  defaultr4  rG   s           r,   rQ   Field.__init__  s   F &#&&a6.M=M.M$=)*+, ,
 '&N4NN$ &E&,.I&@&B&B C C
 &'NOO?**G+&'NOO--'%$t*--vdmm/DFG G   9%%g. !! # 9
999D .$('389 9 & A-00'3@A AA9s*   D2 2
F=E 	F 6FFFc                     U[         ;   a  [        R                  XU5        gU R                  (       d  [        R                  XU5        g[	        S5      e)zSetter overidden to prevent assignment to fields after creation.

Args:
  name: Name of attribute to set.
  value: Value to assign.
NzField objects are read-only) _POST_INIT_FIELD_ATTRIBUTE_NAMESrS   rc   r  r\   r   s      r,   rc   Field.__setattr__  sG     33t51 !!t51 !>??r+   c                 6   UcP  U R                   (       a  [        SU R                  -  5      eUR                  R	                  U R
                  S5        gU R                   (       a  [        X5      nOU R                  U5      nX!R                  U R
                  '   g)uSet value on message.

Args:
  message_instance: Message instance to set value on.
  value: Value to set on message.
Nz(May not assign None to repeated field %s)r&  r   rG   r#  rH  r   r
   rr  )rE   message_instancerd   s      r,   __set__Field.__set__  sx     =}}%>JL L !//33DKKF}}!$.e,;@++DKK8r+   c                 x    Uc  U $ UR                   R                  U R                  5      nUc  U R                  $ U$ r   )r#  rC  r   r  )rE   r  rw  results       r,   __get__Field.__get__  s;    #K!0044T[[A><<r+   c                    [        XR                  5      (       d  [        U[        R                  5      (       a  U R                  [        :X  a  [	        U5      $ Uc  U R
                  (       a  [        S5      e U$  U R                  n[        SU R                  < SU< SU< S[        U5      < S3	5      eU$ ! [         aD    [        SU R                  < SU R                  R                  < SU< S[        U5      < S3	5      ef = f)a  Validate single element of field.

This is different from validate in that it is used on individual
values of repeated fields.

Args:
  value: Value to validate.

Returns:
  The value casted in the expected type.

Raises:
  ValidationError if value is not expected type.
zRequired field is missingExpected type z for field z, found z (type )z for )r   rP   ro   r   floatr-  r   rG   r\   r   r%   )rE   rd   rG   s      r,   r  Field.validate_element  s     %++ %!2!233		U8JU|#}==)*EFF ! 
?99D *D%e>? ?  & @)+/99dnn6M6M+0$u++? @ @@s   <B9 9ADc                     U R                   (       d  U" U5      $ [        U[        [        45      (       aB  / nU H8  nUc   U R                  n[        SU-  5      eUR                  U" U5      5        M:     U$ Ub    U R                  n[        SU< SU< 35      eU$ ! [         a#    [        SU R                  R                  -  5      ef = f! [         a'    [        U R                  R                  < SU< 35      ef = f)a  Internal validation function.

Validate an internal value using a function to validate
individual elements.

Args:
  value: Value to validate.
  validate_element: Function to use to validate individual elements.

Raises:
  ValidationError if value is not expected type.

z,Repeated values for field %s may not be Nonez&Repeated values for %s may not be NoneField z is repeated. Found: )
r&  r   rL  tuplerG   r   r\   r   r%   r  )rE   rd   r  r  elementrG   s         r,   
__validateField.__validateA  s     }}#E** %$//$G	:#'99D #2!248!9#: : MM"27";<  % "K99D
 *=A5IK K'  . M"1!248NN4K4K!L#M MM & 9)//+8 9 99s    B;C -C	1C=c                 8    U R                  XR                  5      $ )zValidate value assigned to field.

Args:
  value: Value to validate.

Returns:
  the value in casted in the correct type.

Raises:
  ValidationError if value is not expected type.
)_Field__validater  r  s     r,   rr  Field.validaten  s     u&;&;<<r+   c                 $    U R                  U5      $ )a  Validate value as assigned to field default field.

Some fields may allow for delayed resolution of default types
necessary in the case of circular definition references. In
this case, the default value might be a place holder that is
resolved when needed after all the message classes are
defined.

Args:
  value: Default value to validate.

Returns:
  the value in casted in the correct type.

Raises:
  ValidationError if value is not expected type.

)r  r  s     r,   validate_default_elementField.validate_default_element|  s    & $$U++r+   c                 8    U R                  XR                  5      $ )zValidate default value assigned to field.

Args:
  value: Value to validate.

Returns:
  the value in casted in the correct type.

Raises:
  ValidationError if value is not expected type.
)r  r  r  s     r,   r  Field.validate_default  s     u&C&CDDr+   c                 D     U R                  5       $ ! [         a     gf = f)zGet Message definition that contains this Field definition.

Returns:
  Containing Message definition for Field. Will return None if
  for some reason Field is defined outside of a Message class.

Nr[   rD   s    r,   r^   Field.message_definition  s(    	++-- 		r`   c                     U R                   $ )zGet default value for field.)r  rD   s    r,   r  Field.default  s     ~~r+   c                      U R                   U   $ r   )r  )rV   rR  s     r,   lookup_field_type_by_variant"Field.lookup_field_type_by_variant  s    $$W--r+   )	__default__initializedr   r&  r-  rR  )FFNN)r%   r&   r'   r(   r)   r  r  r   
positionalrQ   rc   r  r  r  r  rr  r  r  r^   r  r  r   r  r*   r#   r+   r,   r	   r	     s    'M	__Q  R" R"h@&A*$L+Z=,*E   . .r+   r	   c                       \ rS rSrSr\" \R                  \R                  \R                  \R                  \R                  \R                  /5      r\R                  r\R                   rSrg)r   i  z$Field definition for integer values.r#   N)r%   r&   r'   r(   r)   	frozensetr   r   r   r  r   r  r  r  r  ro   r   rP   r*   r#   r+   r,   r   r     sT    . H mmODr+   r   c                   p    \ rS rSrSr\" \R                  \R                  /5      r	\R                  r
\rSrg)r   i  z"Field definition for float values.r#   N)r%   r&   r'   r(   r)   r  r   r   r   r  r  r  rP   r*   r#   r+   r,   r   r     s2    , H
 nnODr+   r   c                   Z    \ rS rSrSr\" \R                  /5      r\R                  r	\
rSrg)r   i  z$Field definition for boolean values.r#   N)r%   r&   r'   r(   r)   r  r   r  r  r  boolrP   r*   r#   r+   r,   r   r     s#    .',,(HllODr+   r   c                   Z    \ rS rSrSr\" \R                  /5      r\R                  r	\
rSrg)r   i  z(Field definition for byte string values.r#   N)r%   r&   r'   r(   r)   r  r   r  r  r  bytesrP   r*   r#   r+   r,   r   r     s#    2'--)HmmODr+   r   c                      ^  \ rS rSrSr\" \R                  /5      r\R                  r	\
R                  rU 4S jrSrU =r$ )r   i  z+Field definition for unicode string values.c           	      v  > [        U[        5      (       a   [        R                  " US5        U$ [        [        U ]/  U5      $ ! [         aj  n U R
                  n[        SU R
                  < SU< SU< 35      nU R
                  Ul        Ue! [         a    [        SU< SU< 35      n Uef = fSnAff = f)zkValidate StringField allowing for str and unicode.

Raises:
  ValidationError if a str value is not UTF-8.
zUTF-8r  z encountered non-UTF-8 string rb  z#Field encountered non-UTF-8 string N)r   r  ro   rp   UnicodeDecodeErrorrG   r   
field_namer\   superr   r  )rE   rd   r4  _validation_errorr   s        r,   r  StringField.validate_element  s     eU##'eW-   d<UCC & '
<		A (7 IIuc3(4$ 37))$/&& & M'6GLGJL(M$ '&M's5   A 
B8B4B3B0,B3/B00B33B8r#   )r%   r&   r'   r(   r)   r  r   r  r  r  ro   rp   rP   r  r*   __classcell__r   s   @r,   r   r     s3    5'..)*HnnO==D r+   r   c                      ^  \ rS rSrSr\" \R                  /5      r\R                  r	\
R                  " S5         SU 4S jj5       rU 4S jr\S 5       r\S 5       rS rS	 rS
rU =r$ )r   i  a  Field definition for sub-message values.

Message fields contain instance of other messages.  Instances stored
on messages stored on message fields  are considered to be owned by
the containing message instance and should not be shared between
owning instances.

Message fields must be defined to reference a single type of message.
Normally message field are defined by passing the referenced message
class in to the constructor.

It is possible to define a message field for a type that does not
yet exist by passing the name of the message in to the constructor
instead of a message class. Resolution of the actual type of the
message is deferred until it is needed, for example, during
message verification. Names provided to the constructor must refer
to a class within the same python module as the class that is
using it. Names refer to messages relative to the containing
messages scope. For example, the two fields of OuterMessage refer
to the same message type:

  class Outer(Message):

    inner_relative = MessageField('Inner', 1)
    inner_absolute = MessageField('Outer.Inner', 2)

    class Inner(Message):
      ...

When resolving an actual type, MessageField will traverse the
entire scope of nested messages to match a message name. This
makes it easy for siblings to reference siblings:

  class Outer(Message):

    class Inner(Message):

      sibling = MessageField('Sibling', 1)

    class Sibling(Message):
      ...

r   c                 l  > [        U[        R                  5      =(       d6    U[        L=(       a'    [        U[        5      =(       a    [        U[        5      nU(       d  [        SU-  5      e[        U[        R                  5      (       a  Xl        SU l        OXl        [        [        U ]/  UUUUS9  g)a  Constructor.

Args:
  message_type: Message type for field.  Must be subclass of Message.
  number: Number of field.  Must be unique per message class.
  required: Whether or not field is required.  Mutually exclusive to
    'repeated'.
  repeated: Whether or not field is repeated.  Mutually exclusive to
    'required'.
  variant: Wire-format variant hint.

Raises:
  FieldDefinitionError when invalid message_type is provided.
Invalid message class: %sN)r-  r&  rR  )r   ro   r   r   rP   r  r   _MessageField__type_namerI   r  r   rQ   )rE   r.  r   r-  r&  rR  
valid_typer   s          r,   rQ   MessageField.__init__>  s    * !s/?/?@ :#72 9!,59!,8 	
 &+l:< < lC$4$455+DK&KlD*64<4<3: 	+ 	<r+   c                   > U R                   n[        U[         5      (       a  [        U[        5      (       a  U R                  (       aR  U(       aJ  [        U[
        [        45      (       a/  U Vs/ s H"  n[        U[        5      (       a  U" S0 UD6OUPM$     nnO[        U[        5      (       a  U" S0 UD6n[        [        U ]+  X5        gs  snf )r  Nr#   )rP   r   r  r   r&  rL  r  r   r  r   r  )rE   r  rd   tr  r   s        r,   r  MessageField.__set__g  s     IIa:a#9#9}}Ze}==&+-&+ )31d(;(;af!fB&+  -E4((
E
lD)*:B	-s   /)Cc                 
   U R                   ck  [        U R                  U R                  5       5      nU[        La*  [        U[        5      (       a  [        U[        5      (       d  [        SU-  5      eXl         U R                   $ )zMessage type used for field.r  )	rI   r   r  r^   r   r   rP   r  r   )rE   r.  s     r,   rP   MessageField.typex  st     ;;*  $"9"9";=L /|T22|W55*/,>@ @&K{{r+   c                     U R                   $ )zUnderlying message type used for serialization.

Will always be a sub-class of Message.  This is different from type
which represents the python value that message_type is mapped to for
use by the user.
)rP   rD   s    r,   r.  MessageField.message_type  s     yyr+   c                     [        XR                  5      (       d>  [        SU R                  R                  < S[	        U5      R                  < SU< 35      eU$ )zConvert a message to a value instance.

Used by deserializers to convert from underlying messages to
value of expected user type.

Args:
  message: A message instance of type self.message_type.

Returns:
  Value of self.message_type.
r  , got rb  )r   r.  r   r%   rP   )rE   messages     r,   value_from_messageMessageField.value_from_message  sM     '#4#455#0099#G}55&( ) ) r+   c                     [        XR                  5      (       d>  [        SU R                  R                  < S[        U5      R                  < SU< 35      eU$ )zConvert a value instance to a message.

Used by serializers to convert Python user types to underlying
messages for transmission.

Args:
  value: A value of type self.type.

Returns:
  An instance of type self.message_type.
r  r  rb  )r   rP   r   r%   r  s     r,   r/  MessageField.value_to_message  sI     %++#yy11#E{33$& ' ' r+   )__type__type_name)FFN)r%   r&   r'   r(   r)   r  r   r  r  r  r   r  rQ   r  r  rP   r.  r  r/  r*   r  r  s   @r,   r   r     s    *X '//*+HooO	__Q  &< &<PC"    & r+   r   c                      ^  \ rS rSrSr\" \R                  /5      r\R                  r	U 4S jr
U 4S jr\S 5       r\U 4S j5       rSrU =r$ )r   i  a  Field definition 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:

  class Message1(Message):

    class Color(Enum):

      RED = 1
      GREEN = 2
      BLUE = 3

    # This field default value  will be validated when default is accessed.
    animal = EnumField('Message2.Animal', 1, default='HORSE')

  class Message2(Message):

    class Animal(Enum):

      DOG = 1
      CAT = 2
      HORSE = 3

    # This fields default value will be validated right away since Color
    # is already fully resolved.
    color = EnumField(Message1.Color, 1, default='RED')
c                 n  > [        U[        R                  5      =(       d6    U[        L=(       a'    [        U[        5      =(       a    [        U[        5      nU(       d  [        SU-  5      e[        U[        R                  5      (       a  Xl        SU l        OXl        [        [        U ].  " U40 UD6  g)a  Constructor.

Args:
  enum_type: Enum type for field.  Must be subclass of Enum.
  number: Number of field.  Must be unique per message class.
  required: Whether or not field is required.  Mutually exclusive to
    'repeated'.
  repeated: Whether or not field is repeated.  Mutually exclusive to
    'required'.
  variant: Wire-format variant hint.
  default: Default value for field if not found in stream.

Raises:
  FieldDefinitionError when invalid enum_type is provided.
Invalid enum type: %sN)r   ro   r   r   rP   r  r   _EnumField__type_namerJ   r  r   rQ   )rE   	enum_typer   r'  r  r   s        r,   rQ   EnumField.__init__  s      !C,<,<= 4 , 3!)T23!)T2 	
 &'>'JKKi!1!122(DK#Ki'9&9r+   c                    > [        U[        R                  [        R                  45      (       a$  U R                  (       a  U R	                  U5        U$ [
        [        U ]  U5      $ )a  Validate default element of 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.

Args:
  value: Value to validate.

Raises:
  ValidationError if value is not expected message type.

)r   ro   r   r   rJ   r  r   r  )rE   rd   r   s     r,   r  "EnumField.validate_default_element  sO      ec..0A0ABCC {{E"LY>uEEr+   c                 
   U R                   ck  [        U R                  U R                  5       5      nU[        La*  [        U[        5      (       a  [        U[        5      (       d  [        SU-  5      eXl         U R                   $ )zEnum type used for field.r  )	rJ   r   r  r^   r   r   rP   r  r   )rE   
found_types     r,   rP   EnumField.type  st     ;;(  $"9"9";=Jd*z400z400*+j8: : %K{{r+   c                    >  U R                   $ ! [         ac    [        [        U ]  n[        U[        R                  [        R                  45      (       a  U R                  U5      nXl         U R                   s $ f = f)zZDefault for enum field.

Will cause resolution of Enum type and unresolved default value.
)
rK   r\   r  r   r  r   ro   r   r   rP   )rE   resolved_defaultr   s     r,   r  EnumField.default$  s}    		+*** 	+$Y=*S-=-=-0->->-@ A A $(99-=#> &6#***	+s    A*A<;A<)__resolved_defaultr  r  )r%   r&   r'   r(   r)   r  r   r  r  r  rQ   r  r  rP   r  r*   r  r  s   @r,   r   r     sX    @ ',,(HllO:@F2   + +r+   r   r   c                 `  ^^^ TbW  [        T[        R                  5      (       d8  [        T[        5      (       a  [	        T[
        5      (       d  [        ST-  5      eU R                  S5      mTS   (       d  SmTSS mUUU4S jn U" 5       n[        U[        5      (       a  [	        U[        [
        45      (       a  U$ Tc  [        SU -  5      e[        T[        R                  5      (       aG  TR                  R                  S5      SS nU(       d  SmOT" SR                  U5      S	S	US   /5      mOt[        T[        5      (       a_  [	        T[
        5      (       aJ  TR                  5       nUc5  TR                  R                  S5      S   nT" TR                  S	S	U/5      mOUmGM'  )
a  Find definition by name in module-space.

The find algorthm will look for definitions by name relative to a
message definition or by fully qualfied name. If no definition is
found relative to the relative_to parameter it will do the same
search against the container of relative_to. If relative_to is a
nested Message, it will search its message_definition(). If that
message has no message_definition() it will search its module. If
relative_to is a module, it will attempt to look for the
containing module and search relative to it. If the module is a
top-level module, it will look for the a message using a fully
qualified name. If no message is found then, the search fails and
DefinitionNotFoundError is raised.

For example, when looking for any definition 'foo.bar.ADefinition'
relative to an actual message definition abc.xyz.SomeMessage:

  find_definition('foo.bar.ADefinition', SomeMessage)

It is like looking for the following fully qualified names:

  abc.xyz.SomeMessage. foo.bar.ADefinition
  abc.xyz. foo.bar.ADefinition
  abc. foo.bar.ADefinition
  foo.bar.ADefinition

When resolving the name relative to Message definitions and modules, the
algorithm searches any Messages or sub-modules found in its path.
Non-Message values are not searched.

A name that begins with '.' is considered to be a fully qualified
name. The name is always searched for from the topmost package.
For example, assume two message types:

  abc.xyz.SomeMessage
  xyz.SomeMessage

Searching for '.xyz.SomeMessage' relative to 'abc' will resolve to
'xyz.SomeMessage' and not 'abc.xyz.SomeMessage'.  For this kind of name,
the relative_to parameter is effectively ignored and always set to None.

For more information about package name resolution, please see:

  http://code.google.com/apis/protocolbuffers/docs/proto.html#packages

Args:
  name: Name of definition to find.  May be fully qualified or relative
    name.
  relative_to: Search for definition relative to message definition or
    module. None will cause a fully qualified name search.
  importer: Import function to use for resolving modules.

Returns:
  Enum or Message class definition associated with name.

Raises:
  DefinitionNotFoundError if no definition is found in any search path.

NzBrelative_to must be None, Message definition or module.  Found: %srm   r   r   c            	        > Tn T H  n[        XS5      nUb  Un OhU b  [        U [        R                  5      (       aD  U c  UnOU R                  < SU< 3n UR                  S5      S   nT" USS[        U5      /5      n O  g[        U [        R                  5      (       a  M  [        U [        5      (       a  [        U [        [        45      (       a  M    g   U $ ! [         a       gf = f)a  Performs a single iteration searching the path from relative_to.

This is the function that searches up the path from a relative object.

  fully.qualified.object . relative.or.nested.Definition
                           ---------------------------->
                                              ^
                                              |
                        this part of search --+

Returns:
  Message or Enum at the end of name_path, else None.
Nrm   rd  )r   r   types
ModuleTyper%   splitstrImportErrorrP   r  r   r   )	next_partnoder   module_namefromitemimporter	name_pathrelative_tos        r,   search_path$find_definition.<locals>.search_path  s      	D	6I$%	 %"9e.>.>?? (&*1:1C1CT&J$#.#4#4S#9"#=$,["b.1(m_%>	
  i)9)9::"9d33"9wo>>7 :  ' $#$s   )C
C*)C*z Could not find definition for %sr	  rd  )r   r
  r  rP   r  r   rh   r  r   r    r%   rf  r^   r&   )	rG   r  r  r  foundmodule_pathparentlast_module_namer  s	    ``     @r,   r   r   6  s   | {E$4$455{D)){G,,'() 	) 

3I Q<abM	,\ eT""z%$'I'IL "-6=? ? k5+;+;<<"-"6"6"<"<S"A#2"FK&&* '/HH[12rKO;L'N d33 g66(;;=F~+6+A+A+G+G,!!#,%(&.'22B=M<N'P '-I r+   )2r)   r
  r  ro   apitools.base.protorpcliter   __all__r   r   r   r   r   r   r   r   r    r   r   r   r  r   r  rb   r   r   r   r   rP   rM   r|   with_metaclassrS   r   r   r
  r   rL  r
   r  r	   r   r   r   r   r   r   r   r  
__import__r   r#   r+   r,   <module>r      s/  (2   
 + P 	

(% ("5 "-. --. -,- ,$U $.5 ./e /:% :-% -#e # &Y[  $-%$&   ' 
  !  $ " i5t i5Xv"! v"rN(3j&1 N(f#d #Lf9$ f9Ro&c  7 o&d]/ ]/@- -d.Cz62 d.N	5 "
 
5  "% "Jg5 gT|+ |+~ &*Z ^- ^-r+   