<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
h              	   @   s  d Z dZddlZddlZddlZejr*eZ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dOZdZG dd deZG dd deZ G dd de!Z"dPddZ#dd Z$dQddZ%dRdd	Z&dSdd
Z'dd Z(G d d! d!e!Z)dTd"d#Z*dUd$dZ+dVd%d&Z,dWd'd(Z-G d)d* d*e!Z.d+d, Z/d-d. Z0d/d0 Z1d1d2 Z2G d3d4 d4e!Z3e3Z4d5d6 Z5d7d8 Z6d9d: Z7d;d< Z8d=d> Z9d?d@ Z:dXdAdBZ;dYdCdDZ<dZdEdFZ=d[dGdHZ>dIdJ Z?dKdL Z@dMdN ZAdS )\ab  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())
z kenton@google.com (Kenton Varda)    N)type_checkers)
descriptor)text_encodingMessageToStringPrintMessage
PrintFieldPrintFieldValueMergez-?inf(?:inity)?f?znanf?'"zgoogle.protobuf.Anyc               @   s   e Zd ZdZdS )Errorz'Top-level module error for text_format.N)__name__
__module____qualname____doc__ r   r   !/usr/lib/python3.6/text_format.pyr   I   s   r   c                   s2   e Zd ZdZd	 fdd	Zdd Zdd Z  ZS )

ParseErrorz3Thrown in case of text parsing or tokenizing error.Nc                sr   |d k	r:|d k	r:t |}|d k	r.|dj|7 }dj||}|d k	rTtt| j| ntt| j  || _|| _d S )Nz:{0}z	{0} : {1})strformatsuperr   __init___line_column)selfmessagelinecolumnloc)	__class__r   r   r   P   s    zParseError.__init__c             C   s   | j S )N)r   )r   r   r   r   GetLine]   s    zParseError.GetLinec             C   s   | j S )N)r   )r   r   r   r   	GetColumn`   s    zParseError.GetColumn)NNN)r   r   r   r   r   r    r!   __classcell__r   r   )r   r   r   M   s   r   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )

TextWriterc             C   s    t jrtj | _n
tj | _d S )N)sixPY2ioBytesIO_writerStringIO)r   as_utf8r   r   r   r   f   s    zTextWriter.__init__c             C   s(   t jrt|t jr|jd}| jj|S )Nzutf-8)r$   r%   
isinstance	text_typeencoder(   write)r   valr   r   r   r.   l   s    
zTextWriter.writec             C   s
   | j j S )N)r(   close)r   r   r   r   r0   r   s    zTextWriter.closec             C   s
   | j j S )N)r(   getvalue)r   r   r   r   r1   u   s    zTextWriter.getvalueN)r   r   r   r   r.   r0   r1   r   r   r   r   r#   d   s   r#   Fc
             C   sL   t |}
t|
|||||||||	
}|j|  |
j }|
j  |rH|j S |S )a  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.
    message_formatter: A function(message, indent, as_one_line): unicode|None
      to custom format selected sub-messages (usually based on message type).
      Use to pretty print parts of the protobuf for easier diffing.

  Returns:
    A string of the text formatted protocol buffer message.
  )r#   _Printerr   r1   r0   rstrip)r   r*   as_one_linepointy_bracketsuse_index_orderfloat_formatuse_field_numberdescriptor_poolindentmessage_formatteroutprinterresultr   r   r   r   y   s    &
c             C   s"   | j tjjko | jjo | jj jS )N)typer   FieldDescriptorTYPE_MESSAGEmessage_typeZhas_options
GetOptionsZ	map_entry)fieldr   r   r   _IsMapEntry   s    rE   c             C   s(   t |||||||||	|

}|j|  d S )N)r2   r   )r   r<   r:   r*   r4   r5   r6   r7   r8   r9   r;   r=   r   r   r   r      s    c
          	   C   s&   t ||||||||	}
|
j| | dS )z%Print a single field name/value pair.N)r2   r   )rD   valuer<   r:   r*   r4   r5   r6   r7   r;   r=   r   r   r   r      s    
c
          	   C   s&   t ||||||||	}
|
j| | dS )z0Print a single field value (not including name).N)r2   r   )rD   rF   r<   r:   r*   r4   r5   r6   r7   r;   r=   r   r   r   r      s    
c             C   sd   |dkrddl m} |j }ddl m} |j }y|j| }W n tk
rR   dS X |j|}| S )a!  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.
  Nr   )r9   )symbol_database)google.protobufr9   ZDefaultrG   ZFindMessageTypeByNameKeyErrorZGetPrototype)Z	type_namer9   Zpool_modrG   Zdatabasemessage_descriptorrB   r   r   r   _BuildMessageFromTypeName   s    
rK   c            	   @   sJ   e Zd ZdZdddZdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dS )r2   z)Text format printer for protocol message.r   FNc             C   s@   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	dS )aZ  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.
      message_formatter: A function(message, indent, as_one_line): unicode|None
        to custom format selected sub-messages (usually based on message type).
        Use to pretty print parts of the protobuf for easier diffing.
    N)
r<   r:   r*   r4   r5   r6   r7   r8   r9   r;   )r   r<   r:   r*   r4   r5   r6   r7   r8   r9   r;   r   r   r   r      s    %z_Printer.__init__c             C   sh   t |j | j}|r`|j|j | jjd| jd |jf  | j	| | jj| j
rVdnd dS dS dS )z5Serializes if message is a google.protobuf.Any field.z%s[%s] 
TFN)rK   ZTypeNamer9   MergeFromStringrF   r<   r.   r:   Ztype_url_PrintMessageFieldValuer4   )r   r   Zpacked_messager   r   r   _TryPrintAsAnyMessage.  s    
z_Printer._TryPrintAsAnyMessagec             C   sV   | j || j| j}|d krdS | j}|jd| j  |j| |j| jrLdnd dS )NFrL   rM   T)r;   r:   r4   r<   r.   )r   r   Z	formattedr<   r   r   r   _TryCustomFormatMessage;  s    
z _Printer._TryCustomFormatMessagec             C   s   | j r| j|rdS |jjtkr.| j|r.dS |j }| jrL|jdd d x|D ]z\}}t	|rxht
|D ]$}|j ||| d}| j|| qlW qR|jtjjkrx&|D ]}| j|| qW qR| j|| qRW dS )zeConvert protobuf message to text format.

    Args:
      message: The protocol buffers message.
    Nc             S   s
   | d j S )Nr   )index)xr   r   r   <lambda>S  s    z'_Printer.PrintMessage.<locals>.<lambda>)key)rU   rF   )r;   rQ   
DESCRIPTOR	full_name_ANY_FULL_TYPE_NAMErP   Z
ListFieldsr6   sortrE   sortedGetEntryClassr   labelr   r@   LABEL_REPEATED)r   r   ZfieldsrD   rF   rU   Zentry_submsgelementr   r   r   r   F  s"    

z_Printer.PrintMessagec             C   s   | j }|jd| j  | jr.|jt|j n|jr|jd |jj j	rv|j
tjjkrv|jtjjkrv|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 | j|| | jr|jd n
|jd dS )z%Print a single field name/value pair.rL   []z: rM   N)r<   r.   r:   r8   r   numberis_extensioncontaining_typerC   Zmessage_set_wire_formatr?   r   r@   rA   r\   ZLABEL_OPTIONALrB   rW   
TYPE_GROUPnamecpp_typeCPPTYPE_MESSAGEr   r4   )r   rD   rF   r<   r   r   r   r   d  s*    

z_Printer.PrintFieldc             C   s   | j rd}d}nd}d}| jrF| jjd|  | j| | jj| nL| jjd|  |  jd7  _| j| |  jd8  _| jjd| j |  d S )	N<>{}z %s z %s
   rL   )r5   r4   r<   r.   r   r:   )r   rF   ZopenbZclosebr   r   r   rO     s    

z _Printer._PrintMessageFieldValuec             C   s<  | j }|jtjjkr"| j| n|jtjjkrf|jjj	|d}|dk	rV|j
|j n|j
t| n|jtjjkr|j
d t|tjr|jd}n|}|jtjjkrd}n| j}|j
tj|| |j
d nf|jtjjkr|r|j
d n
|j
d n<|jtkr*| jdk	r*|j
dj| j| n|j
t| dS )zPrint 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.
    Nr   zutf-8Ftruefalsez{1:{0}})r<   rf   r   r@   rg   rO   ZCPPTYPE_ENUM	enum_typevalues_by_numbergetr.   re   r   ZCPPTYPE_STRINGr+   r$   r,   r-   r?   
TYPE_BYTESr*   r   ZCEscapeZCPPTYPE_BOOL_FLOAT_TYPESr7   r   )r   rD   rF   r<   
enum_valueZ	out_valueZout_as_utf8r   r   r   r     s2    	
z_Printer.PrintFieldValue)	r   FFFFNFNN)r   r   r   r   r   rP   rQ   r   r   rO   r   r   r   r   r   r2      s            
&!r2   c             C   s>   t | ts&tjr| jd} n
| jd} t| jd||||dS )a  Parses a text representation of a protocol message into a message.

  NOTE: for historical reasons this function does not clear the input
  message. This is different from what the binary msg.ParseFrom(...) does.

  Example
    a = MyProto()
    a.repeated_field.append('test')
    b = MyProto()

    text_format.Parse(repr(a), b)
    text_format.Parse(repr(a), b) # repeated_field contains ["test", "test"]

    # Binary version:
    b.ParseFromString(a.SerializeToString()) # repeated_field is now "test"

  Caller is responsible for clearing the message as needed.

  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.
  zutf-8rM   )r9   )r+   r   r$   PY3decoder-   
ParseLinessplit)textr   allow_unknown_extensionallow_field_numberr9   r   r   r   Parse  s    %


r|   c             C   s>   t | ts&tjr| jd} n
| jd} t| jd||||dS )a^  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.
  zutf-8rM   )r9   )r+   r   r$   ru   rv   r-   
MergeLinesrx   )ry   r   rz   r{   r9   r   r   r   r	     s    

c             C   s   t |||d}|j| |S )a  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.
  )r9   )_Parserrw   )linesr   rz   r{   r9   parserr   r   r   rw     s    rw   c             C   s   t |||d}|j| |S )a  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.
  )r9   )r~   r}   )r   r   rz   r{   r9   r   r   r   r   r}   3  s    r}   c               @   sn   e Zd ZdZdddZdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zedd Zdd ZdS )r~   z(Text format parser for protocol message.FNc             C   s   || _ || _|| _d S )N)rz   r{   r9   )r   rz   r{   r9   r   r   r   r   Q  s    z_Parser.__init__c             C   s&   t |ts|jd}| j|jd|S )zBParses a text representation of a protocol message into a message.zutf-8rM   )r+   r   rv   rw   rx   )r   ry   r   r   r   r   ParseFromStringY  s    

z_Parser.ParseFromStringc             C   s   d| _ | j|| |S )zBParses a text representation of a protocol message into a message.F)_allow_multiple_scalars_ParseOrMerge)r   r   r   r   r   r   rw   _  s    z_Parser.ParseLinesc             C   s   | j |jd|S )zBMerges a text representation of a protocol message into a message.rM   )Z_MergeLinesrx   )r   ry   r   r   r   r   rN   e  s    z_Parser.MergeFromStringc             C   s   d| _ | j|| |S )zBMerges a text representation of a protocol message into a message.T)r   r   )r   r   r   r   r   r   r}   i  s    z_Parser.MergeLinesc             C   s&   t |}x|j s | j|| q
W dS )zConverts 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)	TokenizerAtEnd_MergeField)r   r   r   	tokenizerr   r   r   r   o  s    

z_Parser._ParseOrMergec       	      C   s  |j }|jdr|j g}x|jdr6|j|j  qW dj|}|jsX|jd|j |jj	|}|s| j
rtd}q|jd| n||jkr|jd||jf |jd n|j }| jr|j rt|dd}|jj|d}| r|jr|jj|}nh|jj|d}|s8|jj|j d}|r8|jtjjkr8d}|r`|jtjjkr`|jj|kr`d}|sz|jd	|j|f |r^| j r|jr|j|jj}|dk	r||jkr|jd
|j||jj|jf |jtjj kr|jd | j!}n|jd | j"}|j#tjj$krP|jdrPx8|||| |jdr>P |jd q$W n|||| nt%| |jds||jd dS )zMerges 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.
    r_   .z+Message type "%s" does not have extensions.NzExtension "%s" not registered. Did you import the _pb2 module which defines it? If you are trying to place the extension in the MessageSet field of another message that is in an Any or MessageSet field, that message's _pb2 module must be imported as wellz1Extension "%s" does not extend message type "%s".r`   Tz*Message type "%s" has no field named "%s".zbField "%s" is specified along with field "%s", another member of oneof "%s" for message type "%s".:,;)&rV   
TryConsumeConsumeIdentifierappendjoinZis_extendableParseErrorPreviousTokenrW   
ExtensionsZ_FindExtensionByNamerz   rc   ConsumeConsumeIdentifierOrNumberr{   isdigitParseIntegerZfields_by_numberrq   Z_FindExtensionByNumberfields_by_namelowerr?   r   r@   rd   rB   re   r   Zcontaining_oneofZ
WhichOneofrf   rg   _MergeMessageField_MergeScalarFieldr\   r]   _SkipFieldContents)	r   r   r   rJ   re   rD   ra   Zwhich_oneofZmergerr   r   r   r   }  s    








z_Parser._MergeFieldc             C   s   |j  g}|jd |j|j   |jd |j|j   |jd |j  g}x|jdrj|j|j   qPW dj|dj|fS )zBConsumes a google.protobuf.Any type URL and returns the type name.r   /)r   r   r   r   r   )r   r   prefixre   r   r   r   _ConsumeAnyTypeUrl  s    




z_Parser._ConsumeAnyTypeUrlc             C   s  t |}|jdrd}n|jd d}|jjtko:|jdr
| j|\}}|jd |jd |jdrpd}n|jd d}t|| j}	|	st	d| x2|j|s|j
 r|jd	|f | j||	 qW |jtjjkrt||jj }
nt||j}
|
j|	|d
 n||jtjjkr^|jr2|j| j }n*|rLt||jj  }nt||jj }n(|jrr|j| }nt||j}|j  x8|j|s|j
 r|jd	|f | j|| qW |r|jjd j}|tjjkrt||j|j }|j|j n|jt||j|j< dS )a"  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.
    rh   ri   rj   rk   r_   r`   r   z$Type %s not found in descriptor poolzExpected "%s".)type_url_prefixrF   N)rE   r   r   rB   rW   rX   r   rK   r9   r   r   r   r   r\   r   r@   r]   getattrre   addZPackrb   r   r[   ZSetInParentr   rf   rg   rU   Z	MergeFromrF   )r   r   r   rD   Zis_map_entryZ	end_tokenr   Zpacked_type_nameZexpanded_any_end_tokenZexpanded_any_sub_messageZany_messageZsub_messageZvalue_cpptyperF   r   r   r   r     sb    








z_Parser._MergeMessageFieldc             C   s   | j }t|do|jdkS )Nsyntaxproto3)rV   hasattrr   )r   rJ   r   r   r   _IsProto3SyntaxA  s    
z_Parser._IsProto3Syntaxc             C   s  | j }d}|jtjjtjjtjjfkr0t|}n|jtjjtjj	tjj
fkrVt|}n|jtjjtjjfkrvt|}n|jtjjtjjfkrt|}n|jtjjtjjfkr|j }nr|jtjjkr|j }nZ|jtjjkr|j }nB|jtjjkr|j }n*|jtjjkr|j|}ntd|j |jtjjkrf|j rR|j!| j"| nt#||j$j"| n| j%| }|j r| j& r|r|j'|r|j(d|j)j*|j*f n
||j!|< nF| j& r|r|j+|j$r|j(d|j)j*|j$f nt,||j$| dS )aH  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.
    NzUnknown field type %dz;Message type "%s" should not have multiple "%s" extensions.z7Message type "%s" should not have multiple "%s" fields.)-rz   r?   r   r@   Z
TYPE_INT32ZTYPE_SINT32ZTYPE_SFIXED32_ConsumeInt32Z
TYPE_INT64ZTYPE_SINT64ZTYPE_SFIXED64_ConsumeInt64ZTYPE_UINT32ZTYPE_FIXED32_ConsumeUint32ZTYPE_UINT64ZTYPE_FIXED64_ConsumeUint64Z
TYPE_FLOATZTYPE_DOUBLEConsumeFloatZ	TYPE_BOOLConsumeBoolZTYPE_STRINGConsumeStringrr   ConsumeByteStringZ	TYPE_ENUMConsumeEnumRuntimeErrorr\   r]   rb   r   r   r   re   r   r   ZHasExtensionr   rV   rW   ZHasFieldsetattr)r   r   r   rD   _rF   Zcan_check_presencer   r   r   r   G  s\    












z_Parser._MergeScalarField)FFN)r   r   r   r   r   r   rw   rN   r}   r   r   r   r   staticmethodr   r   r   r   r   r   r~   N  s     
mHr~   c             C   s8   | j dr,| jd r,| jd r,t|  nt|  dS )z}Skips over contents (value or message) of a field.

  Args:
    tokenizer: A tokenizer to parse the field name and values.
  r   rj   rh   N)r   	LookingAt_SkipFieldValue_SkipFieldMessage)r   r   r   r   r     s    
r   c             C   s^   | j dr6| j  x| j dr(| j  qW | jd n| j  t|  | j dsZ| j d dS )zSkips over a complete field (name and value/message).

  Args:
    tokenizer: A tokenizer to parse the field name and values.
  r_   r   r`   r   r   N)r   r   r   r   )r   r   r   r   
_SkipField  s    

r   c             C   sR   | j drd}n| jd d}x$| jd rB| jd rBt|  q W | j| dS )zfSkips over a field message.

  Args:
    tokenizer: A tokenizer to parse the field name and values.
  rh   ri   rj   rk   N)r   r   r   r   )r   Z	delimiterr   r   r   r     s    

r   c             C   sT   | j  rx| j  rq
W dS | j  rPt|  rPt|  rP| j  rPtd| j dS )zSkips 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.
  NzInvalid field value: )TryConsumeByteStringTryConsumeIdentifier_TryConsumeInt64_TryConsumeUint64TryConsumeFloatr   token)r   r   r   r   r     s    


r   c               @   sH  e Zd 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dd	 eD  Zejd
ZejdZdEddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( ZdFd*d+Zd,d- Zd.d/ Zd0d1 Z d2d3 Z!d4d5 Z"d6d7 Z#d8d9 Z$d:d; Z%d<d= Z&d>d? Z'd@dA Z(dBdC Z)dDS )Gr   zProtocol 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.
  z\s+z	(\s*#.*$)z(\s|(#.*$))+|z[a-zA-Z_][0-9a-zA-Z_+-]*z#([0-9+-]|(\.[0-9]))[0-9a-zA-Z_.+-]*c             C   s   g | ]}d j |dqS )z!{qt}([^{qt}\n\\]|\\.)*({qt}|\\?$))Zqt)r   ).0Zmarkr   r   r   
<listcomp>  s    zTokenizer.<listcomp>z
[^\d\W]\w*z\w+Tc             C   sl   d| _ d| _d| _d | _d| _t|| _d| _d| _d| _	d| _
|| _|rP| jpT| j| _| j  | j  d S )Nr       T)Z	_positionr   r   Z_token_startr   iter_lines_current_line_previous_line_previous_column_more_lines_skip_comments_WHITESPACE_OR_COMMENT_WHITESPACE_whitespace_pattern_SkipWhitespace	NextToken)r   r   Zskip_commentsr   r   r   r     s    

zTokenizer.__init__c             C   s
   | j |kS )N)r   )r   r   r   r   r   r     s    zTokenizer.LookingAtc             C   s   | j  S )z^Checks the end of the text was reached.

    Returns:
      True iff the end was reached.
    )r   )r   r   r   r   r   
  s    zTokenizer.AtEndc             C   s`   xZt | j| jkrZyt| j| _W n  tk
rB   d| _d| _d S X |  jd7  _d| _qW d S )Nr   Fr   r   )lenr   r   nextr   StopIterationr   r   )r   r   r   r   _PopLine  s    zTokenizer._PopLinec             C   sF   x@| j   | jj| j| j}|s"P t|jd}|  j|7  _qW d S )Nr   )r   r   matchr   r   r   group)r   r   Zlengthr   r   r   r     s    zTokenizer._SkipWhitespacec             C   s   | j |kr| j  dS dS )zTries to consume a given piece of text.

    Args:
      token: Text to consume.

    Returns:
      True iff the text was consumed.
    TF)r   r   )r   r   r   r   r   r   '  s    	
zTokenizer.TryConsumec             C   s   | j |s| jd| dS )zConsumes a piece of text.

    Args:
      token: Text to consume.

    Raises:
      ParseError: If the text couldn't be consumed.
    zExpected "%s".N)r   r   )r   r   r   r   r   r   5  s    	
zTokenizer.Consumec             C   s(   | j }| jj|s| jd| j  |S )NzExpected comment.)r   _COMMENTr   r   r   )r   r>   r   r   r   ConsumeCommentA  s
    
zTokenizer.ConsumeCommentc             C   s:   | j dko| jdk}| j}| j }| j|ko0| }||fS )zCConsumes a comment, returns a 2-tuple (trailing bool, comment str).r   )r   r   r   r   )r   Zjust_startedZbefore_parsingZcommentZtrailingr   r   r   ConsumeCommentOrTrailingCommentH  s    
z)Tokenizer.ConsumeCommentOrTrailingCommentc             C   s&   y| j   dS  tk
r    dS X d S )NTF)r   r   )r   r   r   r   r   X  s
    zTokenizer.TryConsumeIdentifierc             C   s(   | j }| jj|s| jd| j  |S )zConsumes protocol message field identifier.

    Returns:
      Identifier string.

    Raises:
      ParseError: If an identifier couldn't be consumed.
    zExpected identifier.)r   _IDENTIFIERr   r   r   )r   r>   r   r   r   r   _  s
    	
zTokenizer.ConsumeIdentifierc             C   s&   y| j   dS  tk
r    dS X d S )NTF)r   r   )r   r   r   r   TryConsumeIdentifierOrNumbern  s
    z&Tokenizer.TryConsumeIdentifierOrNumberc             C   s,   | j }| jj|s | jd| | j  |S )zConsumes protocol message field identifier.

    Returns:
      Identifier string.

    Raises:
      ParseError: If an identifier couldn't be consumed.
    z&Expected identifier or number, got %s.)r   _IDENTIFIER_OR_NUMBERr   r   r   )r   r>   r   r   r   r   u  s
    	z#Tokenizer.ConsumeIdentifierOrNumberc             C   s&   y| j   dS  tk
r    dS X d S )NTF)ConsumeIntegerr   )r   r   r   r   TryConsumeInteger  s
    zTokenizer.TryConsumeIntegerFc             C   sP   yt | j|d}W n0 tk
rB } z| jt|W Y dd}~X nX | j  |S )zConsumes 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.
    )is_longN)_ParseAbstractIntegerr   
ValueErrorr   r   r   )r   r   r>   er   r   r   r     s     zTokenizer.ConsumeIntegerc             C   s&   y| j   dS  tk
r    dS X d S )NTF)r   r   )r   r   r   r   r     s
    zTokenizer.TryConsumeFloatc             C   sL   yt | j}W n0 tk
r> } z| jt|W Y dd}~X nX | j  |S )zConsumes an floating point number.

    Returns:
      The number parsed.

    Raises:
      ParseError: If a floating point number couldn't be consumed.
    N)
ParseFloatr   r   r   r   r   )r   r>   r   r   r   r   r     s    	 zTokenizer.ConsumeFloatc             C   sL   yt | j}W n0 tk
r> } z| jt|W Y dd}~X nX | j  |S )zConsumes a boolean value.

    Returns:
      The bool parsed.

    Raises:
      ParseError: If a boolean value couldn't be consumed.
    N)	ParseBoolr   r   r   r   r   )r   r>   r   r   r   r   r     s    	 zTokenizer.ConsumeBoolc             C   s&   y| j   dS  tk
r    dS X d S )NTF)r   r   )r   r   r   r   r     s
    zTokenizer.TryConsumeByteStringc             C   sF   | j  }ytj|dS  tk
r@ } z| j|W Y dd}~X nX dS )zConsumes a string value.

    Returns:
      The string parsed.

    Raises:
      ParseError: If a string value couldn't be consumed.
    zutf-8N)r   r$   r,   UnicodeDecodeError_StringParseError)r   Z	the_bytesr   r   r   r   r     s
    	zTokenizer.ConsumeStringc             C   s<   | j  g}x&| jr0| jd tkr0|j| j   qW dj|S )zConsumes a byte array value.

    Returns:
      The array parsed (as a string).

    Raises:
      ParseError: If a byte array value couldn't be consumed.
    r       )_ConsumeSingleByteStringr   _QUOTESr   r   )r   Zthe_listr   r   r   r     s    	
zTokenizer.ConsumeByteStringc             C   s   | j }t|dk s|d tkr.| jd|f t|dk sJ|d |d krZ| jd|f ytj|dd }W n0 tk
r } z| jt|W Y dd}~X nX | j  |S )	aO  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.
    r   r   zExpected string but found: %rrl   zString missing ending quote: %rNr   r   )	r   r   r   r   r   Z	CUnescaper   r   r   )r   ry   r>   r   r   r   r   r     s     z"Tokenizer._ConsumeSingleByteStringc             C   sN   yt || j}W n0 tk
r@ } z| jt|W Y d d }~X nX | j  |S )N)	ParseEnumr   r   r   r   r   )r   rD   r>   r   r   r   r   r     s     zTokenizer.ConsumeEnumc             C   s   t || jd | jd S )zCreates and *returns* a ParseError for the previously read token.

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

    Returns:
      A ParseError instance.
    r   )r   r   r   )r   r   r   r   r   r     s    	z!Tokenizer.ParseErrorPreviousTokenc             C   s   t || jd | jd S )z9Creates and *returns* a ParseError for the current token.r   )r   r   r   )r   r   r   r   r   r     s    zTokenizer.ParseErrorc             C   s   | j dt| S )NzCouldn't parse string: )r   r   )r   r   r   r   r   r     s    zTokenizer._StringParseErrorc             C   s   | j | _| j| _|  jt| j7  _| j  | js<d| _dS | jj	| j
| j}| rn| j rn| jj	| j
| j}|r|jd}|| _n| j
| j | _dS )z Reads the next meaningful token.r   Nr   )r   r   r   r   r   r   r   r   _TOKENr   r   r   r   r   )r   r   r   r   r   r   r     s    
zTokenizer.NextTokenN)T)F)*r   r   r   r   recompiler   	MULTILINEr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     sJ   



	
r   c             C   s   t | dddS )zConsumes 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.
  TF)	is_signedr   )_ConsumeInteger)r   r   r   r   r   8  s    r   c             C   s   t | dddS )zConsumes 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.
  F)r   r   )r   )r   r   r   r   r   G  s    r   c             C   s&   yt |  dS  tk
r    dS X d S )NTF)r   r   )r   r   r   r   r   V  s
    r   c             C   s   t | dddS )zConsumes 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)r   r   )r   )r   r   r   r   r   ^  s    r   c             C   s&   yt |  dS  tk
r    dS X d S )NTF)r   r   )r   r   r   r   r   m  s
    r   c             C   s   t | dddS )zConsumes 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.
  FT)r   r   )r   )r   r   r   r   r   u  s    r   c             C   s,   yt | ||d dS  tk
r&   dS X d S )N)r   r   TF)r   r   )r   r   r   r   r   r   _TryConsumeInteger  s
    r   c             C   sR   yt | j||d}W n0 tk
rD } z| jt|W Y dd}~X nX | j  |S )aU  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   N)r   r   r   r   r   r   )r   r   r   r>   r   r   r   r   r     s     r   c             C   s2   t | |d}tdt| t|  }|j| |S )a  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   rl   )r   _INTEGER_CHECKERSintZ
CheckValue)ry   r   r   r>   Zcheckerr   r   r   r     s    
r   c             C   sB   y|rt | dS t | dS W n  tk
r<   td|  Y nX dS )a  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.
  r   zCouldn't parse integer: %sN)r   r   )ry   r   r   r   r   r     s    
r   c             C   s   yt | S  tk
r   tj| r@| d dkr6t dS t dS nBtj| rRt dS yt | jdS  tk
r   td|  Y nX Y nX dS )	zParse a floating point number.

  Args:
    text: Text to parse.

  Returns:
    The number parsed.

  Raises:
    ValueError: If a floating point number couldn't be parsed.
  r   -z-infinfnanfzCouldn't parse float: %sN)floatr   _FLOAT_INFINITYr   
_FLOAT_NANr3   )ry   r   r   r   r     s    


r   c             C   s$   | dkrdS | dkrd
S t ddS )zParse a boolean value.

  Args:
    text: Text to parse.

  Returns:
    Boolean values parsed

  Raises:
    ValueError: If text is not a valid boolean.
  rm   t1TrueTrn   r   0FalseFzExpected "true" or "false".N)rm   r   r   r   )rn   r   r   r   )r   )ry   r   r   r   r     s
    r   c             C   s   | j }yt|d}W n< tk
rP   |jj|d}|dkrLtd|j|f Y nFX t| jdrn| jjdkrn|S |j	j|d}|dkrtd|j|f |j
S )a&  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.
  r   Nz%Enum type "%s" has no value named %s.r   r   z+Enum type "%s" has no value with number %d.)ro   r   r   Zvalues_by_namerq   rW   r   filer   rp   ra   )rD   rF   Zenum_descriptorra   rt   r   r   r   r     s     r   )r
   r   )	FFFFNFNr   N)	r   FFFFNFNN)r   FFFFNN)r   FFFFNN)FFN)FFN)FFN)FFN)FF)FF)FF)F)Br   
__author__r&   r   r$   ru   r   ZlongZgoogle.protobuf.internalr   rH   r   r   __all__ZUint32ValueCheckerZInt32ValueCheckerZUint64ValueCheckerZInt64ValueCheckerr   r   
IGNORECASEr   r   	frozensetr@   ZCPPTYPE_FLOATZCPPTYPE_DOUBLErs   r   rX   	Exceptionr   r   objectr#   r   rE   r   r   r   rK   r2   r|   r	   rw   r}   r~   r   r   r   r   r   Z
_Tokenizerr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>)   s   
        
)        

      

      
 J  
/  
#  
  
  A  W



 