Your IP : 3.142.36.215


Current Path : /usr/lib/python2.7/site-packages/google/protobuf/
Upload File :
Current File : //usr/lib/python2.7/site-packages/google/protobuf/json_format.pyc

�
Du�ac@s�dZdZyddlmZWn!ek
rCddlmZnXddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZdZeejjejjejjejjg�Zeejjejjg�Zeejjejjg�Zd	Zd
ZdZe	j e
j!d��Z"e	j d
�Z#de$fd��YZ%de%fd��YZ&de%fd��YZ'e(e(de(d�Z)e(e(d�Z*d�Z+de,fd��YZ-d�Z.d�Z/d�Z0e(d�Z1e(d�Z2e
j3e4fZ5de,fd ��YZ6e(d!�Z7d"�Z8d#�Z9d$�Z:id%d&gd'6d(d)gd*6d(d)gd+6d,d-gd.6d/d0gd16d(d)gd26d3d4gd56Z;dS(6stContains routines for printing protocol messages in JSON format.

Simple usage example:

  # Create a proto object and serialize it to a json format string.
  message = my_proto_pb2.MyMessage(foo='bar')
  json_string = json_format.MessageToJson(message)

  # Parse a json format string to proto object.
  message = json_format.Parse(json_string, my_proto_pb2.MyMessage())
sjieluo@google.com (Jie Luo)i����(tOrderedDictN(tmethodcaller(t
descriptor(tsymbol_databases%Y-%m-%dT%H:%M:%StInfinitys	-InfinitytNaNsF[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]s\[[a-zA-Z0-9\._]*\]$tErrorcBseZdZRS(s'Top-level module error for json_format.(t__name__t
__module__t__doc__(((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyRPstSerializeToJsonErrorcBseZdZRS(s&Thrown if serialization to JSON fails.(RRR	(((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR
Tst
ParseErrorcBseZdZRS(s Thrown in case of parsing error.(RRR	(((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyRXsicCs"t||�}|j|||�S(s_Converts protobuf message to JSON format.

  Args:
    message: The protocol buffers message instance to serialize.
    including_default_value_fields: If True, singular primitive fields,
        repeated fields, and map fields will always be serialized.  If
        False, only serialize non-empty fields.  Singular message fields
        and oneof fields are not affected by this option.
    preserving_proto_field_name: If True, use the original proto field
        names as defined in the .proto file. If False, convert the field
        names to lowerCamelCase.
    indent: The JSON object will be pretty-printed with this indent level.
        An indent level of 0 or negative will only insert newlines.
    sort_keys: If True, then the output will be sorted by field names.

  Returns:
    A string containing the JSON formatted protocol buffer message.
  (t_PrintertToJsonString(tmessagetincluding_default_value_fieldstpreserving_proto_field_nametindentt	sort_keystprinter((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt
MessageToJson\s	cCst||�}|j|�S(s�Converts protobuf message to a dictionary.

  When the dictionary is encoded to JSON, it conforms to proto3 JSON spec.

  Args:
    message: The protocol buffers message instance to serialize.
    including_default_value_fields: If True, singular primitive fields,
        repeated fields, and map fields will always be serialized.  If
        False, only serialize non-empty fields.  Singular message fields
        and oneof fields are not affected by this option.
    preserving_proto_field_name: If True, use the original proto field
        names as defined in the .proto file. If False, convert the field
        names to lowerCamelCase.

  Returns:
    A dict representation of the protocol buffer message.
  (Rt_MessageToJsonObject(RRRR((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt
MessageToDictxs	cCs1|jtjjko0|jjo0|jj�jS(N(ttypeRtFieldDescriptortTYPE_MESSAGEtmessage_typethas_optionst
GetOptionst	map_entry(tfield((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt_IsMapEntry�sRcBsweZdZeed�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�ZRS(s)JSON format printer for protocol message.cCs||_||_dS(N(RR(tselfRR((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt__init__�s	cCs(|j|�}tj|d|d|�S(NRR(Rtjsontdumps(R RRRtjs((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR
�scCsh|j}|j}t|�r+|j|�S|tkrRtt|d|�|�Si}|j||�S(sEConverts message to an object according to Proto3 JSON Specification.i(t
DESCRIPTORt	full_namet_IsWrapperMessaget_WrapperMessageToJsonObjectt_WKTJSONMETHODSRt_RegularMessageToJsonObject(R Rtmessage_descriptorR&R$((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR�s		
cCs�|j�}y�x�|D]�\}}|jr7|j}n	|j}t|�r�|jjd}i}xU|D]M}	t|	t�r�|	r�d}
q�d}
n|	}
|j	|||	�||
<qiW|||<q|j
tjj
krg|D]}|j	||�^q�||<q|jr�|}|jj�jr_|jtjjkr_|j
tjjkr_|j}nd|j|f}|j	||�||<q|j	||�||<qW|jr�|j}
x�|
jD]�}|j
tjj
kr�|jtjjks�|jrq�n|jr|j}n	|j}||kr0q�nt|�rIi||<q�|j
tjj
krkg||<q�|j	||j�||<q�WnWn.tk
r�}tdj|j|���nX|S(s?Converts normal message according to Proto3 JSON Specification.tvaluettruetfalses[%s.%s]s#Failed to serialize {0} field: {1}.( t
ListFieldsRtnamet	json_nameRRtfields_by_namet
isinstancetboolt_FieldToJsonObjecttlabelRRtLABEL_REPEATEDtis_extensiontcontaining_typeRtmessage_set_wire_formatRRtLABEL_OPTIONALR&RR%tfieldstcpp_typetCPPTYPE_MESSAGEtcontaining_oneoft
default_valuet
ValueErrorR
tformat(R RR$R<RR,R0tv_fieldtjs_maptkeytrecorded_keytktfR+te((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR*�sf		
		
)						

$cCsU|jtjjkr"|j|�S|jtjjkr�|jjj|d�}|dk	rb|j
S|jjdkrx|St
d��n�|jtjjkr�|jtjjkr�tj|�jd�S|Sn�|jtjjkr�t|�S|jtkrt|�S|jtkrQtj|�r;|dkr4tStSntj|�rQtSn|S(s<Converts field value according to Proto3 JSON Specification.tproto3sKEnum field contains an integer value which can not mapped to an enum value.sutf-8gN(R=RRR>RtCPPTYPE_ENUMt	enum_typetvalues_by_numbertgettNoneR0tfiletsyntaxR
tCPPTYPE_STRINGRt
TYPE_BYTEStbase64t	b64encodetdecodetCPPTYPE_BOOLR4t_INT64_TYPEStstrt_FLOAT_TYPEStmathtisinft
_NEG_INFINITYt	_INFINITYtisnant_NAN(R RR,t
enum_value((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR5�s2


cCs�|j�siSt�}|j}||d<t|�}|j|j�|j}|j}t|�r}|j	|�|d<|S|t
kr�tt
|d|�|�|d<|S|j||�S(s<Converts Any message according to Proto3 JSON Specification.s@typeR,i(
R/Rttype_urlt_CreateMessageFromTypeUrltParseFromStringR,R%R&R'R(R)RR*(R RR$Rbtsub_messageR+R&((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt_AnyMessageToJsonObjects"		
		cCs
|j�S(s8Converts message according to Proto3 JSON Specification.(R
(R R((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt_GenericMessageToJsonObject+scCs�|jd�}|dks'|dkr+dS|dkrG|j|j�S|dkr_|j}nt||�}|jj|}|j||�S(s>Converts Value message according to Proto3 JSON Specification.tkindt
null_valuet
list_valuetstruct_valueN(	t
WhichOneofROt_ListValueMessageToJsonObjectRjRktgetattrR%R2R5(R RtwhichR,toneof_descriptor((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt_ValueMessageToJsonObject1scCs#g|jD]}|j|�^q
S(sBConverts ListValue message according to Proto3 JSON Specification.(tvaluesRq(R RR,((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyRmAscCs;|j}i}x%|D]}|j||�||<qW|S(s?Converts Struct message according to Proto3 JSON Specification.(R<Rq(R RR<tretRE((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt_StructMessageToJsonObjectFs
	
cCs|j|jjd|j�S(NR,(R5R%R2R,(R R((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR(Ns(RRR	tFalseR!R
RR*R5RfRgRqRmRtR((((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR�s			E	!					cCs|jjdkS(Nsgoogle/protobuf/wrappers.proto(RPR0(R+((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR'SscCsOi}xB|D]:\}}||kr=tdj|���n|||<q
W|S(Ns'Failed to load JSON: duplicate key {0}.(RRB(R$tresultR0R,((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt_DuplicateCheckerWscCsttj�}|jd�d}y|jj|�}Wn&tk
r]tdj|���nX|j|�}|�S(Nt/i����s1Can not find message descriptor by type_url: {0}.(	RtDefaulttsplittpooltFindMessageTypeByNametKeyErrort	TypeErrorRBtGetPrototype(Rbtdbt	type_nameR+t
message_class((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyRc`s
cCs�t|tj�s$|jd�}ny:tjdkrHtj|�}ntj|dt�}Wn.t	k
r�}t
djt|����nXt
|||�S(sbParses a JSON representation of a protocol message into a message.

  Args:
    text: Message JSON representation.
    message: A protocol buffer message to merge into.
    ignore_unknown_fields: If True, do not raise errors for unknown fields.

  Returns:
    The same message passed as argument.

  Raises::
    ParseError: On JSON parsing problems.
  sutf-8iitobject_pairs_hooksFailed to load JSON: {0}.(ii(R3tsixt	text_typeRVtsystversion_infoR"tloadsRwRARRBRYt	ParseDict(ttextRtignore_unknown_fieldsR$RI((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pytParsenscCs t|�}|j||�|S(s.Parses a JSON dictionary representation into a message.

  Args:
    js_dict: Dict representation of a JSON message.
    message: A protocol buffer message to merge into.
    ignore_unknown_fields: If True, do not raise errors for unknown fields.

  Returns:
    The same message passed as argument.
  (t_ParsertConvertMessage(tjs_dictRR�tparser((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR��sR�cBsheZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�ZRS(s(JSON format parser for protocol message.cCs
||_dS(N(R�(R R�((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR!�scCsr|j}|j}t|�r1|j||�n=|tkr^tt|d||�|�n|j||�dS(s�Convert a JSON object into a message.

    Args:
      value: A JSON object.
      message: A WKT or regular protocol message to record the data.

    Raises:
      ParseError: In case of convert problems.
    iN(R%R&R't_ConvertWrapperMessageR)Rt_ConvertFieldValuePair(R R,RR+R&((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR��s
		!cCs�g}|j}td�|jD��}xk|D]c}y�|j|d�}|sh|jj|d�}n|r�tj|�r�|js�t	dj
|j���n|dd!}dj|j
d�d �}|jj|�}n|s|jr�w/nt	dj
|j||j���n||krFt	dj
|jj|���n|j|�|jdk	r�|jj}	|	|kr�t	dj
|jj|	���n|j|	�n||}
|
dkr|jtjjkr|jjd	krt||j�}d
|_n|j|j�w/nt|�rN|j|j�|j|
||�n�|jtjjkrl|j|j�t |
t!�s�t	dj
||
���n|jtjjkrx�|
D][}t||j�j"�}|dkr|jjd	krt	d��n|j#||�q�Wq�x�|
D]C}|dkrCt	d��nt||j�jt$||��q"Wny|jtjjkr�|j%r�|j|}nt||j�}|j&�|j#|
|�nt'||jt$|
|��Wq/t	k
r=}
|r(|jdkr(t	d
j
||
���q�t	t(|
���q/t)k
rg}
t	dj
||
���q/t*k
r�}
t	dj
||
���q/Xq/WdS(s�Convert field value pairs into regular message.

    Args:
      js: A JSON object to convert the field value pairs.
      message: A regular protocol message to record the data.

    Raises:
      ParseError: In case of problems converting.
    css|]}|j|fVqdS(N(R1(t.0RH((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pys	<genexpr>�ss)Message type {0} does not have extensionsii����t.sVMessage type "{0}" has no field named "{1}".
 Available Fields(except extensions): {2}s9Message type "{0}" should not have multiple "{1}" fields.s?Message type "{0}" should not have multiple "{1}" oneof fields.sgoogle.protobuf.Valueis.repeated field {0} must be in [] which is {1}.sAnull is not allowed to be used as an element in a repeated field.sFailed to parse {0} field: {1}sFailed to parse {0} field: {1}.N(+R%tdictR<RNROR2t_VALID_EXTENSION_NAMEtmatcht
is_extendableRRBR&tjoinRzt
Extensionst_FindExtensionByNameR�tappendR?R0R=RRR>RRnRit
ClearFieldRt_ConvertMapFieldValueR6R7R3tlisttaddR�t_ConvertScalarFieldValueR8tSetInParenttsetattrRYRAR~(R R$RtnamesR+tfields_by_json_nameR0Rt
identifiert
oneof_nameR,RetitemRI((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR��s�
		
		
			
	
	

	
 cCs�t|t�r|rdSy|d}Wntk
rGtd��nXt|�}|j}|j}t|�r�|j|d|�nH|t	kr�t
t	|d|d|�|�n|d=|j||�|j�|_
||_dS(s/Convert a JSON representation into Any message.Ns@types*@type is missing when parsing any message.R,i(R3R�R}RRcR%R&R'R�R)RR�tSerializeToStringR,Rb(R R,RRbReR+R&((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt_ConvertAnyMessages$
		"cCs|j|�dS(s?Convert a JSON representation into message with FromJsonString.N(tFromJsonString(R R,R((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt_ConvertGenericMessage7scCs�t|t�r%|j||j�n�t|t�rJ|j||j�nx|dkrbd|_n`t|t	�r}||_
nEt|tj�r�||_
n't|t�r�||_ntd��dS(s1Convert a JSON representation into Value message.is"Unexpected type for Value message.N(R3R�t_ConvertStructMessageRkR�t_ConvertListValueMessageRjRORiR4t
bool_valueR�tstring_typeststring_valuet
_INT_OR_FLOATtnumber_valueR(R R,R((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt_ConvertValueMessage=scCsbt|t�s'tdj|���n|jd�x'|D]}|j||jj��q;WdS(s5Convert a JSON representation into ListValue message.s%ListValue must be in [] which is {0}.RrN(R3R�RRBR�R�RrR�(R R,RR�((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR�Ns

cCsWt|t�s'tdj|���nx)|D]!}|j|||j|�q.WdS(s2Convert a JSON representation into Struct message.s&Struct must be in a dict which is {0}.N(R3R�RRBR�R<(R R,RRE((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR�Ws
cCs-|jjd}t|dt||��dS(s3Convert a JSON representation into Wrapper message.R,N(R%R2R�R�(R R,RR((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR�`scCs�t|t�s-tdj|j|���n|jjd}|jjd}x|D]w}t||t�}|j	t
jjkr�|j
||t||j�|�qTt|||�t||j�|<qTWdS(s5Convert map field value for a message map field.

    Args:
      value: A JSON object to convert the map field value.
      message: A protocol message to record the converted data.
      field: The descriptor of the map field to be converted.

    Raises:
      ParseError: In case of convert problems.
    s-Map field {0} must be in a dict which is {1}.RER,N(R3R�RRBR0RR2R�tTrueR=RRR>R�Rn(R R,RRt	key_fieldtvalue_fieldREt	key_value((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR�es
(
RRR	R!R�R�R�R�R�R�R�R�R�(((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR��s			j								cCs�|jtkrt|�S|jtkr2t|�S|jtjjkrTt||�S|jtjj	kr�|j
tjjkr�tj
|�Stj|�r�td��n|Sn�|jtjjkr�|jjj|d�}|dkr�y(t|�}|jjj|d�}Wn/tk
rBtdj||jj���nX|dkr�|jjdkre|Stdj||jj���q�n|jSdS(sBConvert a single scalar field value.

  Args:
    value: A scalar value to convert the scalar field value.
    field: The descriptor of the field to convert.
    require_str: If True, the field value must be a str.

  Returns:
    The converted scalar field value

  Raises:
    ParseError: In case of convert problems.
  sUnpaired surrogates)Invalid enum value {0} for enum type {1}.RJN(R=t
_INT_TYPESt_ConvertIntegerRZt
_ConvertFloatRRRWt_ConvertBoolRRRRSRTt	b64decodet_UNPAIRED_SURROGATE_PATTERNtsearchRRKRLtvalues_by_nameRNROtintRMRARBR&RPRQtnumber(R,Rtrequire_strRaR�((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR��s6




		cCs}t|t�r4|j�r4tdj|���nt|tj�rs|jd�dkrstdj|���nt|�S(s�Convert an integer.

  Args:
    value: A scalar value to convert.

  Returns:
    The integer value.

  Raises:
    ParseError: If an integer couldn't be consumed.
  sCouldn't parse integer: {0}.t i����sCouldn't parse integer: "{0}".(	R3tfloatt
is_integerRRBR�R�tfindR�(R,((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR��s
'cCs�|dkrtd��nyt|�SWnhtk
r�|tkrOtd�S|tkretd�S|tkr{td�Stdj|���nXdS(s!Convert an floating point number.tnans.Couldn't parse float "nan", use "NaN" instead.s-inftinfsCouldn't parse float: {0}.N(RR�RAR]R^R`RB(R,((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR��s



cCs`|r>|dkrtS|dkr&tStdj|���nt|t�s\td��n|S(s�Convert a boolean value.

  Args:
    value: A scalar value to convert.
    require_str: If True, value must be a str.

  Returns:
    The bool parsed.

  Raises:
    ParseError: If a boolean value couldn't be consumed.
  R-R.s$Expected "true" or "false", not {0}.s&Expected true or false without quotes.(R�RuRRBR3R4(R,R�((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyR��s
RfR�sgoogle.protobuf.AnyRgR�sgoogle.protobuf.Durationsgoogle.protobuf.FieldMaskRmR�sgoogle.protobuf.ListValueRtR�sgoogle.protobuf.Structsgoogle.protobuf.TimestampRqR�sgoogle.protobuf.Value(<R	t
__author__tcollectionsRtImportErrortordereddictRTR"R[treR�R�toperatorRtgoogle.protobufRRt_TIMESTAMPFOMATt	frozensetRt
CPPTYPE_INT32tCPPTYPE_UINT32t
CPPTYPE_INT64tCPPTYPE_UINT64R�RXt
CPPTYPE_FLOATtCPPTYPE_DOUBLERZR^R]R`tcompiletuR�R�t	ExceptionRR
RRuRRRtobjectRR'RwRcR�R�t
integer_typesR�R�R�R�R�R�R�R)(((s?/usr/lib/python2.7/site-packages/google/protobuf/json_format.pyt<module>)s�
			�				�0			







?>