Q,Qc@sdZdZyddlmZWn!ek rCddlmZnXddlZddlZddlZddlm Z ddlm Z ddlm Z ddlm Z dd lm Zdd lmZdd lmZdd lmZdd lmZddlmZejZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)d Z*d!Z+d"Z,d#Z-d$Z.d%Z/d&Z0d'Z1d(Z2d)Z3d*Z4d+Z5d,Z6d-Z7d.Z8d/Z9d0Z:d1Z;d2Z<d3Z=d4Z>d5Z?d6e@fd7YZAd8e@fd9YZBdS(: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(tStringION(t containers(tdecoder(tencoder(tenum_type_wrapper(tmessage_listener(t type_checkers(t wire_format(t descriptor(tmessage(t text_formatcCst||t|||S(N(t&_AddClassAttributesForNestedExtensionst _AddSlots(tbasesRt dictionary((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt NewMessageLs  csi_i_i_|jrR|jjrRtjjjtjfs(t_decoders_by_tagt_extensions_by_namet_extensions_by_numbert has_optionst GetOptionstmessage_set_wire_formatRtMessageSetItemDecodertMESSAGE_SET_ITEM_TAGtfieldst_AttachFieldHelperst_AddEnumValuest_AddInitMethodt_AddPropertiesForFieldst_AddPropertiesForExtensionst_AddStaticMethodst_AddMessageMethodst_AddPrivateHelperMethodstcopy_regtpickle(RRtfield((RsK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt InitMessageRs            cCs|S(sReturns 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. ((tproto_field_name((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt _PropertyNameqscCst|ts"td|n|jsAtd|jn|js`td|jn|j|jk rtd|j|jj|jjfndS(s0Verify that the given extension handle is valid.s3HasExtension() expects an extension handle, got: %ss"%s" is not an extension.s""%s" is missing a containing_type.sKExtension "%s" extends message type "%s", but this message is of type "%s".N(t isinstancet_FieldDescriptortKeyErrort is_extensiont full_nametcontaining_typet DESCRIPTOR(R textension_handle((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_VerifyExtensionHandles    cCs&ddddddddg|d t j j j |}t jj j |}|_|_t_fd}|t jj trtjj r|tjtndS(NcsHtjj|}tjjj|jj|t_default_constructorR(twiretypet is_packedt tag_bytes(Rtfield_descriptort is_repeated(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt AddDecoders  (RBR,tLABEL_REPEATEDRRtpackedRDRtMessageSetItemEncoderRFtMessageSetItemSizerRtTYPE_TO_ENCODERR>t TYPE_TO_SIZERt_encodert_sizert _DefaultValueConstructorForFieldRHtFIELD_TYPE_TO_WIRE_TYPEtFalseRtIsTypePackabletWIRETYPE_LENGTH_DELIMITEDtTrue(RRLRJt field_encodertsizerRN((RRLRMsK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs&       cCsF|j}x6|jD](\}}||ks4t|||(R'RmRpRtRv((R'R@RosK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRWs"  cs7j}fd}d|_d|_||_dS(sAdds an __init__ method to cls.cstd|_t|dk|_i|_d|_t|_tj|_ t ||_ x|j D]\}}t |}|dkrtdj|fn|jtjkr|j|}|jtjkrx1|D]}|jj|qWn |j|||j|RutsetRRRRfR(R'RR)Rt valid_valuesRRR((RuR'RosK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs         csjt}jfd}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. csV|jj}|dkrRj}|j|j|jj|}n|S(N(R6RRRqRrR:R(RR(R'R@(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs   sGetter for %s.cstddS(NsJAssignment not allowed to composite field "%s" in protocol message object.(R(RR(R)(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRss/Magic attribute generated for "%s" proto field.RN(RgR*R@RRRRfR(R'RRRRR((R'R@R)sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs      cCsM|j}x=|jD]/\}}|jd}t|||jqWdS(s=Adds properties for all fields in this protocol message type.RN(R_R`RRfRF(RRRbRcRdR((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR!s cs@fd}t|_fd}t|_dS(Ncsj|_t|jj|j|}||k rktd|j|jjj|jfn|j|j<|}t |r|j|j js csXix3|jD](}|jtjkr||jRaRR6R`RBRRRHRRyR8R7R(RtmsgRR'RR(RzROR(sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs4          (R,RORzR(RR((RzRORsK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_AddMergeFromMethods  #cCst||t||t|||jrGt|t|nt||t||t||t ||t |t ||t ||t ||t||t||t|dS(s3Adds implementations of all Message methods to cls.N(RRRRRRRRRRRRRRRRR(R=R((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR#s"                cCsd}||_||_dS(s5Adds implementation of private helper methods to cls.cSs;|js7t|_t|j_t|_|jjndS(swSets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change. N(R5R\R:RR8R9tModified(R((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs    N(Rt SetInParent(RR((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR$s  RcBs eZdZdZdZRS(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|tjr||_ntj||_t|_dS(sArgs: parent_message: The message whose _Modified() method we should call when we receive Modified() messages. N(R+tweakreft ProxyTypet_parent_message_weakreftproxyRYR(Rtparent_message((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs  cCs6|jr dSy|jjWntk r1nXdS(N(RRRtReferenceError(R((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs   (RRRRR(((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs  RcBsMeZdZdZdZdZdZdZdZdZ RS(sDict-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(Rtextended_message((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyR"scCst|j||jjj|}|dk r5|S|jtjkr\|j|j}nV|j tj kr|j j }y|j |jjWqtk rqXn|jS|jjj||}|S(s8Returns the current value of the given extension handle.N(R3RR6RRRBR,RORHRyRzR@RqRrR:RRuR(RR2Rs((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt __getitem__(s     cCst||jstS|jj}|jj}g|D]}|jr;|^q;}g|D]}|jr]|^q]}||kS(N(R+t __class__RYRRR.(RRt my_fieldst other_fieldsR'((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRIs""cCs ||k S(N((RR((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt__ne__VscCstddS(Nsunhashable object(R(R((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt__hash__YscCst|j||jtjks4|jtjkrJtd|jnt j |j|j }|j |||jj |<|jjdS(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(R3RRBR,RORyRzRR/RR{R>RR6R(RR2RRo((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt __setitem__`s cCs|jjj|dS(sTries to find a known extension with the specified name. Args: name: Extension full name. Returns: Extension field descriptor. N(RRRR(RRg((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt_FindExtensionByNameus ( RRRRRRR#R$R%R&(((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyRs  !   (CRt __author__t cStringIORt ImportErrorR%RRtgoogle.protobuf.internalRRRRRR}RRtgoogle.protobufRtdescriptor_modR RR tFieldDescriptorR,RR(R*R3R RDRR RRWRRR RRRRR!R"RRRRRRRRRRRRRRRRRRR#R$tobjectRR(((sK/usr/lib/python2.7/site-packages/google/protobuf/internal/python_message.pyt1sx           #   1 &   , ' 3  "           * R *  2