
Q,Qc           @   s  d  Z  d Z y d d l m Z Wn! e k
 rC d d l m Z n Xd d l Z d d l Z d d l Z d d l m	 Z	 d d l m
 Z
 d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d d l m Z e j Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d    Z* d!   Z+ d"   Z, d#   Z- d$   Z. d%   Z/ d&   Z0 d'   Z1 d(   Z2 d)   Z3 d*   Z4 d+   Z5 d,   Z6 d-   Z7 d.   Z8 d/   Z9 d0   Z: d1   Z; d2   Z< d3   Z= d4   Z> d5   Z? d6 e@ f d7     YZA d8 e@ f d9     YZB d S(:   s  Contains a metaclass and helper functions used to create
protocol message classes from Descriptor objects at runtime.

Recall that a metaclass is the "type" of a class.
(A class is to a metaclass what an instance is to a class.)

In this case, we use the GeneratedProtocolMessageType metaclass
to inject all the useful functionality into the classes
output by the protocol compiler at compile-time.

The upshot of all this is that the real implementation
details for ALL pure-Python protocol buffers are *here in
this file*.
s#   robinson@google.com (Will Robinson)i(   t   StringION(   t
   containers(   t   decoder(   t   encoder(   t   enum_type_wrapper(   t   message_listener(   t   type_checkers(   t   wire_format(   t
   descriptor(   t   message(   t   text_formatc         C   s   t  | |  t | |  |  S(   N(   t&   _AddClassAttributesForNestedExtensionst	   _AddSlots(   t   basesR   t
   dictionary(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt
   NewMessageL   s    c            s   i    _  i    _ i    _ |  j rR |  j   j rR t j   j    j  t j <n  x |  j	 D] } t
   |  q\ Wt |     t |     t |     t |     t    t |     t    t j     f d    d  S(   Nc            s     d |  j    f S(   N(    (   t   __getstate__(   t   obj(   t   cls(    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   <lambda>f   s    (   t   _decoders_by_tagt   _extensions_by_namet   _extensions_by_numbert   has_optionst
   GetOptionst   message_set_wire_formatR   t   MessageSetItemDecodert   MESSAGE_SET_ITEM_TAGt   fieldst   _AttachFieldHelperst   _AddEnumValuest   _AddInitMethodt   _AddPropertiesForFieldst   _AddPropertiesForExtensionst   _AddStaticMethodst   _AddMessageMethodst   _AddPrivateHelperMethodst   copy_regt   pickle(   R   R   t   field(    (   R   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   InitMessageR   s     				

c         C   s   |  S(   s  Returns the name of the public property attribute which
  clients can use to get and (in some cases) set the value
  of a protocol message field.

  Args:
    proto_field_name: The protocol message field name, exactly
      as it appears (or would appear) in a .proto file.
  (    (   t   proto_field_name(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _PropertyNameq   s    c         C   s   t  | t  s" t d |   n  | j sA t d | j   n  | j s` t d | j   n  | j |  j k	 r t d | j | j j |  j j f   n  d S(   s0   Verify that the given extension handle is valid.s3   HasExtension() expects an extension handle, got: %ss   "%s" is not an extension.s"   "%s" is missing a containing_type.sK   Extension "%s" extends message type "%s", but this message is of type "%s".N(   t
   isinstancet   _FieldDescriptort   KeyErrort   is_extensiont	   full_namet   containing_typet
   DESCRIPTOR(   R	   t   extension_handle(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _VerifyExtensionHandle   s    			c         C   s&   d d d d d d d d g | d	 <d
 S(   s  Adds a __slots__ entry to dictionary, containing the names of all valid
  attributes for this message type.

  Args:
    message_descriptor: A Descriptor instance describing this message type.
    dictionary: Class dictionary to which we'll add a '__slots__' entry.
  t   _cached_byte_sizet   _cached_byte_size_dirtyt   _fieldst   _unknown_fieldst   _is_present_in_parentt	   _listenert   _listener_for_childrent   __weakref__t	   __slots__N(    (   t   message_descriptorR   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR      s    c         C   s[   |  j  oZ |  j j oZ |  j j   j oZ |  j t j k oZ |  j |  j	 k oZ |  j
 t j k S(   N(   R.   R0   R   R   R   t   typeR,   t   TYPE_MESSAGEt   message_typet   extension_scopet   labelt   LABEL_OPTIONAL(   R'   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _IsMessageSetExtension   s    	c            s   j  t j k   j o'  j   j } t   r] t j  j	  } t j
  j	  } n> t j  j  j	  |  } t j  j  j	  |  } |  _ |  _ t    _     f d   } | t j  j t   rt j  j  r| t j t  n  d  S(   Nc            sH   t  j  j |   } t j  j  j  |   j    j | <d  S(   N(   R   t   TagBytest   numberR   t   TYPE_TO_DECODERR>   t   _default_constructorR   (   t   wiretypet	   is_packedt	   tag_bytes(   R   t   field_descriptort   is_repeated(    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt
   AddDecoder   s    (   RB   R,   t   LABEL_REPEATEDR   R   t   packedRD   R   t   MessageSetItemEncoderRF   t   MessageSetItemSizerR   t   TYPE_TO_ENCODERR>   t   TYPE_TO_SIZERt   _encodert   _sizert    _DefaultValueConstructorForFieldRH   t   FIELD_TYPE_TO_WIRE_TYPEt   FalseR   t   IsTypePackablet   WIRETYPE_LENGTH_DELIMITEDt   True(   R   RL   RJ   t   field_encodert   sizerRN   (    (   R   RL   RM   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR      s&    			c         C   sF   |  j  } x6 | j   D]( \ } } | | k s4 t  | | | <q Wd  S(   N(   t   extensions_by_namet	   iteritemst   AssertionError(   R   R   t   extension_dictt   extension_namet   extension_field(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR      s    	c         C   s^   xW |  j  D]L } t | | j t j |   x' | j D] } t | | j | j  q6 Wq
 Wd S(   s  Sets class-level attributes for all enum fields defined in this message.

  Also exporting a class-level object that can name enum values.

  Args:
    descriptor: Descriptor object for this message type.
    cls: Class we're constructing for this message type.
  N(   t
   enum_typest   setattrt   nameR   t   EnumTypeWrappert   valuesRF   (   R   R   t	   enum_typet
   enum_value(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR      s    	c            s     j  t j k r   j r@   j g  k r@ t d   j   n    j t j k rn   j    f d   } | St	 j
   j   j    f d   } | Sn    j t j k r   j   f d   } | S  f d   } | S(   s  Returns a function which returns a default value for a field.

  Args:
    field: FieldDescriptor object for this field.

  The returned function has one argument:
    message: Message instance containing this field, or a weakref proxy
      of same.

  That function in turn returns a default value for this field.  The default
    value may refer back to |message| via a weak reference.
  s/   Repeated field default value not empty list: %sc            s   t  j |  j   j  S(   N(   R   t   RepeatedCompositeFieldContainerR:   R@   (   R	   (   R'   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   MakeRepeatedMessageDefault  s    c            s   t  j |  j    S(   N(   R   t   RepeatedScalarFieldContainerR:   (   R	   (   t   type_checker(    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   MakeRepeatedScalarDefault  s    c            s      j    } | j |  j  | S(   N(   t   _concrete_classt   _SetListenerR:   (   R	   t   result(   R@   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   MakeSubMessageDefault  s    c            s     j  S(   N(   t   default_value(   R	   (   R'   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   MakeScalarDefault"  s    (   RB   R,   RO   t   has_default_valueRu   t
   ValueErrort   cpp_typet   CPPTYPE_MESSAGER@   R   t   GetTypeCheckerR>   (   R'   Rm   Rp   Rt   Rv   (    (   R'   R@   Ro   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRW      s"    		c            s7     j  }   f d   } d | _ d | _ | | _ d S(   s   Adds an __init__ method to cls.c            st  d |  _  t |  d k |  _ i  |  _ d |  _ t |  _ t j   |  _	 t
 |   |  _ x| j   D]\ } } t   |  } | d  k r t d   j | f   n  | j t j k r| j |   } | j t j k rx1 | D] } | j   j |  q Wn | j |  | |  j | <qd | j t j k r\| j |   } | j |  | |  j | <qd t |  | |  qd Wd  S(   Ni    s,   %s() got an unexpected keyword argument '%s'(    (   R4   t   lenR5   R6   R7   RY   R8   t   message_listener_modt   NullMessageListenerR9   t	   _ListenerR:   R`   t   _GetFieldByNamet   Nonet	   TypeErrorRg   RB   R,   RO   RH   Ry   Rz   t   addt	   MergeFromt   extendRf   (   t   selft   kwargst
   field_namet   field_valueR'   t   copyt   val(   R=   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   init,  s0    				N(   R   R   t
   __module__t   __doc__t   __init__(   R=   R   R   R   (    (   R=   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR   )  s
    			c         C   s7   y |  j  | SWn! t k
 r2 t d |   n Xd S(   s   Returns a field descriptor by field name.

  Args:
    message_descriptor: A Descriptor describing all fields in message.
    field_name: The name of the field to retrieve.
  Returns:
    The field descriptor associated with the field name.
  s#   Protocol message has no "%s" field.N(   t   fields_by_nameR-   Rx   (   R=   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR   O  s    	c         C   sC   x |  j  D] } t | |  q
 W|  j r? t d    | _ n  d S(   s=   Adds properties for all fields in this protocol message type.c         S   s
   t  |   S(   N(   t   _ExtensionDict(   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR   f  s    N(   R   t   _AddPropertiesForFieldt   is_extendablet   propertyt
   Extensions(   R   R   R'   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR    ^  s    	c         C   s   t  j d k s t  |  j j   d } t | | |  j  |  j t  j k r] t	 |  |  n/ |  j
 t  j k r t |  |  n t |  |  d S(   s#  Adds a public property for a protocol message field.
  Clients can use this property to get and (in the case
  of non-repeated scalar fields) directly set the value
  of a protocol message field.

  Args:
    field: A FieldDescriptor for this field.
    cls: The class we're constructing.
  i
   t   _FIELD_NUMBERN(   R,   t   MAX_CPPTYPERa   Rg   t   upperRf   RF   RB   RO   t   _AddPropertiesForRepeatedFieldRy   Rz   t*   _AddPropertiesForNonRepeatedCompositeFieldt'   _AddPropertiesForNonRepeatedScalarField(   R'   R   t   constant_name(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR   i  s    c            sv     j   t   }   f d   } d | _ d  | _  f d   } d  } t | | t | | d |  d S(   s  Adds a public property for a "repeated" protocol message field.  Clients
  can use this property to get the value of the field, which will be either a
  _RepeatedScalarFieldContainer or _RepeatedCompositeFieldContainer (see
  below).

  Note that when clients add values to these containers, we perform
  type-checking in the case of repeated scalar fields, and we also set any
  necessary "has" bits as a side-effect.

  Args:
    field: A FieldDescriptor for this field.
    cls: The class we're constructing.
  c            sI   |  j  j    } | d  k rE   j |   } |  j  j   |  } n  | S(   N(   R6   t   getR   RH   t
   setdefault(   R   R   (   R'   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   getter  s
    s   Getter for %s.c            s   t  d     d  S(   NsI   Assignment not allowed to repeated field "%s" in protocol message object.(   t   AttributeError(   R   t	   new_value(   R)   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   setter  s    s/   Magic attribute generated for "%s" proto field.t   docN(   Rg   R*   R   R   R   Rf   R   (   R'   R   t   property_nameR   R   R   (    (   R'   R)   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s    		
c            s    j  } t |  } t j  j  j    j   t   }    f d   } d | _	 d | | _
   f d   } d | _	 d | | _
 d | } t | | t | | d |  d S(   s  Adds a public property for a nonrepeated, scalar protocol message field.
  Clients can use this property to get and directly set the value of the field.
  Note that when the client sets the value of a field by using this property,
  all necessary "has" bits are set as a side-effect, and we also perform
  type-checking.

  Args:
    field: A FieldDescriptor for this field.
    cls: The class we're constructing.
  c            s   |  j  j     S(   N(   R6   R   (   R   (   Ru   R'   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s    s   Getter for %s.c            s4    j  |  | |  j   <|  j s0 |  j   n  d  S(   N(   t
   CheckValueR6   R5   t	   _Modified(   R   R   (   R'   Ro   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s    	s   Setter for %s.s/   Magic attribute generated for "%s" proto field.R   N(   Rg   R*   R   R{   Ry   R>   Ru   t   setR   R   R   Rf   R   (   R'   R   R)   R   t   valid_valuesR   R   R   (    (   Ru   R'   Ro   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s    					
c            s     j   t   }   j     f d   } d | _ d  | _  f d   } d  } t | | t | | d |  d S(   sN  Adds a public property for a nonrepeated, composite protocol message field.
  A composite field is a "group" or "message" field.

  Clients can use this property to get the value of the field, but cannot
  assign to the property directly.

  Args:
    field: A FieldDescriptor for this field.
    cls: The class we're constructing.
  c            sV   |  j  j    } | d  k rR  j   } | j |  j  |  j  j   |  } n  | S(   N(   R6   R   R   Rq   Rr   R:   R   (   R   R   (   R'   R@   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s    s   Getter for %s.c            s   t  d     d  S(   NsJ   Assignment not allowed to composite field "%s" in protocol message object.(   R   (   R   R   (   R)   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s    s/   Magic attribute generated for "%s" proto field.R   N(   Rg   R*   R@   R   R   R   Rf   R   (   R'   R   R   R   R   R   (    (   R'   R@   R)   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s    			
c         C   sM   |  j  } x= | j   D]/ \ } } | j   d } t | | | j  q Wd S(   s=   Adds properties for all fields in this protocol message type.R   N(   R_   R`   R   Rf   RF   (   R   R   Rb   Rc   Rd   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR!     s    	c            s@     f d   } t  |    _   f d   } t  |    _ d  S(   Nc            s     j  |  _ t   |     j j |  j |   } | |  k	 rk t d |  j | j   j  j |  j f   n  |    j |  j <|  } t	 |  r |    j |  j
 j <n  d  S(   NsS   Extensions "%s" and "%s" both try to extend message type "%s" with field number %d.(   R1   R0   R   R   R   RF   Ra   R/   R   RD   R@   (   R2   t   actual_handlet   handle(   R   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   RegisterExtension  s    	c            s       } | j  |   | S(   N(   t   MergeFromString(   t   sR	   (   R   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt
   FromString+  s    	(   t   staticmethodR   R   (   R   R   R   (    (   R   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR"     s    c         C   sM   |  d j  t j k r$ t |  d  S|  d j t j k rE |  d j St Sd S(   s   Given a (FieldDescriptor, value) tuple from _fields, return true if the
  value should be included in the list returned by ListFields().i    i   N(   RB   R,   RO   t   boolRy   Rz   R8   R\   (   t   item(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt
   _IsPresent2  s
    c         C   s   d   } | | _  d S(   s    Helper for _AddMessageMethods().c         S   sE   g  |  j  j   D] } t |  r | ^ q } | j d d    | S(   Nt   keyc         S   s   |  d j  S(   Ni    (   RF   (   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR   C  s    (   R6   R`   R   t   sort(   R   R   t
   all_fields(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt
   ListFieldsA  s    .N(   R   (   R=   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddListFieldsMethod>  s    	c            sX   i    x3 |  j  D]( } | j t j k r |   | j <q q W  f d   } | | _ d S(   s    Helper for _AddMessageMethods().c            sz   y   | } Wn! t  k
 r1 t d |   n X| j t j k ri |  j j |  } | d  k	 oh | j S| |  j k Sd  S(   Ns,   Protocol message has no singular "%s" field.(	   R-   Rx   Ry   R,   Rz   R6   R   R   R8   (   R   R   R'   t   value(   t   singular_fields(    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   HasFieldQ  s    N(   R   RB   R,   RO   Rg   R   (   R=   R   R'   R   (    (   R   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddHasFieldMethodI  s    c            s     f d   } | | _  d S(   s    Helper for _AddMessageMethods().c            s_   y   j  | } Wn! t k
 r4 t d |   n X| |  j k rQ |  j | =n  |  j   d  S(   Ns#   Protocol message has no "%s" field.(   R   R-   Rx   R6   R   (   R   R   R'   (   R=   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt
   ClearFieldb  s    N(   R   (   R=   R   R   (    (   R=   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddClearFieldMethod`  s    c         C   s   d   } | |  _  d S(   s    Helper for _AddMessageMethods().c         S   s7   t  |  |  | |  j k r) |  j | =n  |  j   d  S(   N(   R3   R6   R   (   R   R2   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   ClearExtensionx  s    N(   R   (   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddClearExtensionMethodv  s    	c         C   s   d   } | | _  d S(   s    Helper for _AddMessageMethods().c         S   s    i  |  _  d |  _ |  j   d  S(   N(    (   R6   R7   R   (   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   Clear  s    		N(   R   (   R=   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddClearMethod  s    	c         C   s   d   } | |  _  d S(   s    Helper for _AddMessageMethods().c         S   s}   t  |  |  | j t j k r5 t d | j   n  | j t j k rl |  j j	 |  } | d  k	 ok | j S| |  j k Sd  S(   Ns   "%s" is repeated.(   R3   RB   R,   RO   R-   R/   Ry   Rz   R6   R   R   R8   (   R   R2   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   HasExtension  s    N(   R   (   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddHasExtensionMethod  s    	
c         C   s   d   } | | _  d S(   s    Helper for _AddMessageMethods().c         S   s   t  | t j  s% | j |  j k r) t S|  | k r9 t S|  j   | j   k sU t St |  j  } | j	   t | j  } | j	   | | k S(   N(
   R+   t   message_modt   MessageR1   RY   R\   R   t   listR7   R   (   R   t   othert   unknown_fieldst   other_unknown_fields(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   __eq__  s    

N(   R   (   R=   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddEqualsMethod  s    	c         C   s   d   } | | _  d S(   s    Helper for _AddMessageMethods().c         S   s   t  j |   S(   N(   R
   t   MessageToString(   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   __str__  s    N(   R   (   R=   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddStrMethod  s    	c         C   s   d   } | | _  d S(   s    Helper for _AddMessageMethods().c         S   s   t  j |  d t j d  S(   Nt   as_utf8s   utf-8(   R
   R   R\   t   decode(   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   __unicode__  s    N(   R   (   t   unused_message_descriptorR   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddUnicodeMethod  s    	c         C   s   d   } | |  _  d S(   s    Helper for _AddMessageMethods().c         S   s+   | d  k r t j   |  _ n	 | |  _ d  S(   N(   R   R}   R~   R9   (   R   t   listener(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   SetListener  s    N(   Rr   (   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddSetListenerMethod  s    	c         C   sI   y t  j | } | | |   SWn$ t k
 rD t j d |   n Xd S(   s   Returns the number of bytes needed to serialize a non-repeated element.
  The returned byte count includes space for tag information and any
  other additional space associated with serializing value.

  Args:
    value: Value we're serializing.
    field_number: Field number of this value.  (Since the field number
      is stored as part of a varint-encoded tag, this has an impact
      on the total bytes required to serialize the value).
    field_type: The type of the field.  One of the TYPE_* constants
      within FieldDescriptor.
  s   Unrecognized field type: %dN(   R   t   TYPE_TO_BYTE_SIZE_FNR-   R   t   EncodeError(   R   t   field_numbert
   field_typet   fn(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _BytesForNonRepeatedElement  s
    c         C   s   d   } | | _  d S(   s    Helper for _AddMessageMethods().c         S   s   |  j  s |  j Sd } x- |  j   D] \ } } | | j |  7} q# Wx1 |  j D]& \ } } | t |  t |  7} qP W| |  _ t |  _  t |  j _ | S(   Ni    (	   R5   R4   R   RV   R7   R|   RY   R:   t   dirty(   R   t   sizeRL   R   RK   t   value_bytes(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   ByteSize  s    			N(   R   (   R=   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddByteSizeMethod  s    	c         C   s   d   } | | _  d S(   s    Helper for _AddMessageMethods().c         S   sM   g  } |  j    sC t j d |  j j d j |  j    f   n  |  j   S(   Ns)   Message %s is missing required fields: %st   ,(   t   IsInitializedR   R   R1   R/   t   joint   FindInitializationErrorst   SerializePartialToString(   R   t   errors(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   SerializeToString  s    (N(   R   (   R=   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddSerializeToStringMethod  s    	c         C   s(   d   } | | _  d   } | | _ d S(   s    Helper for _AddMessageMethods().c         S   s#   t    } |  j | j  | j   S(   N(   R    t   _InternalSerializet   writet   getvalue(   R   t   out(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s    	c         S   s_   x* |  j    D] \ } } | j | |  q Wx+ |  j D]  \ } } | |  | |  q7 Wd  S(   N(   R   RU   R7   (   R   t   write_bytesRL   R   RK   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   InternalSerialize  s
    
N(   R   R   (   R=   R   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt"   _AddSerializePartialToStringMethod  s    			c            sO   d   } | | _  t j  t j  | j       f d   } | | _ d S(   s    Helper for _AddMessageMethods().c         S   s   t  |  } y1 |  j | d |  | k r< t j d   n  WnD t k
 r_ t j d   n% t j k
 r } t j |   n X| S(   Ni    s   Unexpected end-group tag.s   Truncated message.(   R|   t   _InternalParseR   t   DecodeErrort
   IndexErrort   structt   error(   R   t
   serializedt   lengtht   e(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s    c   
         s   |  j    |  j } |  j } x | | k r  | |  \ } }   j |  } | d  k r | }	  | | | |  } | d k r | S| s g  } |  _ n  | j | | |	 | !f  | } q | | | | |  |  } q W| S(   Ni(   R   R6   R7   R   R   t   append(
   R   t   buffert   post   endt
   field_dictt   unknown_field_listRK   t   new_post   field_decodert   value_start_pos(   t   decoders_by_tagt   local_ReadTagt   local_SkipField(    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   InternalParse*  s"    
			N(   R   R   t   ReadTagt	   SkipFieldR   R   (   R=   R   R   R  (    (   R  R  R  sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddMergeFromStringMethod  s    					c            se   g  |  j  D] } | j t j k r
 | ^ q
   d   f d  } | | _   f d   } | | _ d S(   s[   Adds the IsInitialized and FindInitializationError methods to the
  protocol message class.c            s6  xf   D]^ } | |  j  k s? | j t j k r |  j  | j r | d k	 ra | j |  j    n  t Sq Wx |  j  j	   D] \ } } | j t j k ry | j
 t j k r x | D]8 } | j   s | d k	 r | j |  j    n  t Sq Wq.| j r.| j   r.| d k	 r'| j |  j    n  t Sqy qy Wt S(   s  Checks if all required fields of a message are set.

    Args:
      errors:  A list which, if provided, will be populated with the field
               paths of all missing required fields.

    Returns:
      True iff the specified message has all required fields set.
    N(   R6   Ry   R,   Rz   R8   R   R   R   RY   R`   RB   RO   R   R\   (   R   R   R'   R   t   element(   t   required_fields(    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR   G  s(    c   
         sD  g  } x3   D]+ } |  j  | j  s | j | j  q q Wx|  j   D] \ } } | j t j k rI | j r d | j } n	 | j } | j	 t j
 k rx t t |   D]M } | | } d | | f } | j   } | g  | D] }	 | |	 ^ q 7} q Wq<| d } | j   } | g  | D] }	 | |	 ^ q"7} qI qI W| S(   s   Finds required fields which are not initialized.

    Returns:
      A list of strings.  Each string is a path to an uninitialized field from
      the top-level message, e.g. "foo.bar[5].baz".
    s   (%s)s   %s[%d].t   .(   R   Rg   R   R   Ry   R,   Rz   R.   R/   RB   RO   t   xrangeR|   R   (
   R   R   R'   R   Rg   t   iR	  t   prefixt
   sub_errorsR   (   R
  (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR   m  s&    		
(
(N(   R   RB   R,   t   LABEL_REQUIREDR   R   R   (   R=   R   R'   R   R   (    (   R
  sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddIsInitializedMethod@  s    $	"c            s4   t  j  t  j       f d   } |  _ d  S(   Nc            sv  t  |   s4 t d  j t |  j f   n  | |  k	 sF t  |  j   |  j } x | j j   D] \ } } | j  k r | j	 |  } | d  k r | j |   } | | | <n  | j |  qi | j   k r-| j r:| j	 |  } | d  k r| j |   } | | | <n  | j |  q:qi | |  j | <qi W| j rr|  j s\g  |  _ n  |  j j | j  n  d  S(   NsL   Parameter to MergeFrom() must be instance of same class: expected %s got %s.(   R+   R   t   __name__R>   Ra   R   R6   R`   RB   R   R   RH   R   Ry   R8   R7   R   (   R   t   msgR   R'   R   R   (   Rz   RO   R   (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s4    
				(   R,   RO   Rz   R   (   R   R   (    (   Rz   RO   R   sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _AddMergeFromMethod  s    		#c         C   s   t  |  |  t |  |  t |  |  |  j rG t |  t |  n  t |  |  t |  |  t |  |  t	 |  |  t
 |  t |  |  t |  |  t |  |  t |  |  t |  |  t |  d S(   s3   Adds implementations of all Message methods to cls.N(   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R  (   R=   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR#     s"    	

c         C   s   d   } | |  _  | |  _ d S(   s5   Adds implementation of private helper methods to cls.c         S   s;   |  j  s7 t |  _  t |  j _ t |  _ |  j j   n  d S(   sw   Sets the _cached_byte_size_dirty bit to true,
    and propagates this to our listener iff this was a state change.
    N(   R5   R\   R:   R   R8   R9   t   Modified(   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR    s
    				N(   R   t   SetInParent(   R   R  (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR$     s    		R   c           B   s    e  Z d  Z d   Z d   Z RS(   s0  MessageListener implementation that a parent message registers with its
  child message.

  In order to support semantics like:

    foo.bar.baz.qux = 23
    assert foo.HasField('bar')

  ...child objects must have back references to their parents.
  This helper class is at the heart of this support.
  c         C   s=   t  | t j  r | |  _ n t j |  |  _ t |  _ d S(   s   Args:
      parent_message: The message whose _Modified() method we should call when
        we receive Modified() messages.
    N(   R+   t   weakreft	   ProxyTypet   _parent_message_weakreft   proxyRY   R   (   R   t   parent_message(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s    	c         C   s6   |  j  r d  Sy |  j j   Wn t k
 r1 n Xd  S(   N(   R   R  R   t   ReferenceError(   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR    s    	(   R  R   R   R   R  (    (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s   	R   c           B   sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s   Dict-like container for supporting an indexable "Extensions"
  field on proto instances.

  Note that in all cases we expect extension handles to be
  FieldDescriptors.
  c         C   s   | |  _  d S(   sM   extended_message: Message instance for which we are the Extensions dict.
    N(   t   _extended_message(   R   t   extended_message(    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR   "  s    c         C   s   t  |  j |  |  j j j |  } | d k	 r5 | S| j t j k r\ | j |  j  } nV | j	 t j
 k r | j j   } y | j |  j j  Wq t k
 r q Xn | j S|  j j j | |  } | S(   s8   Returns the current value of the given extension handle.N(   R3   R  R6   R   R   RB   R,   RO   RH   Ry   Rz   R@   Rq   Rr   R:   R  Ru   R   (   R   R2   Rs   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   __getitem__(  s     c         C   s   t  | |  j  s t S|  j j   } | j j   } g  | D] } | j r; | ^ q; } g  | D] } | j r] | ^ q] } | | k S(   N(   R+   t	   __class__RY   R  R   R.   (   R   R   t	   my_fieldst   other_fieldsR'   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR   I  s    ""c         C   s   |  | k S(   N(    (   R   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   __ne__V  s    c         C   s   t  d   d  S(   Ns   unhashable object(   R   (   R   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   __hash__Y  s    c         C   s   t  |  j |  | j t j k s4 | j t j k rJ t d | j   n  t	 j
 | j | j  } | j |  | |  j j | <|  j j   d S(   sl   If extension_handle specifies a non-repeated, scalar extension
    field, sets the value of that field.
    sK   Cannot assign to extension "%s" because it is a repeated or composite type.N(   R3   R  RB   R,   RO   Ry   Rz   R   R/   R   R{   R>   R   R6   R   (   R   R2   R   Ro   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   __setitem__`  s    c         C   s   |  j  j j | d  S(   s   Tries to find a known extension with the specified name.

    Args:
      name: Extension full name.

    Returns:
      Extension field descriptor.
    N(   R  R   R   R   (   R   Rg   (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   _FindExtensionByNameu  s    	(
   R  R   R   R   R  R   R#  R$  R%  R&  (    (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR     s   		!				(C   R   t
   __author__t	   cStringIOR    t   ImportErrorR%   R   R  t   google.protobuf.internalR   R   R   R   R   R}   R   R   t   google.protobufR   t   descriptor_modR	   R   R
   t   FieldDescriptorR,   R   R(   R*   R3   R   RD   R   R   R   RW   R   R   R    R   R   R   R   R!   R"   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R  R#   R$   t   objectR   R   (    (    (    sK   /usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt   <module>1   sx   									#			1	&				,	'	3		"						
					
					*	R	*		2