Q,Qc@sdZdZddlZddlZddlmZddlmZddlm Z ddd d d gZ ej ej ej ejfZejd ejZejd ejZdefdYZeedZdeedZdeedZdeedZdZdZdZdefdYZdZ ejdZ!dZ"eedZ#dZ$dZ%d Z&dS(!s@Contains routines for printing protocol messages in text format.s kenton@google.com (Kenton Varda)iN(tdeque(t type_checkers(t descriptortMessageToStringt PrintMessaget PrintFieldtPrintFieldValuetMerges-?inf(?:inity)?f?snanf?t ParseErrorcBseZdZRS(s&Thrown in case of ASCII parsing error.(t__name__t __module__t__doc__(((s?/usr/lib/python2.7/site-packages/google/protobuf/text_format.pyR6scCsOtj}t||d|d||j}|j|rK|jS|S(Ntas_utf8t as_one_line(t cStringIOtStringIORtgetvaluetclosetrstrip(tmessageR R touttresult((s?/usr/lib/python2.7/site-packages/google/protobuf/text_format.pyR:s    ic Cs|xu|jD]g\}}|jtjjkr[xC|D]}t||||||q5Wq t||||||q WdS(N(t ListFieldstlabelRtFieldDescriptortLABEL_REPEATEDR(RRtindentR R tfieldtvaluetelement((s?/usr/lib/python2.7/site-packages/google/protobuf/text_format.pyRDs   c CsK|jd||jr|jd|jjjr|jtjjkr|j |j kr|j tjj kr|j|j j n|j|j |jdn;|jtjjkr|j|j jn|j|j|jtjjkr |jdnt|||||||r:|jdn |jddS(scPrint a single field name/value pair. For repeated fields, the value should be a single element.t t[t]s: s N(twritet is_extensiontcontaining_typet GetOptionstmessage_set_wire_formatttypeRRt TYPE_MESSAGEt message_typetextension_scopeRtLABEL_OPTIONALt full_namet TYPE_GROUPtnametcpp_typetCPPTYPE_MESSAGER(RRRRR R ((s?/usr/lib/python2.7/site-packages/google/protobuf/text_format.pyRMs&  cCs|jtjjkr|rN|jdt||||||jdq|jdt|||d|||jd|dn,|jtjjkr|jjj |d }|d k r|j|j q|jt |n|jtjj krk|jdt|tkrE|jt|jd|n|jt|||jdnN|jtjjkr|r|jdq|jd n|jt |d S( snPrint a single field value (not including name). For repeated fields, the value should be a single element.s { t}s { iRs"sutf-8ttruetfalseN(R.RRR/R!Rt CPPTYPE_ENUMt enum_typetvalues_by_numbertgettNoneR-tstrtCPPTYPE_STRINGR&tunicodet_CEscapetencodet CPPTYPE_BOOL(RRRRR R t enum_value((s?/usr/lib/python2.7/site-packages/google/protobuf/text_format.pyRns0    "cCs0t|}x|js+t||qWdS(sMerges an ASCII representation of a protocol message into a message. Args: text: Message ASCII representation. message: A protocol buffer message to merge into. Raises: ParseError: On ASCII parsing problems. N(t _TokenizertAtEndt _MergeField(ttextRt tokenizer((s?/usr/lib/python2.7/site-packages/google/protobuf/text_format.pyRs cCs|j}|jdr|jg}x&|jdrO|j|jq*Wdj|}|js|jd|jn|jj |}|s|jd|n.||j kr|jd||jfn|j dn|j}|j j |d}|sV|j j |jd}|rV|jtjjkrVd}qVn|r|jtjjkr|jj|krd}n|s|jd|j|fn|jtjjkr|jd|jd rd }n|j d d }|jtjjkrM|jr2|j|j}qt||jj}n5|jrf|j|}nt||j}|jxU|j|s|jr|jd |nt||qWnt |||dS(sMerges a single protocol message field into a message. Args: tokenizer: A tokenizer to parse the field name and values. message: A protocol message to record the data. Raises: ParseError: In case of ASCII parsing problems. Rt.s+Message type "%s" does not have extensions.sExtension "%s" not registered.s1Extension "%s" does not extend message type "%s".R s*Message type "%s" has no field named "%s".t:tt{R0sExpected "%s".N(!t DESCRIPTORt TryConsumetConsumeIdentifiertappendtjoint is_extendabletParseErrorPreviousTokenR+t Extensionst_FindExtensionByNameR#tConsumetfields_by_nameR6R7tlowerR&RRR,R(R-R.R/RRR"taddtgetattrt SetInParentR@RAt_MergeScalarField(RCRtmessage_descriptorR-Rt end_tokent sub_message((s?/usr/lib/python2.7/site-packages/google/protobuf/text_format.pyRAsf            cCs<|jdd}|jtjjtjjtjjfkrL|j}no|jtjj tjj tjj fkr|j }n6|jtjj tjjfkr|j}n|jtjjtjjfkr|j}n|jtjjtjjfkr|j}n|jtjjkr9|j}n|jtjjkr]|j}n^|jtjjkr|j}n:|jtjjkr|j|}ntd|j|jtjj kr |j!r|j"|j#|q8t$||j%j#|n,|j!r%||j"|X|jj|d}|dkrtd|j|fn|jS(s&Parse an enum value. The value can be specified by a number (the enum value), or by a string literal (the enum name). Args: field: Enum field descriptor. value: String value. Returns: Enum value number. Raises: ValueError: If the enum value could not be parsed. is%Enum type "%s" has no value named %s.s+Enum type "%s" has no value with number %d.N( R4RRtvalues_by_nameR6R7R+R5tnumber(RRtenum_descriptorRR>((s?/usr/lib/python2.7/site-packages/google/protobuf/text_format.pyRs    ('R t __author__RRt collectionsRtgoogle.protobuf.internalRtgoogle.protobufRt__all__tUint32ValueCheckertInt32ValueCheckertUint64ValueCheckertInt64ValueCheckerRRt IGNORECASERRt ExceptionRRRRRRRRARXtobjectR?R;RRRRRR(((s?/usr/lib/python2.7/site-packages/google/protobuf/text_format.pyts@         !#  P 7+