o
    ‹¨Êh¼Ô  ã                   @   sn  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 g d¢Ze	 ¡ e	 ¡ e	 ¡ e	 ¡ fZe dej¡Ze d	ej¡ZeejjejjgƒZed
ƒZdZG dd„ deƒZG dd„ deƒZ G dd„ de!ƒZ"										dQdd„Z#dd„ Z$dd„ Z%										dRdd„Z&								dSdd„Z'								dSdd„Z(dd „ Z)G d!d"„ d"e!ƒZ*			dTd#d$„Z+			dTd%d&„Z,			dTd'd(„Z-			dTd)d*„Z.G d+d,„ d,e!ƒZ/d-d.„ Z0d/d0„ Z1d1d2„ Z2d3d4„ Z3G d5d6„ d6e!ƒZ4e4Z5d7d8„ Z6d9d:„ Z7d;d<„ Z8d=d>„ Z9d?d@„ Z:dAdB„ Z;dUdCdD„Z<dUdEdF„Z=dUdGdH„Z>dVdIdJ„Z?dKdL„ Z@dMdN„ ZAdOdP„ ZBdS )Wab  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ÚParseÚPrintMessageÚ
PrintFieldÚPrintFieldValueÚMergeÚMessageToBytesz-?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   úM/var/www/html/env/lib/python3.10/site-packages/google/protobuf/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 ur|d urt |ƒ}|d ur|d |¡7 }d ||¡}|d ur*tt| ƒ |¡ ntt| ƒ ¡  || _|| _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   ó   | j S ©N)r   ©r   r   r   r   ÚGetLine]   ó   zParseError.GetLinec                 C   r#   r$   )r   r%   r   r   r   Ú	GetColumn`   r'   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 ¡ | _d S t ¡ | _d S r$   )Ú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| d¡}| j |¡S )Núutf-8)r+   r,   Ú
isinstanceÚ	text_typeÚencoder/   Úwrite)r   Úvalr   r   r   r6   l   s   
zTextWriter.writec                 C   ó
   | j  ¡ S r$   )r/   Úcloser%   r   r   r   r9   r   ó   
zTextWriter.closec                 C   r8   r$   )r/   Úgetvaluer%   r   r   r   r;   u   r:   zTextWriter.getvalueN)r   r   r   r   r6   r9   r;   r   r   r   r   r*   d   s
    r*   Fc                 C   sN   t |ƒ}t||	|||||||||
ƒ}| | ¡ | ¡ }| ¡  |r%| ¡ 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: Return unescaped Unicode for non-ASCII characters.
        In Python 3 actual Unicode characters may appear as is in strings.
        In Python 2 the return value will be valid UTF-8 rather than only ASCII.
    as_one_line: Don't introduce newlines between fields.
    use_short_repeated_primitives: Use short repeated format for primitives.
    pointy_brackets: If True, use angle brackets instead of curly braces for
      nesting.
    use_index_order: If True, fields of a proto message will be printed using
      the order defined in source code instead of the field number, extensions
      will be printed at the end of the message and their relative order is
      determined by the extension 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 initial 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   r;   r9   Úrstrip)r   r1   Úas_one_lineÚuse_short_repeated_primitivesÚpointy_bracketsÚuse_index_orderÚfloat_formatÚuse_field_numberÚdescriptor_poolÚindentÚmessage_formatterÚoutÚprinterÚresultr   r   r   r   y   s   -
ý
r   c                 K   s:   t | fi |¤Ž}t|tƒr|S | d¡rdnd}| |¡S )zFConvert protobuf message to encoded text format.  See MessageToString.r1   r2   Úascii)r   r3   ÚbytesÚgetr5   )r   ÚkwargsÚtextÚcodecr   r   r   r   ³   s
   

r   c                 C   s"   | j tjjko| jjo| j ¡ jS r$   )Útyper   ÚFieldDescriptorÚTYPE_MESSAGEÚmessage_typeÚhas_optionsÚ
GetOptionsÚ	map_entry)Úfieldr   r   r   Ú_IsMapEntry½   s
   ÿ
þrX   c                 C   s*   t |||||||||	|
|ƒ}| | ¡ d S r$   )r<   r   )r   rG   rE   r1   r>   r?   r@   rA   rB   rC   rD   rF   rH   r   r   r   r   Ã   s   
ýr   c                 C   ó*   t ||||||||	|
d�	}| | |¡ dS )ú%Print a single field name/value pair.©rF   N)r<   r   ©rW   ÚvaluerG   rE   r1   r>   r?   r@   rA   rB   rF   rH   r   r   r   r   Ö   ó   
ýr   c                 C   rY   )z0Print a single field value (not including name).r[   N)r<   r	   r\   r   r   r   r	   é   r^   r	   c                 C   sd   |du rddl m} | ¡ }ddl m} | ¡ }z| | ¡}W n
 ty)   Y dS w | |¡}|ƒ 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   ©rD   )Úsymbol_database)Úgoogle.protobufrD   ÚDefaultr`   ÚFindMessageTypeByNameÚKeyErrorÚGetPrototype)Ú	type_namerD   Úpool_modr`   ÚdatabaseÚmessage_descriptorrS   r   r   r   Ú_BuildMessageFromTypeNameü   s   ÿ
rj   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dS )r<   z)Text format printer for protocol message.r   FNc                 C   sF   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
dS )a[  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 initial indent level for pretty print.
      as_utf8: Return unescaped Unicode for non-ASCII characters.
          In Python 3 actual Unicode characters may appear as is in strings.
          In Python 2 the return value will be valid UTF-8 rather than ASCII.
      as_one_line: Don't introduce newlines between fields.
      use_short_repeated_primitives: Use short repeated format for primitives.
      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)rG   rE   r1   r>   r?   r@   rA   rB   rC   rD   rF   )r   rG   rE   r1   r>   r?   r@   rA   rB   rC   rD   rF   r   r   r   r     s   )
z_Printer.__init__c                 C   sx   d|j vrdS t| ¡ | jƒ}|r:| |j¡ | j d| jd |j f ¡ |  	|¡ | j | j
r5d¡ dS d¡ dS dS )z5Serializes if message is a google.protobuf.Any field.ú/Fz%s[%s] ú Ú
T)Útype_urlrj   ÚTypeNamerD   ÚMergeFromStringr]   rG   r6   rE   Ú_PrintMessageFieldValuer>   )r   r   Úpacked_messager   r   r   Ú_TryPrintAsAnyMessageM  s   
ÿ
ÿz_Printer._TryPrintAsAnyMessagec                 C   s\   |   || j| j¡}|d u rdS | j}| d| j ¡ | |¡ | | jr)d¡ dS d¡ dS )NFrl   rm   T)rF   rE   r>   rG   r6   )r   r   Ú	formattedrG   r   r   r   Ú_TryCustomFormatMessage\  s   
ÿz _Printer._TryCustomFormatMessagec                 C   sø   | j r
|  |¡r
dS |jjtkr|  |¡rdS | ¡ }| jr&|jdd„ d� |D ]Q\}}t	|ƒrHt
|ƒD ]}| ¡ ||| d�}|  ||¡ q4q(|jtjjkrs| jrg|jtjjkrg|jtjjkrg|  ||¡ q(|D ]}|  ||¡ qiq(|  ||¡ q(dS )zeConvert protobuf message to text format.

    Args:
      message: The protocol buffers message.
    Nc                 S   s   | d j r
| d jS | d jS )Nr   )Úis_extensionÚnumberÚindex)Úxr   r   r   Ú<lambda>u  s    z'_Printer.PrintMessage.<locals>.<lambda>)Úkey)r{   r]   )rF   ru   Ú
DESCRIPTORÚ	full_nameÚ_ANY_FULL_TYPE_NAMErs   Ú
ListFieldsrA   ÚsortrX   ÚsortedÚGetEntryClassr   Úlabelr   rQ   ÚLABEL_REPEATEDr?   Úcpp_typeÚCPPTYPE_MESSAGEÚCPPTYPE_STRINGÚ"_PrintShortRepeatedPrimitivesValue)r   r   ÚfieldsrW   r]   r{   Úentry_submsgÚelementr   r   r   r   g  s6   ÿÿùÿíz_Printer.PrintMessagec                 C   sØ   | j }| d| j ¡ | jr| t|jƒ¡ nE|jrG| d¡ |j ¡ j	r;|j
tjjkr;|jtjjkr;| |jj¡ n| |j¡ | d¡ n|j
tjjkrV| |jj¡ n| |j¡ |jtjjkrj| d¡ dS dS )zPrint field name.rl   ú[ú]ú:N)rG   r6   rE   rC   r   rw   rv   Úcontaining_typerU   Úmessage_set_wire_formatrP   r   rQ   rR   rƒ   ÚLABEL_OPTIONALrS   r}   Ú
TYPE_GROUPÚnamer…   r†   )r   rW   rG   r   r   r   Ú_PrintFieldName‹  s$   
ýz_Printer._PrintFieldNamec                 C   sB   |   |¡ | j d¡ |  ||¡ | j | jrd¡ dS d¡ dS )rZ   rl   rm   N)r”   rG   r6   r	   r>   )r   rW   r]   r   r   r   r   ¦  s   
 z_Printer.PrintFieldc                 C   sˆ   |   |¡ | j d¡ tj t|ƒd ¡D ]}|  ||| ¡ | j d¡ q|  ||d ¡ | j d¡ | j | jr?d¡ d S d¡ d S )Nz [é   z, éÿÿÿÿr�   rl   rm   )	r”   rG   r6   r+   ÚmovesÚrangeÚlenr	   r>   )r   rW   r]   Úir   r   r   rˆ   ­  s   
 z+_Printer._PrintShortRepeatedPrimitivesValuec                 C   s˜   | j rd}d}nd}d}| jr$| j d| ¡ |  |¡ | j |¡ d S | j d| ¡ |  jd7  _|  |¡ |  jd8  _| j d| j | ¡ d S )	Nú<ú>Ú{Ú}z%s z%s
é   rl   )r@   r>   rG   r6   r   rE   )r   r]   ÚopenbÚclosebr   r   r   rq   ¸  s   

z _Printer._PrintMessageFieldValuec                 C   sP  | j }|jtjjkr|  |¡ dS |jtjjkr5|jj 	|d¡}|dur,| 
|j¡ dS | 
t|ƒ¡ dS |jtjjkrr| 
d¡ t|tjƒrStjsM| jsS| d¡}n|}|jtjjkr_d}n| j}| 
t ||¡¡ | 
d¡ dS |jtjjkr‰|r‚| 
d¡ dS | 
d¡ dS |jtv rŸ| jdurŸ| 
d | j|¡¡ dS | 
t|ƒ¡ dS )zÝ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.
    Nr   r2   FÚtrueÚfalsez{1:{0}})rG   r…   r   rQ   r†   rq   ÚCPPTYPE_ENUMÚ	enum_typeÚvalues_by_numberrL   r6   r“   r   r‡   r3   r+   r4   r,   r1   r5   rP   Ú
TYPE_BYTESr   ÚCEscapeÚCPPTYPE_BOOLÚ_FLOAT_TYPESrB   r   )r   rW   r]   rG   Ú
enum_valueÚ	out_valueÚout_as_utf8r   r   r   r	   Ë  s2   	
z_Printer.PrintFieldValue©
r   FFFFFNFNN)r   r   r   r   r   rs   ru   r   r”   r   rˆ   rq   r	   r   r   r   r   r<     s*    
õ5$r<   c                 C   ó&   t |  t| tƒr
dn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.
  ó   
rm   r_   )Ú
ParseLinesÚsplitr3   rK   ©rN   r   Úallow_unknown_extensionÚallow_field_numberrD   r   r   r   r   õ  s   %ür   c                 C   r¯   )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.
  r°   rm   r_   )Ú
MergeLinesr²   r3   rK   r³   r   r   r   r
   !  s   ûr
   c                 C   ó   t |||d�}| | |¡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.
  r_   )Ú_Parserr±   ©Úlinesr   r´   rµ   rD   Úparserr   r   r   r±   A  s
   þr±   c                 C   r·   )a€  Parses a text representation of a protocol message into a message.

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

  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.
  r_   )r¸   r¶   r¹   r   r   r   r¶   \  s
   þr¶   c                   @   sd   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
edd„ ƒZdd„ ZdS )r¸   z(Text format parser for protocol message.FNc                 C   s   || _ || _|| _d S r$   )r´   rµ   rD   )r   r´   rµ   rD   r   r   r   r   }  s   
z_Parser.__init__c                 C   ó   d| _ |  ||¡ |S )zBParses a text representation of a protocol message into a message.F©Ú_allow_multiple_scalarsÚ_ParseOrMerge©r   rº   r   r   r   r   r±   …  ó   z_Parser.ParseLinesc                 C   r¼   )zBMerges a text representation of a protocol message into a message.Tr½   rÀ   r   r   r   r¶   ‹  rÁ   z_Parser.MergeLinesc                 C   sP   t jrdd„ |D ƒ}ndd„ |D ƒ}t|ƒ}| ¡ s&|  ||¡ | ¡ rdS dS )zü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.
    c                 s   ó(   � | ]}t |tƒr|n| d ¡V  qdS ©r2   N)r3   r   r5   ©Ú.0r   r   r   r   Ú	<genexpr>�  ó   €  ÿz(_Parser._ParseOrMerge.<locals>.<genexpr>c                 s   rÂ   rÃ   )r3   r   ÚdecoderÄ   r   r   r   rÆ      rÇ   N)r+   r,   Ú	TokenizerÚAtEndÚ_MergeField)r   rº   r   Ú	str_linesÚ	tokenizerr   r   r   r¿   ‘  s   ÿÿÿz_Parser._ParseOrMergec                 C   sL  |j }|jtkr`| d¡r`|  |¡\}}| d¡ | d¡ | d¡r&d}n| d¡ d}t|| jƒ}|s;td| ƒ‚| |¡sW| 	¡ rL| 
d	|f ¡‚|  ||¡ | |¡r@|j||d
� dS | d¡rµ| ¡ g}| d¡r{| | ¡ ¡ | d¡sod |¡}|js‹| 
d|j ¡‚|j |¡}	|	s | jr™d}	n| 
d| ¡‚||	jkr¯| 
d||jf ¡‚| d¡ nb| ¡ }| jrÙ| ¡ rÙt|ddƒ}
|j |
d¡}	|	sØ|jrØ|j |
¡}	n1|j |d¡}	|	sö|j | ¡ d¡}	|	rö|	jtj j!kröd}	|	�r
|	jtj j!k�r
|	j"j#|k�r
d}	|	�s| 
d|j|f ¡‚|	�r�| j$�sC|	j%�rC| &|	j%j#¡}|du�rC||	j#k�rC| 
d|	j#||	j%j#|jf ¡‚|	j'tj j(k�rT| d¡ | j)}n| d¡ | j*}|	j+tj j,k�r†| d¡�r†| d¡�s…	 ||||	ƒ | d¡�r~n| d¡ �qqn||||	ƒ n
| j�s“J ‚t-|ƒ | d¡�s¤| d¡ dS dS )zþ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.
    rŒ   r�   rŽ   r›   rœ   r�   rž   z$Type %s not found in descriptor poolúExpected "%s".)Útype_url_prefixNÚ.z+Message type "%s" does not have extensions.zþExtension "%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".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".ú,ú;).r|   r}   r~   Ú
TryConsumeÚ_ConsumeAnyTypeUrlÚConsumerj   rD   r   rÊ   ÚParseErrorPreviousTokenrË   ÚPackÚConsumeIdentifierÚappendÚjoinÚis_extendableÚ
ExtensionsÚ_FindExtensionByNamer´   r�   ÚConsumeIdentifierOrNumberrµ   ÚisdigitÚParseIntegerÚfields_by_numberrL   Ú_FindExtensionByNumberÚfields_by_nameÚlowerrP   r   rQ   r’   rS   r“   r¾   Úcontaining_oneofÚ
WhichOneofr…   r†   Ú_MergeMessageFieldÚ_MergeScalarFieldrƒ   r„   Ú_SkipFieldContents)r   rÍ   r   ri   rÏ   Úpacked_type_nameÚexpanded_any_end_tokenÚexpanded_any_sub_messager“   rW   rw   Úwhich_oneofÚmergerr   r   r   rË   ¦  sÞ   

ÿ



ÿÿ
ÿ
üÿ



ÿ
ÿÿüÿ
ÿÿ
€ÿÿÿþÿ

ÿ
ü€ÿz_Parser._MergeFieldc                 C   s„   |  ¡ g}| d¡ | |  ¡ ¡ | d¡ | |  ¡ ¡ | d¡ |  ¡ g}| d¡r8| |  ¡ ¡ | d¡s,d |¡d |¡fS )zBConsumes a google.protobuf.Any type URL and returns the type name.rÐ   rk   )rØ   rÕ   rÙ   rÓ   rÚ   )r   rÍ   Úprefixr“   r   r   r   rÔ   ,  s   






ÿz_Parser._ConsumeAnyTypeUrlc           	      C   s€  t |ƒ}| d¡rd}n| d¡ d}|jtjjkr:|jr%|j|  	¡ }nQ|r1t
||jƒ ¡ ƒ }nEt
||jƒ 	¡ }n<|jrW| jsQ| |¡rQ| d|jj|jf ¡‚|j| }n| jsl| |j¡rl| d|jj|jf ¡‚t
||jƒ}| ¡  | |¡s’| ¡ r‡| d|f ¡‚|  ||¡ | |¡r{|r¾|jjd j}|tjjkr²t
||jƒ|j }| |j¡ d	S |jt
||jƒ|j< d	S 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.
    r›   rœ   r�   rž   ú;Message type "%s" should not have multiple "%s" extensions.ú7Message type "%s" should not have multiple "%s" fields.rÎ   r]   N)rX   rÓ   rÕ   rƒ   r   rQ   r„   rv   rÜ   ÚaddÚgetattrr“   r‚   r¾   ÚHasExtensionrÖ   r|   r}   ÚHasFieldÚSetInParentrÊ   rË   rS   rã   r…   r†   r{   Ú	MergeFromr]   )	r   rÍ   r   rW   Úis_map_entryÚ	end_tokenÚsub_messageÚvalue_cpptyper]   r   r   r   rç   ;  sV   

ÿÿÿ
ÿÿÿ

ýúz_Parser._MergeMessageFieldc                 C   s   | j }t|dƒo|jdkS )NÚsyntaxÚproto3)r|   Úhasattrrü   )r   ri   r   r   r   Ú_IsProto3Syntaxu  s   
ÿz_Parser._IsProto3Syntaxc                 C   s
  | j }d}|jtjjtjjtjjfv rt|ƒ}n{|jtjjtjj	tjj
fv r+t|ƒ}nh|jtjjtjjfv r;t|ƒ}nX|jtjjtjjfv rKt|ƒ}nH|jtjjtjjfv r[| ¡ }n8|jtjjkrg| ¡ }n,|jtjjkrs| ¡ }n |jtjjkr| ¡ }n|jtjjkrŒ| |¡}ntd|j ƒ‚|jtjjkr²|j r§|j!|  "|¡ dS t#||j$ƒ "|¡ dS |j rÕ| j%sÎ|  &|¡sÎ| '|¡rÎ| (d|j)j*|j*f ¡‚||j!|< dS d}| j%sî|  &|¡rèt+t#||j$ƒƒ}n| ,|j$¡}|rü| (d|j)j*|j$f ¡‚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 %drð   Frñ   ).r´   rP   r   rQ   Ú
TYPE_INT32ÚTYPE_SINT32ÚTYPE_SFIXED32Ú_ConsumeInt32Ú
TYPE_INT64ÚTYPE_SINT64ÚTYPE_SFIXED64Ú_ConsumeInt64ÚTYPE_UINT32ÚTYPE_FIXED32Ú_ConsumeUint32ÚTYPE_UINT64ÚTYPE_FIXED64Ú_ConsumeUint64Ú
TYPE_FLOATÚTYPE_DOUBLEÚConsumeFloatÚ	TYPE_BOOLÚConsumeBoolÚTYPE_STRINGÚConsumeStringr§   ÚConsumeByteStringÚ	TYPE_ENUMÚConsumeEnumÚRuntimeErrorrƒ   r„   rv   rÜ   rÙ   ró   r“   r¾   rÿ   rô   rÖ   r|   r}   Úboolrõ   Úsetattr)r   rÍ   r   rW   Ú_r]   Úduplicate_errorr   r   r   rè   {  sz   
þ

þ

ÿ

ÿ

ÿ



ÿþÿÿ
ÿÿz_Parser._MergeScalarField©FFN)r   r   r   r   r   r±   r¶   r¿   rË   rÔ   rç   Ústaticmethodrÿ   rè   r   r   r   r   r¸   z  s     
ý :
r¸   c                 C   s6   |   d¡r|  d¡s|  d¡st| ƒ dS 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Ž   r�   r›   N)rÓ   Ú	LookingAtÚ_SkipFieldValueÚ_SkipFieldMessage©rÍ   r   r   r   ré   Ç  s   ÿÿré   c                 C   sf   |   d¡r|  ¡  |   d¡r|  ¡  |   d¡s|  d¡ n|  ¡  t| ƒ |   d¡s1|   d¡ dS dS )z€Skips 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   r   Ú
_SkipFieldÚ  s   


ÿ
ÿr#  c                 C   s\   |   d¡rd}n|  d¡ d}|  d¡s'|  d¡s't| ƒ |  d¡s'|  d¡r|  |¡ dS )zfSkips over a field message.

  Args:
    tokenizer: A tokenizer to parse the field name and values.
  r›   rœ   r�   rž   N)rÓ   rÕ   r  r#  )rÍ   Ú	delimiterr   r   r   r!  ñ  s   

ÿr!  c                 C   s\   |   ¡ r|   ¡ r	 |   ¡ sdS |  ¡ s&t| ƒs(t| ƒs*|  ¡ s,td| j ƒ‚dS dS dS dS )z¨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.
  NzInvalid field value: )ÚTryConsumeByteStringÚTryConsumeIdentifierÚ_TryConsumeInt64Ú_TryConsumeUint64ÚTryConsumeFloatr   Útokenr"  r   r   r   r     s   ÿÿÿþýr   c                   @   sH  e Zd ZdZe d¡Ze dej¡Ze dej¡Z	e d 
ddgdd	„ eD ƒ ¡¡Ze d
¡Ze 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É   zÍ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.
  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 )z0{qt}[^{qt}\n\\]*((\\.)+[^{qt}\n\\]*)*({qt}|\\?$))Úqt)r   )rÅ   Ú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| _
|| _|r(| jp*| j| _|  ¡  |  ¡  d S )Nr   r–   Ú T)Ú	_positionr   r   Ú_token_startr*  ÚiterÚ_linesÚ_current_lineÚ_previous_lineÚ_previous_columnÚ_more_linesÚ_skip_commentsÚ_WHITESPACE_OR_COMMENTÚ_WHITESPACEÚ_whitespace_patternÚ_SkipWhitespaceÚ	NextToken)r   rº   Úskip_commentsr   r   r   r   2  s    

ÿzTokenizer.__init__c                 C   s
   | j |kS r$   ©r*  ©r   r*  r   r   r   r  C  r:   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Ê   F  s   zTokenizer.AtEndc                 C   sn   t | jƒ| jkr5zt| jƒ| _W n ty    d| _d| _Y d S w |  jd7  _d| _t | jƒ| jksd S d S )Nr/  Fr•   r   )r™   r4  r   Únextr3  ÚStopIterationr7  r   r%   r   r   r   Ú_PopLineN  s   ý÷zTokenizer._PopLinec                 C   sB   	 |   ¡  | j | j| j¡}|sd S t| d¡ƒ}|  j|7  _q)NTr   )rC  r;  Úmatchr4  r   r™   Úgroup)r   rD  Úlengthr   r   r   r<  Z  s   úzTokenizer._SkipWhitespacec                 C   s   | j |kr|  ¡  dS dS )z‰Tries 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Ó   c  s   
	zTokenizer.TryConsumec                 C   s   |   |¡s|  d| ¡‚dS )zˆConsumes a piece of text.

    Args:
      token: Text to consume.

    Raises:
      ParseError: If the text couldn't be consumed.
    rÎ   N)rÓ   r   r@  r   r   r   rÕ   q  s   
	ÿzTokenizer.Consumec                 C   ó(   | j }| j |¡s|  d¡‚|  ¡  |S )NzExpected comment.)r*  Ú_COMMENTrD  r   r=  ©r   rI   r   r   r   ÚConsumeComment}  s
   
zTokenizer.ConsumeCommentc                 C   s:   | j dko	| jdk}| j}|  ¡ }| j|ko| }||fS )zCConsumes a comment, returns a 2-tuple (trailing bool, comment str).r   )r   r   r5  rJ  )r   Újust_startedÚbefore_parsingÚcommentÚtrailingr   r   r   ÚConsumeCommentOrTrailingComment„  s   
ÿz)Tokenizer.ConsumeCommentOrTrailingCommentc                 C   ó$   z|   ¡  W dS  ty   Y dS w ©NTF)rØ   r   r%   r   r   r   r&  ”  ó   ÿzTokenizer.TryConsumeIdentifierc                 C   rG  )ú�Consumes protocol message field identifier.

    Returns:
      Identifier string.

    Raises:
      ParseError: If an identifier couldn't be consumed.
    zExpected identifier.)r*  Ú_IDENTIFIERrD  r   r=  rI  r   r   r   rØ   ›  s
   	
zTokenizer.ConsumeIdentifierc                 C   rP  rQ  )rÞ   r   r%   r   r   r   ÚTryConsumeIdentifierOrNumberª  rR  z&Tokenizer.TryConsumeIdentifierOrNumberc                 C   s,   | j }| j |¡s|  d| ¡‚|  ¡  |S )rS  z&Expected identifier or number, got %s.)r*  Ú_IDENTIFIER_OR_NUMBERrD  r   r=  rI  r   r   r   rÞ   ±  s
   	z#Tokenizer.ConsumeIdentifierOrNumberc                 C   rP  rQ  )ÚConsumeIntegerr   r%   r   r   r   ÚTryConsumeIntegerÀ  s   ÿzTokenizer.TryConsumeIntegerFc              
   C   sF   z	t | j|d�}W n ty } z|  t|ƒ¡‚d}~ww |  ¡  |S )zÜ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.
    ©Úis_longN)Ú_ParseAbstractIntegerr*  Ú
ValueErrorr   r   r=  )r   rZ  rI   Úer   r   r   rW  È  s   €ÿzTokenizer.ConsumeIntegerc                 C   rP  rQ  )r  r   r%   r   r   r   r)  Ú  rR  zTokenizer.TryConsumeFloatc              
   C   óB   zt | jƒ}W n ty } z|  t|ƒ¡‚d}~ww |  ¡  |S )zžConsumes 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   rI   r]  r   r   r   r  á  ó   	€ÿzTokenizer.ConsumeFloatc              
   C   r^  )z‹Consumes 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  ñ  ra  zTokenizer.ConsumeBoolc                 C   rP  rQ  )r  r   r%   r   r   r   r%    rR  zTokenizer.TryConsumeByteStringc              
   C   s:   |   ¡ }zt |d¡W S  ty } z|  |¡‚d}~ww )z‹Consumes a string value.

    Returns:
      The string parsed.

    Raises:
      ParseError: If a string value couldn't be consumed.
    r2   N)r  r+   r4   ÚUnicodeDecodeErrorÚ_StringParseError)r   Ú	the_bytesr]  r   r   r   r    s   	
€ÿzTokenizer.ConsumeStringc                 C   sJ   |   ¡ g}| jr | jd tv r | |   ¡ ¡ | jr | jd tv sd |¡S )z Consumes 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   Úthe_listr   r   r   r    s
   
	ÿ
zTokenizer.ConsumeByteStringc              
   C   s¤   | j }t|ƒdk s|d tvr|  d|f ¡‚t|ƒdk s%|d |d kr-|  d|f ¡‚zt |dd… ¡}W n tyK } z|  t|ƒ¡‚d}~ww |  ¡  |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: %rrŸ   r–   zString missing ending quote: %rN)	r*  r™   rh  r   r   Ú	CUnescaper\  r   r=  )r   rN   rI   r]  r   r   r   rg  %  s   €ÿz"Tokenizer._ConsumeSingleByteStringc              
   C   sD   zt || jƒ}W n ty } z|  t|ƒ¡‚d }~ww |  ¡  |S r$   )Ú	ParseEnumr*  r\  r   r   r=  )r   rW   rI   r]  r   r   r   r  ?  s   €ÿzTokenizer.ConsumeEnumc                 C   s   t || jd | jd ƒS )z¯Creates and *returns* a ParseError for the previously read token.

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

    Returns:
      A ParseError instance.
    r•   )r   r5  r6  ©r   r   r   r   r   rÖ   G  s   	ÿz!Tokenizer.ParseErrorPreviousTokenc                 C   s&   t d| j d | | jd | jd ƒS )z9Creates and *returns* a ParseError for the current token.r   z': r•   )r   r4  r   r   rl  r   r   r   r   S  s   ÿzTokenizer.ParseErrorc                 C   s   |   dt|ƒ ¡S )NzCouldn't parse string: )r   r   )r   r]  r   r   r   rd  X  s   zTokenizer._StringParseErrorc                 C   s”   | j | _| j| _|  jt| jƒ7  _|  ¡  | jsd| _dS | j 	| j
| j¡}|s5| js5| j 	| j
| j¡}|rA| d¡}|| _dS | j
| j | _dS )z Reads the next meaningful token.r/  Nr   )r   r5  r   r6  r™   r*  r<  r7  Ú_TOKENrD  r4  r8  rH  rE  )r   rD  r*  r   r   r   r=  [  s   


zTokenizer.NextTokenN)T©F)*r   r   r   r   ÚreÚcompiler:  Ú	MULTILINErH  r9  rÚ   rh  rm  rT  rV  r   r  rÊ   rC  r<  rÓ   rÕ   rJ  rO  r&  rØ   rU  rÞ   rX  rW  r)  r  r  r%  r  r  rg  r  rÖ   r   rd  r=  r   r   r   r   rÉ     sT    
þýý
	

	
rÉ   c                 C   ó   t | ddd�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.
  TF©Ú	is_signedrZ  ©Ú_ConsumeIntegerr"  r   r   r   r  u  ó   r  c                 C   ó   t | ddd�S )zì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.
  Frt  rv  r"  r   r   r   r
  „  rx  r
  c                 C   ó$   zt | ƒ W dS  ty   Y dS w rQ  )r  r   r"  r   r   r   r'  “  rR  r'  c                 C   ry  )rs  Trt  rv  r"  r   r   r   r  ›  rx  r  c                 C   rz  rQ  )r  r   r"  r   r   r   r(  ª  rR  r(  c                 C   rr  )zì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.
  FTrt  rv  r"  r   r   r   r  ²  rx  r  c                 C   s*   z
t | ||d� W dS  ty   Y dS w )Nrt  TF)rw  r   )rÍ   ru  rZ  r   r   r   Ú_TryConsumeIntegerÁ  s   ÿr{  c              
   C   sH   z
t | j||d�}W n ty } z|  t|ƒ¡‚d}~ww |  ¡  |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.
  rt  N)rà   r*  r\  r   r   r=  )rÍ   ru  rZ  rI   r]  r   r   r   rw  É  s   €ÿrw  c                 C   s2   t | |d�}tdt|ƒ t|ƒ  }| |¡ |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.
  rY  rŸ   )r[  Ú_INTEGER_CHECKERSÚintÚ
CheckValue)rN   ru  rZ  rI   Úcheckerr   r   r   rà   ß  s   
rà   c                 C   sd   | }t  d| ¡}|r| d¡d | d¡ } z|rt| dƒW S t| dƒW S  ty1   td| ƒ‚w )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.
  z(-?)0(\d+)$r•   Ú0orŸ   r   zCouldn't parse integer: %s)ro  rD  rE  Úlongr}  r\  )rN   rZ  Ú	orig_textÚc_octal_matchr   r   r   r[  ö  s   ÿr[  c                 C   sŽ   zt | ƒW S  tyF   t | ¡r#| d dkrt dƒ Y S t dƒ Y S t | ¡r.t dƒ Y S z
t |  d¡ƒW  Y S  tyE   td|  ƒ‚w w )z°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.
  r   ú-z-infÚinfÚnanÚfzCouldn't parse float: %s)Úfloatr\  Ú_FLOAT_INFINITYrD  Ú
_FLOAT_NANr=   ©rN   r   r   r   r_    s   


ÿór_  c                 C   s    | dv rdS | dv rdS t dƒ‚)zœParse a boolean value.

  Args:
    text: Text to parse.

  Returns:
    Boolean values parsed

  Raises:
    ValueError: If text is not a valid boolean.
  )r¢   ÚtÚ1ÚTrueT)r£   r‡  Ú0ÚFalseFzExpected "true" or "false".)r\  r‹  r   r   r   rb  6  s
   rb  c                 C   sž   | j }zt|dƒ}W n ty)   |j |d¡}|du r%td|j|f ƒ‚Y |j
S w t| jdƒr8| jjdkr8|S |j	 |d¡}|du rLt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.)r¥   r}  r\  Úvalues_by_namerL   r}   rþ   Úfilerü   r¦   rw   )rW   r]   Úenum_descriptorrw   r«   r   r   r   rk  J  s*   ÿÿïÿrk  )
FFFFFNFNr   Nr®   )r   FFFFFNNr  )FFrn  )Cr   Ú
__author__r-   ro  r+   ÚPY3r}  r�  Úgoogle.protobuf.internalr   ra   r   r   Ú__all__ÚUint32ValueCheckerÚInt32ValueCheckerÚUint64ValueCheckerÚInt64ValueCheckerr|  rp  Ú
IGNORECASEr‰  rŠ  Ú	frozensetrQ   ÚCPPTYPE_FLOATÚCPPTYPE_DOUBLErª   rh  r~   Ú	Exceptionr   r   Úobjectr*   r   r   rX   r   r   r	   rj   r<   r   r
   r±   r¶   r¸   ré   r#  r!  r   rÉ   Ú
_Tokenizerr  r
  r'  r  r(  r  r{  rw  rà   r[  r_  rb  rk  r   r   r   r   Ú<module>   sÞ   ýÿ
ö:

õ
ö
ö c
ü.
ü"
ü
ü  O  Z



  