� S�Ljc@s!dZdZddlmZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddlm Z dd lm Z dd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZejZdZdefd��YZd�Zd�Zd�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&�Z0d'�Z1d(�Z2d)�Z3d*�Z4d+Z5d,Z6d-�Z7d.�Z8d/�Z9d0�Z:d1�Z;d2�Z<d3�Z=d4�Z>d5�Z?d6�Z@d7�ZAd8�ZBd9�ZCd:�ZDd;�ZEd<�ZFd=�ZGd>�ZHd?�ZId@�ZJdA�ZKdB�ZLdC�ZMdDeNfdE��YZOdFeOfdG��YZPdHeNfdI��YZQdS(Js 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#[email protected] (Will Robinson)i����(tBytesION(tapi_implementation(t containers(tdecoder(tencoder(tenum_type_wrapper(tmessage_listener(t type_checkers(twell_known_types(t wire_format(t descriptor(tmessage(t text_formatsgoogle.protobuf.AnytGeneratedProtocolMessageTypecBs&eZdZdZd�Zd�ZRS(sQMetaclass for protocol message classes created at runtime from Descriptors. We add implementations for all methods described in the Message class. We also create properties to allow getting/setting all fields in the protocol message. Finally, we create slots to prevent users from accidentally "setting" nonexistent fields in the protocol message, which then wouldn't get serialized / deserialized properly. The protocol compiler currently uses this metaclass to create protocol message classes at runtime. Clients can also manually create their own classes at runtime, as in this example: mydescriptor = Descriptor(.....) factory = symbol_database.Default() factory.pool.AddDescriptor(mydescriptor) MyProtoClass = factory.GetPrototype(mydescriptor) myproto_instance = MyProtoClass() myproto.foo_field = 23 ... t DESCRIPTORcCs~|tj}|jtjkr9|tj|jf7}nt||�t||�tt|�}|j||||�}|S(sCustom allocation for runtime-generated class types. We override __new__ because this is apparently the only place where we can meaningfully set __slots__ on the class we're creating(?). (The interplay between metaclasses and slots is not very well-documented). Args: name: Name of the class (ignored, but required by the metaclass protocol). bases: Base classes of the class we're constructing. (Should be message.Message). We ignore this field, but it's required by the metaclass protocol dictionary: The class dictionary of the class we're constructing. dictionary[_DESCRIPTOR_KEY] must contain a Descriptor object describing this protocol message type. Returns: Newly-allocated class. ( R t_DESCRIPTOR_KEYt full_nameRtWKTBASESt&_AddClassAttributesForNestedExtensionst _AddSlotstsupert__new__(tclstnametbasest dictionaryR t superclasst new_class((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRis   cCs�|tj}i|_|jrP|j�jrPtj|�df|jtj tj�j�j�|�}tj�j�j�|�}|�_|�_t���_����fd�}|tj�jt��r�tj�j�r�|tjt�ndS(Ntproto2tpackedcs�tj�j|�}�j}|tjkrHtj��rHtj}nd}�j dk rf�}n�r�t ��}t j �t��|�}n%tj|�j�|��j�}||f�j|�j�}|j�jdk r0t|��n|j�|S(N(R%t _SetListenerR[R!t_OneofListenerRA(R tresult(R.RK(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pytMakeSubMessageDefault�s   cs�jS(N(t default_value(R (R.(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pytMakeScalarDefault�s( RMR]RHR5Rkthas_default_valueR�R�RPRQRKRR�(R.R�R�R�R�((R.RKR�sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRx�s&    cCs�tj�d}t|j�dkrYt|�tkrYtdt|�||f�}ntjt|�|tj�d�dS(sCRe-raise the currently-handled TypeError with the field name added.is%s for field %s.%siN( tsystexc_infotlentargsRFt TypeErrortstrtsixtreraise(t message_namet field_nametexc((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_ReraiseTypeErrorWithFieldName�s'"cs:d����fd�}d|_d|_||_dS(sAdds an __init__ method to cls.cSsXt|tj�rTy|j|jSWqTtk rPtd|j|f��qTXn|S(sConvert a string or integer enum value to an integer. If the value is a string, it is converted to the enum value in enum_type with the same name. If the value is not a string, it's returned as-is. (No conversion or bounds-checking is done.) s Enum type %s: unknown label "%s"(R4R�t string_typestvalues_by_nameRWR6R�R(R�RN((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_GetIntegerEnumValue�s c s�d|_t|�dk|_i|_i|_d|_t|_tj �|_ t |�|_ xs|j �D]e\}}t�|�}|dkr�td�j|f��n|dkr�qmn|jtjkr�|j|�}|jtjkr�t|�rFt|�r6x3|D]}||j||�qWq�|j|�q�x�|D]8}t|t�rr|j|�qM|j�j|�qMWnG|jtjkr�g|D]}�|j |�^q�}n|j!|�||j|RmR?tmessage_listener_modtNullMessageListenerR@t _ListenerRAR�t_GetFieldByNameR!R�RRHR5RkR_RPRQRMRSt MergeFromtupdateR4tdicttaddt CPPTYPE_ENUMR�textendRKR%R�R�( tselftkwargsR�t field_valueR.tcopyR�tvaltnew_val(R�RE(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pytinit�s`           %   N(R!R0R1R-(RERR�((R�REsK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR'�s  =  cCs@y|j|SWn*tk r;td|j|f��nXdS(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 %s has no "%s" field.N(ROR6R�R(RER�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR�s  cCsCx|jD]}t||�q W|jr?td��|_ndS(s=Adds properties for all fields in this protocol message type.cSs t|�S(N(t_ExtensionDict(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt/tN(R#t_AddPropertiesForFieldt is_extendabletpropertyt Extensions(R RR.((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR('s cCs{|jj�d}t|||j�|jtjkrHt||�n/|jtj krjt ||�n t ||�dS(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. t _FIELD_NUMBERN( RtupperR�RWRHR5Rkt_AddPropertiesForRepeatedFieldRPRQt*_AddPropertiesForNonRepeatedCompositeFieldt'_AddPropertiesForNonRepeatedScalarField(R.Rt constant_name((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR�2scsv�j�t��}�fd�}d|_d�|_�fd�}d�}t||t||d|��dS(sAdds 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. csI|jj��}|dkrE�j|�}|jj�|�}n|S(N(R=tgetR!R_t setdefault(R�R�(R.(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pytgetter\s  sGetter for %s.cstd���dS(NsIAssignment not allowed to repeated field "%s" in protocol message object.(tAttributeError(R�t new_value(R2(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pytsetteross/Magic attribute generated for "%s" proto field.tdocN(RR3R!R0R1R�R�(R.Rt property_nameR�R�R�((R.R2sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR�Ks     c s��j}t|�}tj����j�t�}�jjdk}��fd�}d |_ d||_ |o}�j ����fd���j r���fd�}n�}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. tproto3cs|jj���S(N(R=R�(R�(R�R.(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR��ssGetter for %s.csY�j|�}�r2| r2|jj�d�n ||j�<|jsU|j�ndS(N(t CheckValueR=tpopR!R<t _Modified(R�R�(tclear_when_set_to_defaultR.R�(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt field_setter�s    cs�||�|j��dS(N(t_UpdateOneofState(R�R�(R.R�(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR��s sSetter for %s.s/Magic attribute generated for "%s" proto field.R�N(RR3RR�R�tsetR8RnR!R0R1R[R�R�( R.RR2R�t valid_valuest is_proto3R�R�R�((R�R�R.R�R�sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR�ws$          csv�j�t��}�fd�}d|_d�|_�fd�}d�}t||t||d|��dS(sNAdds 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. csI|jj��}|dkrE�j|�}|jj�|�}n|S(N(R=R�R!R_R�(R�R�(R.(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR��s  sGetter for %s.cstd���dS(NsJAssignment not allowed to composite field "%s" in protocol message object.(R�(R�R�(R2(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR��ss/Magic attribute generated for "%s" proto field.R�N(RR3R!R0R1R�R�(R.RR�R�R�R�((R.R2sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR��s     cCs�|j}x=|j�D]/\}}|j�d}t|||j�qW|jdk r�|jj}|j||_|j ||_ ndS(s=Adds properties for all fields in this protocol message type.R�N( R�R�R�R�RWtfileR!tpoolt_extensions_by_numbert_extensions_by_name(R RR�R�R�R�R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR)�s  cs@�fd�}t|��_�fd�}t|��_dS(Ncs3�j|_�jjjj|�t�|�dS(N(RR8R�R�tAddExtensionDescriptorR$(R9(R(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pytRegisterExtension�s cs��}|j|�|S(N(tMergeFromString(tsR (R(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt FromString�s  (t staticmethodR�R�(RR�R�((RsK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR*�scCsM|djtjkr$t|d�S|djtjkrE|djStSdS(s�Given a (FieldDescriptor, value) tuple from _fields, return true if the value should be included in the list returned by ListFields().iiN(RHR5RktboolRPRQR?R{(titem((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt _IsPresent�s  cCsd�}||_dS(s Helper for _AddMessageMethods().cSsEg|jj�D]}t|�r|^q}|jdd��|S(NR�cSs |djS(Ni(RW(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR� R�(R=R�R�tsort(R�R�t all_fields((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt ListFields s.N(R�(RERR�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddListFieldsMethods s:Protocol message has no non-repeated submessage field "%s"s/Protocol message has no non-repeated field "%s"cs�|jdk}|rtnt�i�x^|jD]S}|jtjkrOq1n|rw|jtjkrw|j rwq1n|�|j R�(R�tothertany_atany_btunknown_fieldstother_unknown_fields((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt__eq__�s"       N(R(RERR((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddEqualsMethod�s cCsd�}||_dS(s Helper for _AddMessageMethods().cSs tj|�S(N(R tMessageToString(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt__str__�sN(R(RERR((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt _AddStrMethod�s cCsd�}||_dS(s Helper for _AddMessageMethods().cSs tj|�S(N(R R(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt__repr__�sN(R(RERR((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddReprMethod�s cCsd�}||_dS(s Helper for _AddMessageMethods().cSstj|dt�jd�S(Ntas_utf8sutf-8(R RR{tdecode(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt __unicode__�sN(R#(tunused_message_descriptorRR#((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddUnicodeMethod�s cCsIytj|}|||�SWn$tk rDtjd|��nXdS(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. sUnrecognized field type: %dN(RtTYPE_TO_BYTE_SIZE_FNR6Rt EncodeError(RNt field_numbert field_typetfn((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_BytesForNonRepeatedElement�s   cCsd�}||_dS(s Helper for _AddMessageMethods().cSs�|js|jSd}|j}|j�jrg|jdj|j�}||jdj|j�7}ndx-|j �D]\}}||j|�7}qtWx1|j D]&\}}|t |�t |�7}q�W||_t |_t |j _|S(NiR�RN(R<R;RRRLRORwR�RNR�R>R�RmRAtdirty(R�tsizeR RgR�Rbt value_bytes((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pytByteSize�s      N(R/(RERR/((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddByteSizeMethod�s cCsd�}||_dS(s Helper for _AddMessageMethods().c[sPg}|j�sCtjd|jjdj|j��f��n|j|�S(Ns)Message %s is missing required fields: %st,(t IsInitializedRR'RRtjointFindInitializationErrorstSerializePartialToString(R�R�terrors((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pytSerializeToString s  (N(R7(RERR7((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddSerializeToStringMethods cCs+d�}||_dd�}||_dS(s Helper for _AddMessageMethods().c[s&t�}|j|j|�|j�S(N(Rt_InternalSerializetwritetgetvalue(R�R�tout((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR5s cSs�|dkrtj�}n t|�}|j}|j�jr||jdj||j |�|jdj||j |�n^x-|j �D]\}}|j|||�q�Wx+|j D] \}}||�||�q�WdS(NR�RN( R!Rt)IsPythonDefaultSerializationDeterministicR�RRRLRORvR�RNR�R>(R�t write_bytest deterministicR RgR�RbR.((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pytInternalSerializes      N(R5R!R9(RERR5R@((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt"_AddSerializePartialToStringMethods   csad�}||_tj�tj�|j�|jdk�����fd�}||_dS(s Helper for _AddMessageMethods().cSs�t|�}y1|j|d|�|kr<tjd��nWnJttfk retjd��n%tjk r�}tj|��nX|S(NisUnexpected end-group tag.sTruncated message.(R�t_InternalParseRt DecodeErrort IndexErrorR�tstructterror(R�t serializedtlengthte((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR�8s R�c s|j�|j}|j}x�||kr�||�\}}�j|d�\}} |dkr�|} �||||�}|dkr�|S� s�tj�r�|s�g}|_n|j||| |!f�n|}q||||||�}| r|j| �qqW|S(Ni����(NN( R�R=R>R�R!Rt&GetPythonProto3PreserveUnknownsDefaulttappendR�( R�tbuffertpostendt field_dicttunknown_field_listRbtnew_posRft field_desctvalue_start_pos(tdecoders_by_tagR�t local_ReadTagtlocal_SkipField(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt InternalParseLs,       N(R�RtReadTagt SkipFieldRRnRB(RERR�RW((RTR�RURVsK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddMergeFromStringMethod6s    cseg|jD]}|jtjkr |^q �d�fd�}||_�fd�}||_dS(s[Adds the IsInitialized and FindInitializationError methods to the protocol message class.cs`xf�D]^}||jks?|jtjkr|j|j r|dk ra|j|j��ntSqWx�t |jj ��D]�\}}|jtjkr|j tj kr|j jr�|j j�jr�qnx|D]8}|j�s�|dk r|j|j��ntSq�WqX|jrX|j� rX|dk rQ|j|j��ntSqqWtS(sChecks 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(R=RPR5RQR?R!R�R4RmRR�RHRkRKRRRLR2R{(R�R6R.RNtelement(trequired_fields(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR2ns.  "       c s�g}x3�D]+}|j|j�s |j|j�q q Wxw|j�D]i\}}|jtjkrI|jr�d|j}n |j}t |�r�t |�r�xX|D]M}||}d||f}|j �}|g|D]} || ^q�7}q�Wq�q�|j tj krxx�tt|��D]M} || }d|| f}|j �}|g|D]} || ^qZ7}q$Wq�|d}|j �}|g|D]} || ^q�7}qIqIW|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[%s].s%s[%d].t.(RoRRKR�RPR5RQR7RRMRSR4RHRktrangeR�( R�R6R.RNRR�R[tprefixt sub_errorsRFti(R\(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR4�s6        (  (  (N(R#RHR5tLABEL_REQUIREDR!R2R4(RERR.R2R4((R\sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddIsInitializedMethodgs ' ,cs4tj�tj����fd�}|�_dS(Ncszt|��s1td�j|jjf��n|j�|j}x�|jj�D]�\}}|j�kr�|j|�}|dkr�|j |�}||||j|�}|dkr|j |�}|||qT||j|<|jrT|j|�qTqTW|jrv|js`g|_n|jj|j�ndS(NsLParameter to MergeFrom() must be instance of same class: expected %s got %s.(R4R�R/t __class__R�R=R�RHR�R!R_R�RPR?R[R�R>R�(R�R R#R.RNR�(RQRkR(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR��s6            (R5RkRQR�(RR�((RQRkRsK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddMergeFromMethod�s  %cs�fd�}||_dS(Ncswy�j|}Wn!tk r4td|��nX|jj|d�}|dk ro|j|j�ro|jSdSdS(sDReturns the name of the currently set field inside a oneof, or None.s)Protocol message has no oneof "%s" field.N(R�R6R�RCR�R!RoR(R�t oneof_nameR.t nested_field(RE(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt WhichOneof�s (Rh(RERRh((REsK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddWhichOneofMethod�scCsd�}||_dS(NcSst|�d|j�fS(N((RFt __getstate__(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt __reduce__s(Rk(RRk((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddReduceMethods cCs)i|_d|_i|_|j�dS(N((R=R>RCR�(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_Clear s   cCsyg|_xi|j�D][\}}|jtjkr|jtjkrdx%|D]}|j�qMWqq|j�qqWdS(N(R>R�RPR5RQRHRktDiscardUnknownFields(R�R.RNt sub_message((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_DiscardUnknownFieldss  cCs+|dkrtj�|_n ||_dS(N(R!R�R�R@(R�tlistener((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR�s cCs�t||�t||�t||�|jrGt|�t|�nt||�t||�t||�t ||�t ||�t ||�t ||�t ||�t||�t|�t||�t|�t|_t|_t|_dS(s3Adds implementations of all Message methods to cls.N(R�R�R�R�RRRRR R%R0R8RARZRcReRiRlRmtClearRpRnR�(RER((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR+$s*                    cCs1d�}d�}||_||_||_dS(s5Adds implementation of private helper methods to cls.cSs;|js7t|_t|j_t|_|jj�ndS(swSets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change. N(R<R{RAR,R?R@tModified(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRsAs    cSsE|jj|j|�}||k rA|j|=||j|js    R�cBs eZdZd�Zd�ZRS(s0MessageListener 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. cCs=t|tj�r||_ntj|�|_t|_dS(s�Args: parent_message: The message whose _Modified() method we should call when we receive Modified() messages. N(R4tweakreft ProxyTypet_parent_message_weakreftproxyRmR,(R�tparent_message((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR-ns  cCs6|jr dSy|jj�Wntk r1nXdS(N(R,RxR�tReferenceError(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs�s   (R/R0R1R-Rs(((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR�`s  R�cBs eZdZd�Zd�ZRS(sCSpecial listener implementation for setting composite oneof fields.cCs#tt|�j|�||_dS(s�Args: parent_message: The message whose _Modified() method we should call when we receive Modified() messages. field: The descriptor of the field being set in the parent message. N(RR�R-t_field(R�RzR.((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR-�scCsBy*|jj|j�tt|�j�Wntk r=nXdS(sEAlso updates the state of the containing oneof in the parent message.N(RxR�R|RR�RsR{(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs�s  (R/R0R1R-Rs(((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR��s R�cBsVeZdZd�Zd�Zd�Zd�Zd�Zd�Zd�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. cCs ||_dS(sMextended_message: Message instance for which we are the Extensions dict. N(t_extended_message(R�textended_message((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR-�scCs�t|j|�|jjj|�}|dk r5|S|jtjkr\|j|j�}nV|j tj kr�|j j �}y|j |jj�Wq�tk r�q�Xn|jS|jjj||�}|S(s8Returns the current value of the given extension handle.N(R:R}R=R�R!RHR5RkR_RPRQRKR%R�RAR{R�R�(R�R9R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt __getitem__�s     cCs�t||j�stS|jj�}|jj�}g|D]}|jr;|^q;}g|D]}|jr]|^q]}||kS(N(R4RdRmR}R�R7(R�Rt my_fieldst other_fieldsR.((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR�s""cCs ||k S(N((R�R((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt__ne__�scCstd��dS(Nsunhashable object(R�(R�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt__hash__�scCs�t|j|�|jtjks4|jtjkrJtd|j��nt j |�}|j |�|jj |<|jj �dS(slIf extension_handle specifies a non-repeated, scalar extension field, sets the value of that field. sKCannot assign to extension "%s" because it is a repeated or composite type.N(R:R}RHR5RkRPRQR�RRR�R�R=R�(R�R9RNR�((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt __setitem__�scCs|jjj|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�R((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_FindExtensionByNames cCs|jjj|d�S(s�Tries to find a known extension with the field number. Args: number: Extension field number. Returns: Extension field descriptor. N(R}R�R�R!(R�RW((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_FindExtensionByNumbers ( R/R0R1R-RRR�R�R�R�R�(((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR��s  !    (RR1t __author__tioRRER�RvR�tgoogle.protobuf.internalRRRRRRR�RRR RR R�R RR tFieldDescriptorR5RRFR R3R:RRJRMRSR$RR&R]RxR�R'R�R(R�R�R�R�R)R*R�R�R�R�R�R�RRRRRR R%R+R0R8RARZRcReRiRlRmRpR�R+R,tobjectR�R�R�(((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt1s�     k       C    7 T   , 8 ,    * &  (        1 _ ,      ".