HEX
Server: LiteSpeed
System: Linux in-mum-web921.main-hosting.eu 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: u590867752 (590867752)
PHP: 8.2.33
Disabled: NONE
Upload Files
File: //proc/self/root/lib/python3.6/site-packages/google/protobuf/__pycache__/json_format.cpython-36.pyc
3

8��e�t�@s�dZdZyddlmZWn ek
r8ddlmZYnXddlZddlZddlZddl	m
Z
ddlZddlZddl
Z
ddlmZddlmZdZeejjejjejjejjg�Zeejjejjg�Zeejjejjg�Zd	Zd
ZdZej e
j!d��Z"ej d
�Z#Gdd�de$�Z%Gdd�de%�Z&Gdd�de%�Z'd=dd�Z(d>dd�Z)dd�Z*Gdd�de+�Z,dd�Z-d d!�Z.d"d#�Z/d?d$d%�Z0d@d&d'�Z1e
j2e3fZ4Gd(d)�d)e+�Z5dAd*d+�Z6d,d-�Z7d.d/�Z8d0d1�Z9d2d3gd4d5gd4d5gd6d7gd8d9gd4d5gd:d;gd<�Z:dS)BatContains 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())
zjieluo@google.com (Jie Luo)�)�OrderedDictN)�methodcaller)�
descriptor)�symbol_databasez%Y-%m-%dT%H:%M:%SZInfinityz	-InfinityZNaNzF[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]z\[[a-zA-Z0-9\._]*\]$c@seZdZdZdS)�Errorz'Top-level module error for json_format.N)�__name__�
__module__�__qualname__�__doc__�rr�!/usr/lib/python3.6/json_format.pyrWsrc@seZdZdZdS)�SerializeToJsonErrorz&Thrown if serialization to JSON fails.N)rrr	r
rrrrr
[sr
c@seZdZdZdS)�
ParseErrorz Thrown in case of parsing error.N)rrr	r
rrrrr_srF�cCst|||�}|j|||�S)a�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.
    use_integers_for_enums: If true, print integers instead of enum names.

  Returns:
    A string containing the JSON formatted protocol buffer message.
  )�_Printer�ToJsonString)�message�including_default_value_fields�preserving_proto_field_name�indent�	sort_keys�use_integers_for_enums�printerrrr�
MessageToJsoncsrcCst|||�}|j|�S)aConverts 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.
    use_integers_for_enums: If true, print integers instead of enum names.

  Returns:
    A dict representation of the protocol buffer message.
  )r�_MessageToJsonObject)rrrrrrrr�
MessageToDict�srcCs"|jtjjko |jjo |jj�jS)N)�typer�FieldDescriptor�TYPE_MESSAGE�message_typeZhas_options�
GetOptionsZ	map_entry)�fieldrrr�_IsMapEntry�sr"c@sjeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)rz)JSON format printer for protocol message.FcCs||_||_||_dS)N)rrr)�selfrrrrrr�__init__�sz_Printer.__init__cCs|j|�}tj|||d�S)N)rr)r�json�dumps)r#rrr�jsrrrr�s
z_Printer.ToJsonStringcCsL|j}|j}t|�r|j|�S|tkr<tt|d|�|�Si}|j||�S)zEConverts message to an object according to Proto3 JSON Specification.r)�
DESCRIPTOR�	full_name�_IsWrapperMessage�_WrapperMessageToJsonObject�_WKTJSONMETHODSr�_RegularMessageToJsonObject)r#r�message_descriptorr)r'rrrr�s
z_Printer._MessageToJsonObjectc
s|j�}�yҐx|D�]\�}�jr,�j}n�j}t��r��jjd}i}x>|D]6}t|t�rn|rhd}	qrd}	n|}	�j	|||�||	<qPW|||<q�j
tjj
kr���fdd�|D�||<q�j�r�}
|
jj�jr�|
jtjjkr�|
j
tjjkr�|
j}
d|
j|f}�j	�|�||<q�j	�|�||<qW�j�r�|j}x�|jD]���j
tjj
k�rd�jtjjk�s@�j�rp�q@�j�r��j}n�j}||k�r��q@t���r�i||<n,�j
tjj
k�r�g||<n�j	��j�||<�q@WWn6tk
�r}ztdj�j|���WYdd}~XnX|S)	z?Converts normal message according to Proto3 JSON Specification.�value�true�falsecsg|]}�j�|��qSr)�_FieldToJsonObject)�.0�k)r!r#rr�
<listcomp>�sz8_Printer._RegularMessageToJsonObject.<locals>.<listcomp>z[%s.%s]z#Failed to serialize {0} field: {1}.N) �
ListFieldsr�name�	json_namer"r�fields_by_name�
isinstance�boolr2�labelrr�LABEL_REPEATED�is_extensionZcontaining_typer Zmessage_set_wire_formatrrZLABEL_OPTIONALr)rr(�fields�cpp_type�CPPTYPE_MESSAGE�containing_oneofZ
default_value�
ValueErrorr
�format)
r#rr'r?r/r7Zv_fieldZjs_map�keyZrecorded_key�fr.�er)r!r#rr-�sf






"z$_Printer._RegularMessageToJsonObjectcCs�|jtjjkr|j|�S|jtjjkrh|jr0|S|jjj	|d�}|dk	rN|j
S|jjdkr^|St
d��n�|jtjjkr�|jtjjkr�tj|�jd�S|Sn^|jtjjkr�t|�S|jtkr�t|�S|jtk�r�tj|�r�|dkr�tStStj|��r�tS|S)z<Converts field value according to Proto3 JSON Specification.N�proto3zKEnum field contains an integer value which can not mapped to an enum value.zutf-8g)r@rrrAr�CPPTYPE_ENUMr�	enum_type�values_by_number�getr7�file�syntaxr
�CPPTYPE_STRINGr�
TYPE_BYTES�base64Z	b64encode�decode�CPPTYPE_BOOLr;�_INT64_TYPES�str�_FLOAT_TYPES�mathZisinf�
_NEG_INFINITY�	_INFINITYZisnan�_NAN)r#r!r/�
enum_valuerrrr2s6



z_Printer._FieldToJsonObjectcCs�|j�siSt�}|j}||d<t|�}|j|j�|j}|j}t|�rZ|j	|�|d<|S|t
kr�tt
|d|�|�|d<|S|j||�S)z<Converts Any message according to Proto3 JSON Specification.z@typer/r)
r6r�type_url�_CreateMessageFromTypeUrlZParseFromStringr/r(r)r*r+r,rr-)r#rr'r\�sub_messager.r)rrr�_AnyMessageToJsonObject's"z _Printer._AnyMessageToJsonObjectcCs|j�S)z8Converts message according to Proto3 JSON Specification.)r)r#rrrr�_GenericMessageToJsonObject<sz$_Printer._GenericMessageToJsonObjectcCsd|jd�}|dks|dkrdS|dkr2|j|j�S|dkrB|j}n
t||�}|jj|}|j||�S)z>Converts Value message according to Proto3 JSON Specification.ZkindN�
null_value�
list_value�struct_value)Z
WhichOneof�_ListValueMessageToJsonObjectrbrc�getattrr(r9r2)r#rZwhichr/Zoneof_descriptorrrr�_ValueMessageToJsonObjectBs

z"_Printer._ValueMessageToJsonObjectcs�fdd�|jD�S)zBConverts ListValue message according to Proto3 JSON Specification.csg|]}�j|��qSr)rf)r3r/)r#rrr5Tsz:_Printer._ListValueMessageToJsonObject.<locals>.<listcomp>)�values)r#rr)r#rrdRs
z&_Printer._ListValueMessageToJsonObjectcCs.|j}i}x|D]}|j||�||<qW|S)z?Converts Struct message according to Proto3 JSON Specification.)r?rf)r#rr?�retrErrr�_StructMessageToJsonObjectWs

z#_Printer._StructMessageToJsonObjectcCs|j|jjd|j�S)Nr/)r2r(r9r/)r#rrrrr+_sz$_Printer._WrapperMessageToJsonObjectN)FFF)rrr	r
r$rrr-r2r_r`rfrdrir+rrrrr�s
E#rcCs|jjdkS)Nzgoogle/protobuf/wrappers.proto)rMr7)r.rrrr*dsr*cCs8i}x.|D]&\}}||kr(tdj|���|||<q
W|S)Nz'Failed to load JSON: duplicate key {0}.)rrD)r'�resultr7r/rrr�_DuplicateCheckerhsrkcCsZtj�}|jd�d}y|jj|�}Wn"tk
rHtdj|���YnX|j|�}|�S)N�/�z1Can not find message descriptor by type_url: {0}.���)	rZDefault�splitZpoolZFindMessageTypeByName�KeyError�	TypeErrorrDZGetPrototype)r\ZdbZ	type_namer.Z
message_classrrrr]qs
r]cCs�t|tj�s|jd�}y(tjdkr.tj|�}ntj|td�}Wn4t	k
rr}zt
djt|����WYdd}~XnXt
|||�S)abParses 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.
  zutf-8r�)Zobject_pairs_hookzFailed to load JSON: {0}.N)rrr)r:�six�	text_typerR�sys�version_infor%�loadsrkrCrrDrU�	ParseDict)�textr�ignore_unknown_fieldsr'rGrrr�Parses

$r{cCst|�}|j||�|S)a.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.
  )�_Parser�ConvertMessage)Zjs_dictrrz�parserrrrrx�srxc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)r|z(JSON format parser for protocol message.cCs
||_dS)N)rz)r#rzrrrr$�sz_Parser.__init__cCsT|j}|j}t|�r"|j||�n.|tkrDtt|d||�|�n|j||�dS)z�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.
    rmN)r(r)r*�_ConvertWrapperMessager,r�_ConvertFieldValuePair)r#r/rr.r)rrrr}�s
z_Parser.ConvertMessagecCs�g}|j}tdd�|jD��}�xl|D�]b}�y�|j|d�}|sN|jj|d�}|r�tj|�r�|jsttdj	|j
���|dd�}dj|jd�dd��}|j
j|�}|s�|jr�w&tdj	|j
||j���||kr�tdj	|jj
|���|j|�|jdk	�r(|jj}	|	|k�rtd	j	|jj
|	���|j|	�||}
|
dk�rz|jtjjk�rl|jj
d
k�rlt||j�}d|_n|j|j�w&t|��r�|j|j�|j|
||��n,|jtjjk�rt|j|j�t|
t ��s�tdj	||
���|jtjjk�r8x�|
D]B}t||j�j!�}|dk�r$|jj
d
k�r$td
��|j"||��q�Wn:x�|
D]0}|dk�rTtd
��t||j�jt#||���q>WnZ|jtjjk�r�|j$�r�|j
|}nt||j�}|j%�|j"|
|�nt&||jt#|
|��Wq&tk
�r$}
z6|�r|jdk�rtdj	||
���ntt'|
���WYdd}
~
Xq&t(k
�rV}
ztdj	||
���WYdd}
~
Xq&t)k
�r�}
ztdj	||
���WYdd}
~
Xq&Xq&WdS)z�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)r8)r3rFrrr�	<genexpr>�sz1_Parser._ConvertFieldValuePair.<locals>.<genexpr>Nz)Message type {0} does not have extensionsrm�.zVMessage type "{0}" has no field named "{1}".
 Available Fields(except extensions): {2}z9Message type "{0}" should not have multiple "{1}" fields.z?Message type "{0}" should not have multiple "{1}" oneof fields.zgoogle.protobuf.Valuerz.repeated field {0} must be in [] which is {1}.zAnull is not allowed to be used as an element in a repeated field.zFailed to parse {0} field: {1}zFailed to parse {0} field: {1}.rnrn)*r(�dictr?rLr9�_VALID_EXTENSION_NAME�matchZ
is_extendablerrDr)�joinroZ
ExtensionsZ_FindExtensionByNamerz�appendrBr7r@rrrArrera�
ClearFieldr"�_ConvertMapFieldValuer<r=r:�list�addr}�_ConvertScalarFieldValuer>ZSetInParent�setattrrUrCrq)r#r'r�namesr.Zfields_by_json_namer7r!Z
identifierZ
oneof_namer/r^�itemrGrrrr��s�












 z_Parser._ConvertFieldValuePaircCs�t|t�r|rdSy|d}Wntk
r<td��YnXt|�}|j}|j}t|�rl|j|d|�n8|t	kr�t
t	|d|d|�|�n|d=|j||�|j�|_
||_dS)z/Convert a JSON representation into Any message.Nz@typez*@type is missing when parsing any message.r/rm)r:r�rprr]r(r)r*rr,rr�ZSerializeToStringr/r\)r#r/rr\r^r.r)rrr�_ConvertAnyMessage0s$
z_Parser._ConvertAnyMessagecCs|j|�dS)z?Convert a JSON representation into message with FromJsonString.N)ZFromJsonString)r#r/rrrr�_ConvertGenericMessageHsz_Parser._ConvertGenericMessagecCs�t|t�r|j||j�njt|t�r4|j||j�nP|dkrDd|_n@t|t�rV||_	n.t|t
j�rj||_nt|t
�r|||_ntd��dS)z1Convert a JSON representation into Value message.Nrz"Unexpected type for Value message.)r:r��_ConvertStructMessagercr��_ConvertListValueMessagerbrar;Z
bool_valuersZstring_typesZstring_value�
_INT_OR_FLOATZnumber_valuer)r#r/rrrr�_ConvertValueMessageNs



z_Parser._ConvertValueMessagecCsFt|t�stdj|���|jd�x|D]}|j||jj��q(WdS)z5Convert a JSON representation into ListValue message.z%ListValue must be in [] which is {0}.rgN)r:r�rrDr�r�rgr�)r#r/rr�rrrr�_s


z _Parser._ConvertListValueMessagecCs@t|t�stdj|���x"|D]}|j|||j|�qWdS)z2Convert a JSON representation into Struct message.z&Struct must be in a dict which is {0}.N)r:r�rrDr�r?)r#r/rrErrrr�hs

z_Parser._ConvertStructMessagecCs"|jjd}t|dt||��dS)z3Convert a JSON representation into Wrapper message.r/N)r(r9r�r�)r#r/rr!rrrrqsz_Parser._ConvertWrapperMessagecCs�t|t�stdj|j|���|jjd}|jjd}x^|D]V}t||d�}|jt	j
jkrv|j||t
||j�|�q:t|||�t
||j�|<q:WdS)a5Convert 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.
    z-Map field {0} must be in a dict which is {1}.rEr/TN)r:r�rrDr7rr9r�r@rrrAr}re)r#r/rr!Z	key_fieldZvalue_fieldrE�	key_valuerrrr�vs

z_Parser._ConvertMapFieldValueN)rrr	r
r$r}r�r�r�r�r�r�rr�rrrrr|�sj		r|cCs$|jtkrt|�S|jtkr$t|�S|jtjjkr<t||�S|jtjj	krz|j
tjjkrbtj
|�Stj|�rttd��|Sn�|jtjjk�r |jjj|d�}|dk�ryt|�}|jjj|d�}Wn(tk
r�tdj||jj���YnX|dk�r|jjdk�r|Stdj||jj���|jSdS)aBConvert 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.
  zUnpaired surrogateNz)Invalid enum value {0} for enum type {1}.rH)r@�
_INT_TYPES�_ConvertIntegerrV�
_ConvertFloatrrrS�_ConvertBoolrOrrPrQZ	b64decode�_UNPAIRED_SURROGATE_PATTERN�searchrrIrJZvalues_by_namerL�intrKrCrDr)rMrN�number)r/r!�require_strr[r�rrrr��s6






r�cCsRt|t�r"|j�r"tdj|���t|tj�rJ|jd�dkrJtdj|���t|�S)z�Convert an integer.

  Args:
    value: A scalar value to convert.

  Returns:
    The integer value.

  Raises:
    ParseError: If an integer couldn't be consumed.
  zCouldn't parse integer: {0}.� rmzCouldn't parse integer: "{0}".rn)	r:�float�
is_integerrrDrsrt�findr�)r/rrrr��s
r�cCsp|dkrtd��yt|�Stk
rj|tkr8td�S|tkrHtd�S|tkrXtd�Stdj|���YnXdS)z!Convert an floating point number.�nanz.Couldn't parse float "nan", use "NaN" instead.z-inf�infzCouldn't parse float: {0}.N)rr�rCrXrYrZrD)r/rrrr��sr�cCs@|r*|dkrdS|dkrdStdj|���t|t�s<td��|S)z�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.
  r0Tr1Fz$Expected "true" or "false", not {0}.z&Expected true or false without quotes.)rrDr:r;)r/r�rrrr��s

r�r_r�r`r�rdr�rir�rfr�)zgoogle.protobuf.Anyzgoogle.protobuf.Durationzgoogle.protobuf.FieldMaskzgoogle.protobuf.ListValuezgoogle.protobuf.Structzgoogle.protobuf.Timestampzgoogle.protobuf.Value)FFrFF)FFF)F)F)F);r
�
__author__�collectionsr�ImportErrorZordereddictrQr%rW�operatorr�rerursZgoogle.protobufrrZ_TIMESTAMPFOMAT�	frozensetrZ
CPPTYPE_INT32ZCPPTYPE_UINT32Z
CPPTYPE_INT64ZCPPTYPE_UINT64r�rTZ
CPPTYPE_FLOATZCPPTYPE_DOUBLErVrYrXrZ�compile�ur�r��	Exceptionrr
rrrr"�objectrr*rkr]r{rxZ
integer_typesr�r�r|r�r�r�r�r,rrrr�<module>)s�


@	

f
0