
XXc        	   @   s  d  Z  d Z d d l Z d d l Z d d l Z e j rB e Z n  d d l m	 Z	 d d l
 m Z d d l
 m Z d d d	 d
 d g Z e	 j   e	 j   e	 j   e	 j   f Z e j d e j  Z e j d e j  Z e e j j e j j g  Z e d d f  Z d Z d e f d     YZ d e f d     YZ  d e! f d     YZ" e# e# e# e# e$ e# e$ d d  Z% d   Z& d e# e# e# e# e$ e# e$ d  Z' d e# e# e# e# e$ d  Z( d e# e# e# e# e$ d  Z) d   Z* d e! f d     YZ+ e# e# d   Z, e# e# e$ d!  Z- e# e# d"  Z. e# e# e$ d#  Z/ d$ e! f d%     YZ0 d&   Z1 d'   Z2 d(   Z3 d)   Z4 d* e! f d+     YZ5 e5 Z6 d,   Z7 d-   Z8 d.   Z9 d/   Z: d0   Z; d1   Z< e# e# d2  Z= e# e# d3  Z> e# e# d4  Z? e# d5  Z@ d6   ZA d7   ZB d8   ZC d S(9   sb  Contains routines for printing protocol messages in text format.

Simple usage example:

  # Create a proto object and serialize it to a text proto string.
  message = my_proto_pb2.MyMessage(foo='bar')
  text_proto = text_format.MessageToString(message)

  # Parse a text proto string.
  message = text_format.Parse(text_proto, my_proto_pb2.MyMessage())
s    kenton@google.com (Kenton Varda)iN(   t   type_checkers(   t
   descriptor(   t   text_encodingt   MessageToStringt   PrintMessaget
   PrintFieldt   PrintFieldValuet   Merges   -?inf(?:inity)?f?s   nanf?t   't   "s   google.protobuf.Anyt   Errorc           B   s   e  Z d  Z RS(   s'   Top-level module error for text_format.(   t   __name__t
   __module__t   __doc__(    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR
   I   s   t
   ParseErrorc           B   s2   e  Z d  Z d d d d  Z d   Z d   Z RS(   s3   Thrown in case of text parsing or tokenizing error.c         C   s   | d  k	 r[ | d  k	 r[ t |  } | d  k	 rF | d j |  7} n  d j | |  } n  | d  k	 r t t |   j |  n t t |   j   | |  _ | |  _ d  S(   Ns   :{0}s	   {0} : {1}(   t   Nonet   strt   formatt   superR   t   __init__t   _linet   _column(   t   selft   messaget   linet   columnt   loc(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   P   s    	c         C   s   |  j  S(   N(   R   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   GetLine]   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt	   GetColumn`   s    N(   R   R   R   R   R   R   R   (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   M   s   	t
   TextWriterc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s.   t  j r t j   |  _ n t j   |  _ d  S(   N(   t   sixt   PY2t   iot   BytesIOt   _writert   StringIO(   R   t   as_utf8(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   f   s    	c         C   s@   t  j r0 t | t  j  r0 | j d  } q0 n  |  j j |  S(   Ns   utf-8(   R   R   t
   isinstancet	   text_typet   encodeR"   t   write(   R   t   val(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR(   l   s    	c         C   s   |  j  j   S(   N(   R"   t   close(   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR*   r   s    c         C   s   |  j  j   S(   N(   R"   t   getvalue(   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR+   u   s    (   R   R   R   R(   R*   R+   (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   d   s   			i    c	      
   C   sg   t  |  }	 t |	 | | | | | | | | 	 }
 |
 j |   |	 j   } |	 j   | rc | j   S| S(   s  Convert protobuf message to text format.

  Floating point values can be formatted compactly with 15 digits of
  precision (which is the most that IEEE 754 "double" can guarantee)
  using float_format='.15g'. To ensure that converting to text and back to a
  proto will result in an identical value, float_format='.17g' should be used.

  Args:
    message: The protocol buffers message.
    as_utf8: Produce text output in UTF8 format.
    as_one_line: Don't introduce newlines between fields.
    pointy_brackets: If True, use angle brackets instead of curly braces for
      nesting.
    use_index_order: If True, print fields of a proto message using the order
      defined in source code instead of the field number. By default, use the
      field number order.
    float_format: If set, use this to specify floating point number formatting
      (per the "Format Specification Mini-Language"); otherwise, str() is used.
    use_field_number: If True, print field numbers instead of names.
    descriptor_pool: A DescriptorPool used to resolve Any types.
    indent: The indent level, in terms of spaces, for pretty print.

  Returns:
    A string of the text formatted protocol buffer message.
  (   R   t   _PrinterR   R+   R*   t   rstrip(   R   R$   t   as_one_linet   pointy_bracketst   use_index_ordert   float_formatt   use_field_numbert   descriptor_poolt   indentt   outt   printert   result(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   y   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/text_format.pyt   _IsMapEntry   s    c
      
   C   s5   t  | | | | | | | | |	 	 }
 |
 j |   d  S(   N(   R,   R   (   R   R5   R4   R$   R.   R/   R0   R1   R2   R3   R6   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR      s    
		c	   
      C   s2   t  | | | | | | |  }	 |	 j |  |  d S(   s%   Print a single field name/value pair.N(   R,   R   (
   R?   t   valueR5   R4   R$   R.   R/   R0   R1   R6   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR      s    
c	   
      C   s2   t  | | | | | | |  }	 |	 j |  |  d S(   s0   Print a single field value (not including name).N(   R,   R   (
   R?   RA   R5   R4   R$   R.   R/   R0   R1   R6   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR      s    
c         C   sZ   d d l  m } | j   } y | j |   } Wn t k
 rC d SX| j |  } |   S(   s!  Returns a protobuf message instance.

  Args:
    type_name: Fully-qualified protobuf  message type name string.
    descriptor_pool: DescriptorPool instance.

  Returns:
    A Message instance of type matching type_name, or None if the a Descriptor
    wasn't found matching type_name.
  i(   t   symbol_databaseN(   t   google.protobufRB   t   Defaultt   FindMessageTypeByNamet   KeyErrorR   t   GetPrototype(   t	   type_nameR3   RB   t   databaset   message_descriptorR;   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   _BuildMessageFromTypeName   s    R,   c        	   B   s\   e  Z d  Z d e e e e d e d d  Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s)   Text format printer for protocol message.i    c
   
      C   sU   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ d S(   st  Initialize the Printer.

    Floating point values can be formatted compactly with 15 digits of
    precision (which is the most that IEEE 754 "double" can guarantee)
    using float_format='.15g'. To ensure that converting to text and back to a
    proto will result in an identical value, float_format='.17g' should be used.

    Args:
      out: To record the text format result.
      indent: The indent level for pretty print.
      as_utf8: Produce text output in UTF8 format.
      as_one_line: Don't introduce newlines between fields.
      pointy_brackets: If True, use angle brackets instead of curly braces for
        nesting.
      use_index_order: If True, print fields of a proto message using the order
        defined in source code instead of the field number. By default, use the
        field number order.
      float_format: If set, use this to specify floating point number formatting
        (per the "Format Specification Mini-Language"); otherwise, str() is
        used.
      use_field_number: If True, print field numbers instead of names.
      descriptor_pool: A DescriptorPool used to resolve Any types.
    N(	   R5   R4   R$   R.   R/   R0   R1   R2   R3   (
   R   R5   R4   R$   R.   R/   R0   R1   R2   R3   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR      s    !								c         C   s   t  | j   |  j  } | r | j | j  |  j j d |  j d | j f  |  j	 |  |  j j |  j
 rw d n d  t St Sd S(   s5   Serializes if message is a google.protobuf.Any field.s   %s[%s]t    s   
N(   RK   t   TypeNameR3   t   MergeFromStringRA   R5   R(   R4   t   type_urlt   _PrintMessageFieldValueR.   t   Truet   False(   R   R   t   packed_message(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   _TryPrintAsAnyMessage  s    $c      
   C   s  | j  j t k r. |  j r. |  j |  r. d S| j   } |  j rY | j d d    n  x | D] \ } } t |  r x t	 |  D]5 } | j
   d | d | |  } |  j | |  q Wq` | j t j j k r x1 | D] } |  j | |  q Wq` |  j | |  q` Wd S(   se   Convert protobuf message to text format.

    Args:
      message: The protocol buffers message.
    Nt   keyc         S   s   |  d j  S(   Ni    (   t   index(   t   x(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   <lambda>7  s    RA   (   t
   DESCRIPTORt	   full_namet   _ANY_FULL_TYPE_NAMER3   RT   t
   ListFieldsR0   t   sortR@   t   sortedt   GetEntryClassR   t   labelR   R9   t   LABEL_REPEATED(   R   R   t   fieldsR?   RA   RU   t   entry_submsgt   element(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   ,  s    	c         C   sa  |  j  } | j d |  j  |  j r? | j t | j   n | j r | j d  | j j   j	 r | j
 t j j k r | j t j j k r | j | j j  n | j | j  | j d  n; | j
 t j j k r | j | j j  n | j | j  | j t j j k r'| j d  n  |  j | |  |  j rP| j d  n | j d  d S(   s%   Print a single field name/value pair.RL   t   [t   ]s   : s   
N(   R5   R(   R4   R2   R   t   numbert   is_extensiont   containing_typeR=   t   message_set_wire_formatR8   R   R9   R:   R`   t   LABEL_OPTIONALR;   RZ   t
   TYPE_GROUPt   namet   cpp_typet   CPPTYPE_MESSAGER   R.   (   R   R?   RA   R5   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   H  s*    				c         C   s   |  j  r d } d } n d } d } |  j ra |  j j d |  |  j |  |  j j |  nZ |  j j d |  |  j d 7_ |  j |  |  j d 8_ |  j j d |  j |  d  S(	   Nt   <t   >t   {t   }s    %s s    %s
i   RL   (   R/   R.   R5   R(   R   R4   (   R   RA   t   openbt   closeb(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyRP   i  s    			c         C   s  |  j  } | j t j j k r. |  j |  n| j t j j k r | j j j	 | d  } | d k	 rz | j | j  q| j t |   n'| j t j j k r,| j d  t | t j  r | j d  } n | } | j t j j k r t } n	 |  j } | j t j | |   | j d  n | j t j j k rg| rW| j d  q| j d  nP | j t k r|  j d k	 r| j d j |  j |   n | j t |   d S(   s   Print a single field value (not including name).

    For repeated fields, the value should be a single element.

    Args:
      field: The descriptor of the field to be printed.
      value: The value of the field.
    s   "s   utf-8t   truet   falses   {1:{0}}N(   R5   Rn   R   R9   Ro   RP   t   CPPTYPE_ENUMt	   enum_typet   values_by_numbert   getR   R(   Rm   R   t   CPPTYPE_STRINGR%   R   R&   R'   R8   t
   TYPE_BYTESRR   R$   R   t   CEscapet   CPPTYPE_BOOLt   _FLOAT_TYPESR1   R   (   R   R?   RA   R5   t
   enum_valuet	   out_valuet   out_as_utf8(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   |  s2    				N(   R   R   R   RR   R   R   RT   R   R   RP   R   (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR,      s   "			!	c         C   s=   t  |  t  s! |  j d  }  n  t |  j d  | | |  S(   s  Parses a text representation of a protocol message into a message.

  Args:
    text: Message text representation.
    message: A protocol buffer message to merge into.
    allow_unknown_extension: if True, skip over missing extensions and keep
      parsing
    allow_field_number: if True, both field number and field name are allowed.

  Returns:
    The same message passed as argument.

  Raises:
    ParseError: On text parsing problems.
  s   utf-8s   
(   R%   R   t   decodet
   ParseLinest   split(   t   textR   t   allow_unknown_extensiont   allow_field_number(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   Parse  s    c         C   s"   t  |  j d  | | | d | S(   s^  Parses a text representation of a protocol message into a message.

  Like Parse(), but allows repeated values for a non-repeated field, and uses
  the last one.

  Args:
    text: Message text representation.
    message: A protocol buffer message to merge into.
    allow_unknown_extension: if True, skip over missing extensions and keep
      parsing
    allow_field_number: if True, both field number and field name are allowed.
    descriptor_pool: A DescriptorPool used to resolve Any types.

  Returns:
    The same message passed as argument.

  Raises:
    ParseError: On text parsing problems.
  s   
R3   (   t
   MergeLinesR   (   R   R   R   R   R3   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    c         C   s   t  | |  } | j |  |  S(   s  Parses a text representation of a protocol message into a message.

  Args:
    lines: An iterable of lines of a message's text representation.
    message: A protocol buffer message to merge into.
    allow_unknown_extension: if True, skip over missing extensions and keep
      parsing
    allow_field_number: if True, both field number and field name are allowed.
    descriptor_pool: A DescriptorPool used to resolve Any types.

  Returns:
    The same message passed as argument.

  Raises:
    ParseError: On text parsing problems.
  (   t   _ParserR   (   t   linesR   R   R   t   parser(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    c         C   s%   t  | | d | } | j |  |  S(   s  Parses a text representation of a protocol message into a message.

  Args:
    lines: An iterable of lines of a message's text representation.
    message: A protocol buffer message to merge into.
    allow_unknown_extension: if True, skip over missing extensions and keep
      parsing
    allow_field_number: if True, both field number and field name are allowed.

  Returns:
    The same message passed as argument.

  Raises:
    ParseError: On text parsing problems.
  R3   (   R   R   (   R   R   R   R   R3   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    	R   c           B   sq   e  Z d  Z e e d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z RS(   s(   Text format parser for protocol message.c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   R   R3   (   R   R   R   R3   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    		c         C   s:   t  | t  s! | j d  } n  |  j | j d  |  S(   sB   Parses a text representation of a protocol message into a message.s   utf-8s   
(   R%   R   R   R   R   (   R   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   ParseFromString  s    c         C   s   t  |  _ |  j | |  | S(   sB   Parses a text representation of a protocol message into a message.(   RR   t   _allow_multiple_scalarst   _ParseOrMerge(   R   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   "  s    	c         C   s   |  j  | j d  |  S(   sB   Merges a text representation of a protocol message into a message.s   
(   t   _MergeLinesR   (   R   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyRN   (  s    c         C   s   t  |  _ |  j | |  | S(   sB   Merges a text representation of a protocol message into a message.(   RQ   R   R   (   R   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   ,  s    	c         C   s3   t  |  } x  | j   s. |  j | |  q Wd S(   s   Converts a text representation of a protocol message into a message.

    Args:
      lines: Lines of a message's text representation.
      message: A protocol buffer message to merge into.

    Raises:
      ParseError: On text parsing problems.
    N(   t	   Tokenizert   AtEndt   _MergeField(   R   R   R   t	   tokenizer(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   2  s    
c   	      C   s  | j  } t | d  r3 | j d k r3 t |  _ n  | j d  r)| j   g } x& | j d  ry | j | j    qT Wd j |  } | j	 s | j
 d | j   n  | j j |  } | s |  j r d } q| j
 d |   n. | | j k r| j
 d | | j f   n  | j d  n(| j   } |  j r| j   rt | t t  } | j j | d  } | r,| j	 r,| j j |  } q,n | j j | d  } | s| j j | j   d  } | r| j t j j k rd } qn  | r,| j t j j k r,| j j  | k r,d } n  | sQ| j
 d	 | j | f   n  | r|  j r| j! r| j" | j! j   } | d k	 r| | j  k r| j
 d
 | j  | | j! j  | j f   qn  | j# t j j$ k r| j d  |  j% } n | j d  |  j& } | j' t j j( k rs| j d  rsxM t ro| | | |  | j d  r_Pn  | j d  q6Wq| | | |  n |  j st)  t* |  | j d  s| j d  n  d S(   s   Merges 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 text parsing problems.
    t   syntaxt   proto3Re   t   .s+   Message type "%s" does not have extensions.s   Extension "%s" not registered.s1   Extension "%s" does not extend message type "%s".Rf   s*   Message type "%s" has no field named "%s".sb   Field "%s" is specified along with field "%s", another member of oneof "%s" for message type "%s".t   :t   ,t   ;N(+   RY   t   hasattrR   RQ   R   t
   TryConsumet   ConsumeIdentifiert   appendt   joint   is_extendablet   ParseErrorPreviousTokenRZ   t
   Extensionst   _FindExtensionByNameR   R   Ri   t   Consumet   ConsumeIdentifierOrNumberR   t   isdigitt   ParseIntegert   fields_by_numberR{   t   _FindExtensionByNumbert   fields_by_namet   lowerR8   R   R9   Rl   R;   Rm   t   containing_oneoft
   WhichOneofRn   Ro   t   _MergeMessageFieldt   _MergeScalarFieldR`   Ra   t   AssertionErrort   _SkipFieldContents(	   R   R   R   RJ   Rm   R?   Rg   t   which_oneoft   merger(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   @  s    
							
c         C   s   | j    | j d  | j    | j d  | j    | j d  | j    g } x& | j d  r| | j | j     qW Wd j |  S(   sB   Consumes a google.protobuf.Any type URL and returns the type name.R   t   /(   R   R   R   R   R   (   R   R   Rm   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   _ConsumeAnyTypeUrl  s    


c         C   s  t  |  } | j d  r$ d } n | j d  d } | j j t k r| j d  r|  j |  } | j d  | j d  | j d  r d } n | j d  d } |  j s t d   n  t	 | |  j  } | s t d	 |   n  xH | j |  s9| j
   r&| j d
 | f   n  |  j | |  q W| j t j j k rjt | | j  j   }	 n t | | j  }	 |	 j |  n | j t j j k r| j r| j | j   }
 q4| rt | | j  j     }
 q4t | | j  j   }
 n5 | j r| j | }
 n t | | j  }
 |
 j   xH | j |  s~| j
   rk| j d
 | f   n  |  j | |
  q7W| r| j j d j } | t j j k rt | | j  |
 j } | j |
 j  q|
 j t | | j  |
 j <n  d S(   s"  Merges a single scalar field into a message.

    Args:
      tokenizer: A tokenizer to parse the field value.
      message: The message of which field is a member.
      field: The descriptor of the field to be merged.

    Raises:
      ParseError: In case of text parsing problems.
    Rp   Rq   Rr   Rs   Re   Rf   R   s4   Descriptor pool required to parse expanded Any fields$   Type %s not found in descriptor pools   Expected "%s".RA   N(   R@   R   R   R;   RZ   R[   R   R3   R   RK   R   R   R   R`   R   R9   Ra   t   getattrRm   t   addt   PackRh   R   R_   t   SetInParentR   Rn   Ro   RU   t	   MergeFromRA   (   R   R   R   R?   t   is_map_entryt	   end_tokent   packed_type_namet   expanded_any_end_tokent   expanded_any_sub_messaget   any_messaget   sub_messaget   value_cpptypeRA   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     sd    						
c         C   s  |  j  } d } | j t j j t j j t j j f k rH t |  } no| j t j j	 t j j
 t j j f k r t |  } n6| j t j j t j j f k r t |  } n| j t j j t j j f k r t |  } n | j t j j t j j f k r| j   } n | j t j j k r5| j   } n | j t j j k rY| j   } n^ | j t j j k r}| j   } n: | j t j j k r| j |  } n t d | j   | j t j j  k r| j! r| j" | j# |  qt$ | | j%  j# |  n | j! r_|  j& rO| j' |  rO| j( d | j) j* | j* f   q| | j" | <nT |  j& r| j+ | j%  r| j( d | j) j* | j% f   n t, | | j% |  d S(   sH  Merges a single scalar field into a message.

    Args:
      tokenizer: A tokenizer to parse the field value.
      message: A protocol message to record the data.
      field: The descriptor of the field to be merged.

    Raises:
      ParseError: In case of text parsing problems.
      RuntimeError: On runtime errors.
    s   Unknown field type %ds;   Message type "%s" should not have multiple "%s" extensions.s7   Message type "%s" should not have multiple "%s" fields.N(-   R   R   R8   R   R9   t
   TYPE_INT32t   TYPE_SINT32t   TYPE_SFIXED32t   _ConsumeInt32t
   TYPE_INT64t   TYPE_SINT64t   TYPE_SFIXED64t   _ConsumeInt64t   TYPE_UINT32t   TYPE_FIXED32t   _ConsumeUint32t   TYPE_UINT64t   TYPE_FIXED64t   _ConsumeUint64t
   TYPE_FLOATt   TYPE_DOUBLEt   ConsumeFloatt	   TYPE_BOOLt   ConsumeBoolt   TYPE_STRINGt   ConsumeStringR}   t   ConsumeByteStringt	   TYPE_ENUMt   ConsumeEnumt   RuntimeErrorR`   Ra   Rh   R   R   R   Rm   R   t   HasExtensionR   RY   RZ   t   HasFieldt   setattr(   R   R   R   R?   t   _RA   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     sV    					N(   R   R   R   RR   R   R   R   R   RN   R   R   R   R   R   R   (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s   						n		Ic         C   sJ   |  j  d  r< |  j d  r< |  j d  r< t |   n
 t |   d S(   s}   Skips over contents (value or message) of a field.

  Args:
    tokenizer: A tokenizer to parse the field name and values.
  R   Rr   Rp   N(   R   t	   LookingAtt   _SkipFieldValuet   _SkipFieldMessage(   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   G  s    c         C   s   |  j  d  rI |  j   x |  j  d  r8 |  j   q W|  j d  n
 |  j   t |   |  j  d  s| |  j  d  n  d S(   s   Skips over a complete field (name and value/message).

  Args:
    tokenizer: A tokenizer to parse the field name and values.
  Re   R   Rf   R   R   N(   R   R   R   R   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt
   _SkipFieldZ  s    


c         C   sm   |  j  d  r d } n |  j d  d } x. |  j d  r[ |  j d  r[ t |   q. W|  j |  d S(   sf   Skips over a field message.

  Args:
    tokenizer: A tokenizer to parse the field name and values.
  Rp   Rq   Rr   Rs   N(   R   R   R   R   (   R   t	   delimiter(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   q  s    	#c         C   sq   |  j    r# x |  j    r q Wd S|  j   rm t |   rm t |   rm |  j   rm t d |  j   n  d S(   s   Skips over a field value.

  Args:
    tokenizer: A tokenizer to parse the field name and values.

  Raises:
    ParseError: In case an invalid field value is found.
  Ns   Invalid field value: (   t   TryConsumeByteStringt   TryConsumeIdentifiert   _TryConsumeInt64t   _TryConsumeUint64t   TryConsumeFloatR   t   token(   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    R   c           B   s  e  Z d  Z e j d  Z e j d e j  Z e j d e j  Z e j d j	 d d g g  e
 D] Z d j d e  ^ qa   Z e j d	  Z e j d
  Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   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   Protocol buffer text representation tokenizer.

  This class handles the lower level string parsing by splitting it into
  meaningful tokens.

  It was directly ported from the Java protocol buffer API.
  s   \s+s	   (\s*#.*$)s   (\s|(#.*$))+t   |s   [a-zA-Z_][0-9a-zA-Z_+-]*s#   ([0-9+-]|(\.[0-9]))[0-9a-zA-Z_.+-]*s!   {qt}([^{qt}\n\\]|\\.)*({qt}|\\?$)t   qts
   [^\d\W]\w*s   \w+c         C   s   d |  _  d |  _ d |  _ d  |  _ d |  _ t |  |  _ d |  _ d |  _	 d |  _
 t |  _ | |  _ | rx |  j p~ |  j |  _ |  j   |  j   d  S(   Ni    it    (   t	   _positionR   R   R   t   _token_startR   t   itert   _linest   _current_linet   _previous_linet   _previous_columnRQ   t   _more_linest   _skip_commentst   _WHITESPACE_OR_COMMENTt   _WHITESPACEt   _whitespace_patternt   _SkipWhitespacet	   NextToken(   R   R   t   skip_comments(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    										
c         C   s   |  j  | k S(   N(   R   (   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    c         C   s   |  j  S(   s^   Checks the end of the text was reached.

    Returns:
      True iff the end was reached.
    (   R   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    c         C   sx   xq t  |  j  |  j k rs y t |  j  |  _ Wn$ t k
 rW d |  _ t |  _ d  SX|  j d 7_ d |  _ q Wd  S(   NR   i   i    (	   t   lenR   R   t   nextR   t   StopIterationRR   R   R   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   _PopLine  s    		c         C   sd   x] t  r_ |  j   |  j j |  j |  j  } | s8 Pn  t | j d   } |  j | 7_ q Wd  S(   Ni    (   RQ   R  R   t   matchR   R   R   t   group(   R   R  t   length(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    	
c         C   s!   |  j  | k r |  j   t St S(   s   Tries to consume a given piece of text.

    Args:
      token: Text to consume.

    Returns:
      True iff the text was consumed.
    (   R   R   RQ   RR   (   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    	
c         C   s)   |  j  |  s% |  j d |   n  d S(   s   Consumes a piece of text.

    Args:
      token: Text to consume.

    Raises:
      ParseError: If the text couldn't be consumed.
    s   Expected "%s".N(   R   R   (   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    	c         C   s;   |  j  } |  j j |  s- |  j d   n  |  j   | S(   Ns   Expected comment.(   R   t   _COMMENTR  R   R   (   R   R7   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   ConsumeComment  s
    	
c         C   s+   y |  j    t SWn t k
 r& t SXd  S(   N(   R   RQ   R   RR   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s
    
c         C   s;   |  j  } |  j j |  s- |  j d   n  |  j   | S(   s   Consumes protocol message field identifier.

    Returns:
      Identifier string.

    Raises:
      ParseError: If an identifier couldn't be consumed.
    s   Expected identifier.(   R   t   _IDENTIFIERR  R   R   (   R   R7   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   	  s
    		
c         C   s+   y |  j    t SWn t k
 r& t SXd  S(   N(   R   RQ   R   RR   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   TryConsumeIdentifierOrNumber  s
    
c         C   s;   |  j  } |  j j |  s- |  j d   n  |  j   | S(   s   Consumes protocol message field identifier.

    Returns:
      Identifier string.

    Raises:
      ParseError: If an identifier couldn't be consumed.
    s   Expected identifier or number.(   R   t   _IDENTIFIER_OR_NUMBERR  R   R   (   R   R7   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s
    		
c         C   s+   y |  j    t SWn t k
 r& t SXd  S(   N(   t   ConsumeIntegerRQ   R   RR   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   TryConsumeInteger.  s
    
c         C   sR   y t  |  j d | } Wn( t k
 rC } |  j t |    n X|  j   | S(   s   Consumes an integer number.

    Args:
      is_long: True if the value should be returned as a long integer.
    Returns:
      The integer parsed.

    Raises:
      ParseError: If an integer couldn't be consumed.
    t   is_long(   t   _ParseAbstractIntegerR   t
   ValueErrorR   R   R   (   R   R  R7   t   e(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR  6  s    
c         C   s+   y |  j    t SWn t k
 r& t SXd  S(   N(   R   RQ   R   RR   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   H  s
    
c         C   sL   y t  |  j  } Wn( t k
 r= } |  j t |    n X|  j   | S(   s   Consumes an floating point number.

    Returns:
      The number parsed.

    Raises:
      ParseError: If a floating point number couldn't be consumed.
    (   t
   ParseFloatR   R  R   R   R   (   R   R7   R  (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   O  s    	
c         C   sL   y t  |  j  } Wn( t k
 r= } |  j t |    n X|  j   | S(   s   Consumes a boolean value.

    Returns:
      The bool parsed.

    Raises:
      ParseError: If a boolean value couldn't be consumed.
    (   t	   ParseBoolR   R  R   R   R   (   R   R7   R  (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   _  s    	
c         C   s+   y |  j    t SWn t k
 r& t SXd  S(   N(   R   RQ   R   RR   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   o  s
    
c         C   sI   |  j    } y t j | d  SWn" t k
 rD } |  j |   n Xd S(   s   Consumes a string value.

    Returns:
      The string parsed.

    Raises:
      ParseError: If a string value couldn't be consumed.
    s   utf-8N(   R   R   R&   t   UnicodeDecodeErrort   _StringParseError(   R   t	   the_bytesR  (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   v  s
    	c         C   sR   |  j    g } x3 |  j rD |  j d t k rD | j |  j     q Wd j |  S(   s   Consumes a byte array value.

    Returns:
      The array parsed (as a string).

    Raises:
      ParseError: If a byte array value couldn't be consumed.
    i    R   (   t   _ConsumeSingleByteStringR   t   _QUOTESR   R   (   R   t   the_list(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    	c         C   s   |  j  } t |  d k  s+ | d t k rD |  j d | f   n  t |  d k  sj | d | d k r |  j d | f   n  y t j | d d ! } Wn( t k
 r } |  j t |    n X|  j   | S(   sO  Consume one token of a string literal.

    String literals (whether bytes or text) can come in multiple adjacent
    tokens which are automatically concatenated, like in C or Python.  This
    method only consumes one token.

    Returns:
      The token parsed.
    Raises:
      ParseError: When the wrong format data is found.
    i   i    s   Expected string but found: %ri   is   String missing ending quote: %r(	   R   R   R  R   R   t	   CUnescapeR  R   R   (   R   R   R7   R  (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR    s    	"&
c         C   sO   y t  | |  j  } Wn( t k
 r@ } |  j t |    n X|  j   | S(   N(   t	   ParseEnumR   R  R   R   R   (   R   R?   R7   R  (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    
c         C   s   t  | |  j d |  j d  S(   s   Creates and *returns* a ParseError for the previously read token.

    Args:
      message: A message to set for the exception.

    Returns:
      A ParseError instance.
    i   (   R   R   R   (   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    	c         C   s   t  | |  j d |  j d  S(   s9   Creates and *returns* a ParseError for the current token.i   (   R   R   R   (   R   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    c         C   s   |  j  d t |   S(   Ns   Couldn't parse string: (   R   R   (   R   R  (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR    s    c         C   s   |  j  |  _ |  j |  _ |  j t |  j  7_ |  j   |  j sP d |  _ d S|  j j	 |  j
 |  j  } | r |  j r |  j j	 |  j
 |  j  } n  | r | j d  } | |  _ n |  j
 |  j |  _ d S(   s    Reads the next meaningful token.R   Ni    (   R   R   R   R   R   R   R   R   t   _TOKENR  R   R   R  R  (   R   R  R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    
		(,   R   R   R   t   ret   compileR   t	   MULTILINER  R   R   R  t   markR   R  R  R
  RQ   R   R   R   R  R   R   R   R  R   R   R	  R   R  RR   R  R   R   R   R   R   R   R  R   R   R   R  R   (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     sH   ,																								c         C   s   t  |  d t d t S(   s   Consumes a signed 32bit integer number from tokenizer.

  Args:
    tokenizer: A tokenizer used to parse the number.

  Returns:
    The integer parsed.

  Raises:
    ParseError: If a signed 32bit integer couldn't be consumed.
  t	   is_signedR  (   t   _ConsumeIntegerRQ   RR   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    c         C   s   t  |  d t d t S(   s   Consumes an unsigned 32bit integer number from tokenizer.

  Args:
    tokenizer: A tokenizer used to parse the number.

  Returns:
    The integer parsed.

  Raises:
    ParseError: If an unsigned 32bit integer couldn't be consumed.
  R   R  (   R!  RR   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    c         C   s+   y t  |   t SWn t k
 r& t SXd  S(   N(   R   RQ   R   RR   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR      s
    
c         C   s   t  |  d t d t S(   s   Consumes a signed 32bit integer number from tokenizer.

  Args:
    tokenizer: A tokenizer used to parse the number.

  Returns:
    The integer parsed.

  Raises:
    ParseError: If a signed 32bit integer couldn't be consumed.
  R   R  (   R!  RQ   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    c         C   s+   y t  |   t SWn t k
 r& t SXd  S(   N(   R   RQ   R   RR   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s
    
c         C   s   t  |  d t d t S(   s   Consumes an unsigned 64bit integer number from tokenizer.

  Args:
    tokenizer: A tokenizer used to parse the number.

  Returns:
    The integer parsed.

  Raises:
    ParseError: If an unsigned 64bit integer couldn't be consumed.
  R   R  (   R!  RR   RQ   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR     s    c         C   s7   y t  |  d | d | t SWn t k
 r2 t SXd  S(   NR   R  (   R!  RQ   R   RR   (   R   R   R  (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   _TryConsumeInteger.  s
    c         C   sX   y t  |  j d | d | } Wn( t k
 rI } |  j t |    n X|  j   | S(   sU  Consumes an integer number from tokenizer.

  Args:
    tokenizer: A tokenizer used to parse the number.
    is_signed: True if a signed integer must be parsed.
    is_long: True if a long integer must be parsed.

  Returns:
    The integer parsed.

  Raises:
    ParseError: If an integer with given characteristics couldn't be consumed.
  R   R  (   R   R   R  R   R   R   (   R   R   R  R7   R  (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR!  6  s    
c         C   sA   t  |  d | } t d t |  t |  } | j |  | S(   s  Parses an integer.

  Args:
    text: The text to parse.
    is_signed: True if a signed integer must be parsed.
    is_long: True if a long integer must be parsed.

  Returns:
    The integer value.

  Raises:
    ValueError: Thrown Iff the text is not a valid integer.
  R  i   (   R  t   _INTEGER_CHECKERSt   intt
   CheckValue(   R   R   R  R7   t   checker(    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR   L  s    c         C   sL   y$ | r t  |  d  St |  d  SWn! t k
 rG t d |    n Xd S(   s  Parses an integer without checking size/signedness.

  Args:
    text: The text to parse.
    is_long: True if the value should be returned as a long integer.

  Returns:
    The integer value.

  Raises:
    ValueError: Thrown Iff the text is not a valid integer.
  i    s   Couldn't parse integer: %sN(   t   longR$  R  (   R   R  (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR  c  s    c         C   s   y t  |   SWn t k
 r t j |   rT |  d d k rG t  d  St  d  Sq t j |   rm t  d  Sy t  |  j d   SWq t k
 r t d |    q Xn Xd S(	   s   Parse a floating point number.

  Args:
    text: Text to parse.

  Returns:
    The number parsed.

  Raises:
    ValueError: If a floating point number couldn't be parsed.
  i    t   -s   -inft   inft   nant   fs   Couldn't parse float: %sN(   t   floatR  t   _FLOAT_INFINITYR  t
   _FLOAT_NANR-   (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR  }  s    

c         C   s0   |  d k r t  S|  d k r  t St d	   d
 S(   s   Parse a boolean value.

  Args:
    text: Text to parse.

  Returns:
    Boolean values parsed

  Raises:
    ValueError: If text is not a valid boolean.
  Rv   t   tt   1RQ   Rw   R+  t   0RR   s   Expected "true" or "false".N(   s   trueR/  R0  s   True(   s   falseR+  R1  s   False(   RQ   RR   R  (   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR    s
    c         C   s   |  j  } y t | d  } WnN t k
 rl | j j | d  } | d k r t d | j | f   q n> X| j j | d  } | d k r t d | j | f   n  | j S(   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.
  i    s%   Enum type "%s" has no value named %s.s+   Enum type "%s" has no value with number %d.N(	   Ry   R$  R  t   values_by_nameR{   R   RZ   Rz   Rg   (   R?   RA   t   enum_descriptorRg   R   (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyR    s    	(D   R   t
   __author__R    R  R   t   PY3R$  R'  t   google.protobuf.internalR    RC   R   R   t   __all__t   Uint32ValueCheckert   Int32ValueCheckert   Uint64ValueCheckert   Int64ValueCheckerR#  R  t
   IGNORECASER-  R.  t	   frozensetR9   t   CPPTYPE_FLOATt   CPPTYPE_DOUBLER   R  R[   t	   ExceptionR
   R   t   objectR   RR   R   R   R@   R   R   R   RK   R,   R   R   R   R   R   R   R   R   R   R   t
   _TokenizerR   R   R   R   R   R   R"  R!  R   R  R  R  R  (    (    (    s=   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_format.pyt   <module>)   s   						&	

	 7				 F							 	