ó
X¾÷Xc           @   s¼  d  Z  d Z y d d l m Z Wn! e k
 rC d d l m Z n Xd d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l m Z d d l m Z d d l m Z d Z e e j j e j j e j j e j j g ƒ Z e e j j e j j g ƒ Z e e j j e j j g ƒ Z d	 Z d
 Z d Z e	 j  e
 j! d ƒ ƒ Z" d e# f d „  ƒ  YZ$ d e$ f d „  ƒ  YZ% d e$ f d „  ƒ  YZ& e' e' d „ Z( e' e' d „ Z) d „  Z* d e+ f d „  ƒ  YZ, d „  Z- d „  Z. d „  Z/ e' d „ Z0 e' d „ Z1 e
 j2 e3 f Z4 d e+ f d „  ƒ  YZ5 e' d „ Z6 d  „  Z7 d! „  Z8 d" „  Z9 i d# d$ g d% 6d& d' g d( 6d& d' g d) 6d* d+ g d, 6d- d. g d/ 6d& d' g d0 6d1 d2 g d3 6Z: d S(4   st  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())
s   jieluo@google.com (Jie Luo)iÿÿÿÿ(   t   OrderedDictN(   t   methodcaller(   t
   descriptor(   t   symbol_databases   %Y-%m-%dT%H:%M:%St   Infinitys	   -Infinityt   NaNsF   [\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]t   Errorc           B   s   e  Z d  Z RS(   s'   Top-level module error for json_format.(   t   __name__t
   __module__t   __doc__(    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR   M   s   t   SerializeToJsonErrorc           B   s   e  Z d  Z RS(   s&   Thrown if serialization to JSON fails.(   R   R   R	   (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR
   Q   s   t
   ParseErrorc           B   s   e  Z d  Z RS(   s    Thrown in case of parsing error.(   R   R   R	   (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR   U   s   c         C   s   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.

  Returns:
    A string containing the JSON formatted protocol buffer message.
  (   t   _Printert   ToJsonString(   t   messaget   including_default_value_fieldst   preserving_proto_field_namet   printer(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   MessageToJsonY   s    	c         C   s   t  | | ƒ } | j |  ƒ S(   s”  Converts protobuf message to a JSON dictionary.

  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 JSON formatted protocol buffer message.
  (   R   t   _MessageToJsonObject(   R   R   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   MessageToDictp   s    	c         C   s1   |  j  t j j k o0 |  j j o0 |  j j ƒ  j S(   N(   t   typeR   t   FieldDescriptort   TYPE_MESSAGEt   message_typet   has_optionst
   GetOptionst	   map_entry(   t   field(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   _IsMapEntryˆ   s    R   c           B   sw   e  Z d  Z e e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z RS(   s)   JSON format printer for protocol message.c         C   s   | |  _  | |  _ d  S(   N(   R   R   (   t   selfR   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   __init__‘   s    	c         C   s"   |  j  | ƒ } t j | d d ƒS(   Nt   indenti   (   R   t   jsont   dumps(   R   R   t   js(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR   —   s    c         C   sh   | j  } | j } t | ƒ r+ |  j | ƒ S| t k rR t t | d | ƒ |  ƒ Si  } |  j | | ƒ S(   sE   Converts message to an object according to Proto3 JSON Specification.i    (   t
   DESCRIPTORt	   full_namet   _IsWrapperMessaget   _WrapperMessageToJsonObjectt   _WKTJSONMETHODSR   t   _RegularMessageToJsonObject(   R   R   t   message_descriptorR%   R#   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR   ›   s    		c         C   s>  | j  ƒ  } yýx| D]\ } } |  j r7 | j } n	 | j } t | ƒ rÇ | j j d } i  } xU | D]M }	 t |	 t ƒ r– |	 r d }
 qœ d }
 n |	 }
 |  j	 | | |	 ƒ | |
 <qi W| | | <q | j
 t j j k rg  | D] } |  j	 | | ƒ ^ qã | | <q |  j	 | | ƒ | | <q W|  j r| j } xÑ | j D]Ã } | j
 t j j k rn| j t j j k s>| j r}q>n  |  j r’| j } n	 | j } | | k r­q>n  t | ƒ rÆi  | | <q>| j
 t j j k règ  | | <q>|  j	 | | j ƒ | | <q>Wn  Wn. t k
 r9} t d j | j | ƒ ƒ ‚ n X| S(   s?   Converts normal message according to Proto3 JSON Specification.t   valuet   truet   falses#   Failed to serialize {0} field: {1}.(   t
   ListFieldsR   t   namet	   json_nameR   R   t   fields_by_namet
   isinstancet   boolt   _FieldToJsonObjectt   labelR   R   t   LABEL_REPEATEDR   R$   t   fieldst   cpp_typet   CPPTYPE_MESSAGEt   containing_oneoft   default_valuet
   ValueErrorR
   t   format(   R   R   R#   R7   R   R+   R/   t   v_fieldt   js_mapt   keyt   recorded_keyt   kR*   t   e(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR)   ¦   sV    				)					$c         C   s?  | j  t j j k r" |  j | ƒ S| j  t j j k rq | j j j | d ƒ } | d k	 rb | j
 St d ƒ ‚ nÊ | j  t j j k r¸ | j t j j k r± t j | ƒ j d ƒ S| Snƒ | j  t j j k r× t | ƒ S| j  t k rð t | ƒ S| j  t k r;t j | ƒ r%| d k  rt St Sn  t j | ƒ r;t Sn  | S(   s<   Converts field value according to Proto3 JSON Specification.sK   Enum field contains an integer value which can not mapped to an enum value.s   utf-8g        N(   R8   R   R   R9   R   t   CPPTYPE_ENUMt	   enum_typet   values_by_numbert   gett   NoneR/   R
   t   CPPTYPE_STRINGR   t
   TYPE_BYTESt   base64t	   b64encodet   decodet   CPPTYPE_BOOLR3   t   _INT64_TYPESt   strt   _FLOAT_TYPESt   matht   isinft   _NEG_INFINITYt	   _INFINITYt   isnant   _NAN(   R   R   R+   t
   enum_value(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR4   ã   s.    

c         C   s¾   | j  ƒ  s i  St ƒ  } | j } | | d <t | ƒ } | j | j ƒ | j } | j } t | ƒ r} |  j	 | ƒ | d <| S| t
 k r® t t
 | d | ƒ |  ƒ | d <| S|  j | | ƒ S(   s<   Converts Any message according to Proto3 JSON Specification.s   @typeR+   i    (   R.   R    t   type_urlt   _CreateMessageFromTypeUrlt   ParseFromStringR+   R$   R%   R&   R'   R(   R   R)   (   R   R   R#   RY   t   sub_messageR*   R%   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   _AnyMessageToJsonObject  s"    		
		c         C   s
   | j  ƒ  S(   s8   Converts message according to Proto3 JSON Specification.(   R   (   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   _GenericMessageToJsonObject  s    c         C   sŽ   | j  d ƒ } | d k s' | d k r+ d S| d k rG |  j | j ƒ S| d k r_ | j } n t | | ƒ } | j j | } |  j | | ƒ S(   s>   Converts Value message according to Proto3 JSON Specification.t   kindt
   null_valuet
   list_valuet   struct_valueN(	   t
   WhichOneofRH   t   _ListValueMessageToJsonObjectRa   Rb   t   getattrR$   R1   R4   (   R   R   t   whichR+   t   oneof_descriptor(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   _ValueMessageToJsonObject  s    c         C   s#   g  | j  D] } |  j | ƒ ^ q
 S(   sB   Converts ListValue message according to Proto3 JSON Specification.(   t   valuesRh   (   R   R   R+   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyRd   -  s    c         C   s;   | j  } i  } x% | D] } |  j | | ƒ | | <q W| S(   s?   Converts Struct message according to Proto3 JSON Specification.(   R7   Rh   (   R   R   R7   t   retR@   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   _StructMessageToJsonObject2  s
    	c         C   s   |  j  | j j d | j ƒ S(   NR+   (   R4   R$   R1   R+   (   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR'   :  s    (   R   R   R	   t   FalseR   R   R   R)   R4   R]   R^   Rh   Rd   Rk   R'   (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR   Ž   s   			=						c         C   s   |  j  j d k S(   Ns   google/protobuf/wrappers.proto(   t   fileR/   (   R*   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR&   ?  s    c         C   sO   i  } xB |  D]: \ } } | | k r= t  d j | ƒ ƒ ‚ n  | | | <q W| S(   Ns'   Failed to load JSON: duplicate key {0}.(   R   R=   (   R#   t   resultR/   R+   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   _DuplicateCheckerC  s    c         C   st   t  j ƒ  } |  j d ƒ d } y | j j | ƒ } Wn& t k
 r] t d j |  ƒ ƒ ‚ n X| j | ƒ } | ƒ  S(   Nt   /iÿÿÿÿs1   Can not find message descriptor by type_url: {0}.(	   R   t   Defaultt   splitt   poolt   FindMessageTypeByNamet   KeyErrort	   TypeErrorR=   t   GetPrototype(   RY   t   dbt	   type_nameR*   t   message_class(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyRZ   L  s    c         C   sŸ   t  |  t j ƒ s$ |  j d ƒ }  n  y: t j d k  rH t j |  ƒ } n t j |  d t ƒ} Wn. t	 k
 rŽ } t
 d j t | ƒ ƒ ƒ ‚ n Xt | | | ƒ S(   sb  Parses 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.
  s   utf-8i   i   t   object_pairs_hooks   Failed to load JSON: {0}.(   i   i   (   R2   t   sixt	   text_typeRM   t   syst   version_infoR!   t   loadsRo   R<   R   R=   RP   t	   ParseDict(   t   textR   t   ignore_unknown_fieldsR#   RC   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   ParseZ  s     c         C   s    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   _Parsert   ConvertMessage(   t   js_dictR   Rƒ   t   parser(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR   t  s    R…   c           B   sh   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   s(   JSON format parser for protocol message.c         C   s   | |  _  d  S(   N(   Rƒ   (   R   Rƒ   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR   Š  s    c         C   sr   | j  } | j } t | ƒ r1 |  j | | ƒ n= | t k r^ t t | d | | ƒ |  ƒ n |  j | | ƒ d S(   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.
    i   N(   R$   R%   R&   t   _ConvertWrapperMessageR(   R   t   _ConvertFieldValuePair(   R   R+   R   R*   R%   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR†   Ž  s    
		!c         C   s  g  } | j  } t d „  | j Dƒ ƒ } xÔ| D]Ì} y| j | d ƒ } | sh | j j | d ƒ } n  | s› |  j r} w/ n  t d j | j	 | ƒ ƒ ‚ n  | | k rÈ t d j | j  j	 | ƒ ƒ ‚ n  | j
 | ƒ | j d k	 r-| j j } | | k rt d j | j  j	 | ƒ ƒ ‚ n  | j
 | ƒ n  | | }	 |	 d k rž| j t j j k rˆ| j j	 d k rˆt | | j ƒ }
 d |
 _ n | j | j ƒ w/ n  t | ƒ rÐ| j | j ƒ |  j |	 | | ƒ n~| j t j j k rî| j | j ƒ t |	 t ƒ st d j | |	 ƒ ƒ ‚ n  | j t j j k rx´ |	 D][ } t | | j ƒ j ƒ  }
 | d k r†|
 j  j	 d k r†t d ƒ ‚ n  |  j | |
 ƒ q;WqNx® |	 D]C } | d k rÅt d ƒ ‚ n  t | | j ƒ j
 t | | ƒ ƒ q¤Wn` | j t j j k r2t | | j ƒ }
 |
 j ƒ  |  j |	 |
 ƒ n t | | j t |	 | ƒ ƒ Wq/ t k
 r¦} | r‘| j d k r‘t d	 j | | ƒ ƒ ‚ qût t  | ƒ ƒ ‚ q/ t! k
 rÐ} t d
 j | | ƒ ƒ ‚ q/ t" k
 rú} t d
 j | | ƒ ƒ ‚ q/ Xq/ Wd S(   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.
    c         s   s   |  ] } | j  | f Vq d  S(   N(   R0   (   t   .0t   f(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pys	   <genexpr>­  s   s,   Message type "{0}" has no field named "{1}".s9   Message type "{0}" should not have multiple "{1}" fields.s?   Message type "{0}" should not have multiple "{1}" oneof fields.s   google.protobuf.Valuei    s.   repeated field {0} must be in [] which is {1}.sA   null is not allowed to be used as an element in a repeated field.s   Failed to parse {0} field: {1}s   Failed to parse {0} field: {1}.N(#   R$   t   dictR7   RG   RH   R1   Rƒ   R   R=   R%   t   appendR:   R/   R8   R   R   R9   R   Re   R`   t
   ClearFieldR   t   _ConvertMapFieldValueR5   R6   R2   t   listt   addR†   t   _ConvertScalarFieldValuet   SetInParentt   setattrRP   R<   Rv   (   R   R#   R   t   namesR*   t   fields_by_json_nameR/   R   t
   oneof_nameR+   R\   t   itemRC   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyRŠ   ¡  s„    
					
	
 c         C   sí   t  | t ƒ r | r d Sy | d } Wn t k
 rG t d ƒ ‚ n Xt | ƒ } | j } | j } t | ƒ r‰ |  j | d | ƒ nH | t	 k rº t
 t	 | d | d | ƒ |  ƒ n | d =|  j | | ƒ | j ƒ  | _ | | _ d S(   s/   Convert a JSON representation into Any message.Ns   @types*   @type is missing when parsing any message.R+   i   (   R2   R   Ru   R   RZ   R$   R%   R&   R‰   R(   R   RŠ   t   SerializeToStringR+   RY   (   R   R+   R   RY   R\   R*   R%   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   _ConvertAnyMessageý  s$    		"c         C   s   | j  | ƒ d S(   s?   Convert a JSON representation into message with FromJsonString.N(   t   FromJsonString(   R   R+   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   _ConvertGenericMessage  s    c         C   sÆ   t  | t ƒ r% |  j | | j ƒ n t  | t ƒ rJ |  j | | j ƒ nx | d k rb d | _ n` t  | t	 ƒ r} | | _
 nE t  | t j ƒ r› | | _ n' t  | t ƒ r¶ | | _ n t d ƒ ‚ d S(   s1   Convert a JSON representation into Value message.i    s"   Unexpected type for Value message.N(   R2   R   t   _ConvertStructMessageRb   R‘   t   _ConvertListValueMessageRa   RH   R`   R3   t
   bool_valueR|   t   string_typest   string_valuet   _INT_OR_FLOATt   number_valueR   (   R   R+   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   _ConvertValueMessage  s    c         C   sb   t  | t ƒ s' t d j | ƒ ƒ ‚ n  | j d ƒ x' | D] } |  j | | j j ƒ  ƒ q; Wd S(   s5   Convert a JSON representation into ListValue message.s%   ListValue must be in [] which is {0}.Ri   N(   R2   R‘   R   R=   R   R¥   Ri   R’   (   R   R+   R   R™   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyRŸ   ,  s    c         C   sW   t  | t ƒ s' t d j | ƒ ƒ ‚ n  x) | D]! } |  j | | | j | ƒ q. Wd S(   s2   Convert a JSON representation into Struct message.s&   Struct must be in a dict which is {0}.N(   R2   R   R   R=   R¥   R7   (   R   R+   R   R@   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyRž   5  s    c         C   s-   | j  j d } t | d t | | ƒ ƒ d S(   s3   Convert a JSON representation into Wrapper message.R+   N(   R$   R1   R•   R“   (   R   R+   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR‰   >  s    c         C   sÓ   t  | t ƒ s- t d j | j | ƒ ƒ ‚ n  | j j d } | j j d } x | D]w } t | | t ƒ } | j	 t
 j j k r¨ |  j | | t | | j ƒ | ƒ qT t | | | ƒ t | | j ƒ | <qT Wd S(   s5  Convert 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}.R@   R+   N(   R2   R   R   R=   R/   R   R1   R“   t   TrueR8   R   R   R9   R†   Re   (   R   R+   R   R   t	   key_fieldt   value_fieldR@   t	   key_value(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR   C  s    (   R   R   R	   R   R†   RŠ   R›   R   R¥   RŸ   Rž   R‰   R   (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR…   ‡  s   			\								c         C   s~  | j  t k r t |  ƒ S| j  t k r2 t |  ƒ S| j  t j j k rT t |  | ƒ S| j  t j j	 k r° | j
 t j j k r‹ t j |  ƒ St j |  ƒ r© t d ƒ ‚ n  |  SnÊ | j  t j j k rz| j j j |  d ƒ } | d k rsy( t |  ƒ } | j j j | d ƒ } Wn/ t k
 rBt d j |  | j j ƒ ƒ ‚ n X| d k rst d j |  | j j ƒ ƒ ‚ qsn  | j Sd S(   sB  Convert 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.
  s   Unpaired surrogates)   Invalid enum value {0} for enum type {1}.N(   R8   t
   _INT_TYPESt   _ConvertIntegerRQ   t   _ConvertFloatR   R   RN   t   _ConvertBoolRI   R   RJ   RK   t	   b64decodet   _UNPAIRED_SURROGATE_PATTERNt   searchR   RD   RE   t   values_by_nameRG   RH   t   intRF   R<   R=   R%   t   number(   R+   R   t   require_strRX   R³   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR“   ^  s2    

		c         C   s}   t  |  t ƒ r4 |  j ƒ  r4 t d j |  ƒ ƒ ‚ n  t  |  t j ƒ rs |  j d ƒ d k rs t d j |  ƒ ƒ ‚ n  t |  ƒ 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.
  s   Couldn't parse integer: {0}.t    iÿÿÿÿs   Couldn't parse integer: "{0}".(	   R2   t   floatt
   is_integerR   R=   R|   R}   t   findR²   (   R+   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR«   ‹  s
    'c         C   s˜   |  d k r t  d ƒ ‚ n  y t |  ƒ SWnh t k
 r“ |  t k rO t d ƒ S|  t k re t d ƒ S|  t k r{ t d ƒ St  d j |  ƒ ƒ ‚ n Xd S(   s!   Convert an floating point number.t   nans.   Couldn't parse float "nan", use "NaN" instead.s   -inft   infs   Couldn't parse float: {0}.N(   R   R¶   R<   RT   RU   RW   R=   (   R+   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR¬      s    


c         C   s`   | r> |  d k r t  S|  d k r& t St d j |  ƒ ƒ ‚ n  t |  t ƒ s\ t d ƒ ‚ 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¦   Rl   R   R=   R2   R3   (   R+   R´   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyR­   ³  s    R]   R›   s   google.protobuf.AnyR^   R   s   google.protobuf.Durations   google.protobuf.FieldMaskRd   RŸ   s   google.protobuf.ListValueRk   Rž   s   google.protobuf.Structs   google.protobuf.TimestampRh   R¥   s   google.protobuf.Value(;   R	   t
   __author__t   collectionsR    t   ImportErrort   ordereddictRK   R!   RR   t   reR|   R~   t   operatorR   t   google.protobufR   R   t   _TIMESTAMPFOMATt	   frozensetR   t   CPPTYPE_INT32t   CPPTYPE_UINT32t   CPPTYPE_INT64t   CPPTYPE_UINT64Rª   RO   t   CPPTYPE_FLOATt   CPPTYPE_DOUBLERQ   RU   RT   RW   t   compilet   uR¯   t	   ExceptionR   R
   R   Rl   R   R   R   t   objectR   R&   Ro   RZ   R„   R   t   integer_typesR¶   R£   R…   R“   R«   R¬   R­   R(   (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/json_format.pyt   <module>)   s~   			±				×-			





