3
���hr � @ s� d Z dZyddlmZ W n ek
r8 ddlmZ Y nX ddlZddlZddlZddl Z ddl
Z
ddlZddlm
Z
ddlmZ ddlmZ dZeejjejjejjejjg�Zeejjejjg�Zeejjejjg�Zd Zd
ZdZe j e
j!d��Z"e j d
�Z#G dd� de$�Z%G dd� de%�Z&G dd� de%�Z'd=dd�Z(d>dd�Z)dd� Z*G dd� de+�Z,dd� Z-d d!� Z.d"d#� Z/d?d$d%�Z0d@d&d'�Z1e
j2e3f Z4G d(d)� d)e+�Z5dAd*d+�Z6d,d-� Z7d.d/� Z8d0d1� Z9d2d3gd4d5gd4d5gd6d7gd8d9gd4d5gd:d;gd<�Z:dS )Bat Contains 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 @ s e Zd ZdZdS )�Errorz'Top-level module error for json_format.N)�__name__�
__module__�__qualname__�__doc__� r r �!/usr/lib/python3.6/json_format.pyr P s r c @ s e Zd ZdZdS )�SerializeToJsonErrorz&Thrown if serialization to JSON fails.N)r r r r
r r r r r
T s r
c @ s e Zd ZdZdS )�
ParseErrorz Thrown in case of parsing error.N)r r r r
r r r r r X s r F� c C s t ||�}|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.
Returns:
A string containing the JSON formatted protocol buffer message.
)�_Printer�ToJsonString)�message�including_default_value_fields�preserving_proto_field_name�indent� sort_keys�printerr r r �
MessageToJson\ s r c C s t ||�}|j| �S )a� 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 �_MessageToJsonObject)r r r r r r r �
MessageToDictx s r c C s"