o
    Ñ­jIˆ  ã                   @   sô  d Z dZddlZddlmZ ddlZddlZddlmZ ddl	Z	ddl
mZ ddlmZ ddlmZ dd	lmZ eejjejjejjejjgƒZeejjejjgƒZeejjejjgƒZd
ZdZdZe	 d¡Ze	 d¡Z G dd„ de!ƒZ"G dd„ de"ƒZ#G dd„ de"ƒZ$								d@dd„Z%					dAdd„Z&dd„ Z'G dd„ de(ƒZ)d d!„ Z*d"d#„ Z+d$d%„ Z,			&dBd'd(„Z-			&dBd)d*„Z.e/e0fZ1G d+d,„ d,e(ƒZ2dCd-d.„Z3d/d0„ Z4d1d2„ Z5d3d4„ Z6d5d6gd7d8gd7d8gd9d:gd;d<gd7d8gd=d>gd?œZ7dS )Dat  Contains routines for printing protocol messages in JSON format.

Simple usage example:

  # Create a proto object and serialize it to a json format string.
  message = my_proto_pb2.MyMessage(foo='bar')
  json_string = json_format.MessageToJson(message)

  # Parse a json format string to proto object.
  message = json_format.Parse(json_string, my_proto_pb2.MyMessage())
zjieluo@google.com (Jie Luo)é    N)ÚOrderedDict)Úmethodcaller)Útype_checkers)Ú
descriptor)Úmessage_factory)Úsymbol_databaseÚInfinityz	-InfinityÚNaNu.   [í €-í¯¿](?![í°€-í¿¿])|(?<![í €-í¯¿])[í°€-í¿¿]z\[[a-zA-Z0-9\._]*\]$c                   @   ó   e Zd ZdZdS )ÚErrorz'Top-level module error for json_format.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úX/var/www/html/CropPilot/venv/lib/python3.10/site-packages/google/protobuf/json_format.pyr   6   ó    r   c                   @   r
   )ÚSerializeToJsonErrorz&Thrown if serialization to JSON fails.Nr   r   r   r   r   r   :   r   r   c                   @   r
   )Ú
ParseErrorz Thrown in case of parsing error.Nr   r   r   r   r   r   >   r   r   Fé   Tc	           
      C   s"   t |||||d�}	|	 | |||¡S )a  Converts protobuf message to JSON format.

  Args:
    message: The protocol buffers message instance to serialize.
    including_default_value_fields: If True, singular primitive fields,
        repeated fields, and map fields will always be serialized.  If
        False, only serialize non-empty fields.  Singular message fields
        and oneof fields are not affected by this option.
    preserving_proto_field_name: If True, use the original proto field
        names as defined in the .proto file. If False, convert the field
        names to lowerCamelCase.
    indent: The JSON object will be pretty-printed with this indent level.
        An indent level of 0 or negative will only insert newlines. If the
        indent level is None, no newlines will be inserted.
    sort_keys: If True, then the output will be sorted by field names.
    use_integers_for_enums: If true, print integers instead of enum names.
    descriptor_pool: A Descriptor Pool for resolving types. If None use the
        default.
    float_precision: If set, use this to specify float field valid digits.
    ensure_ascii: If True, strings with non-ASCII characters are escaped.
        If False, Unicode strings are returned unchanged.

  Returns:
    A string containing the JSON formatted protocol buffer message.
  ©Úfloat_precision)Ú_PrinterÚToJsonString)
ÚmessageÚincluding_default_value_fieldsÚpreserving_proto_field_nameÚindentÚ	sort_keysÚuse_integers_for_enumsÚdescriptor_poolr   Úensure_asciiÚprinterr   r   r   ÚMessageToJsonB   s   #ûr$   c                 C   s   t |||||d�}| | ¡S )a¿  Converts protobuf message to a dictionary.

  When the dictionary is encoded to JSON, it conforms to proto3 JSON spec.

  Args:
    message: The protocol buffers message instance to serialize.
    including_default_value_fields: If True, singular primitive fields,
        repeated fields, and map fields will always be serialized.  If
        False, only serialize non-empty fields.  Singular message fields
        and oneof fields are not affected by this option.
    preserving_proto_field_name: If True, use the original proto field
        names as defined in the .proto file. If False, convert the field
        names to lowerCamelCase.
    use_integers_for_enums: If true, print integers instead of enum names.
    descriptor_pool: A Descriptor Pool for resolving types. If None use the
        default.
    float_precision: If set, use this to specify float field valid digits.

  Returns:
    A dict representation of the protocol buffer message.
  r   )r   Ú_MessageToJsonObject)r   r   r   r    r!   r   r#   r   r   r   ÚMessageToDictn   s   û
r&   c                 C   s"   | j tjjko| jjo| j ¡ jS ©N)Útyper   ÚFieldDescriptorÚTYPE_MESSAGEÚmessage_typeÚhas_optionsÚ
GetOptionsÚ	map_entry)Úfieldr   r   r   Ú_IsMapEntry”   s
   ÿ
þr0   c                   @   st   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d„ Zdd„ ZdS )r   z)JSON format printer for protocol message.FNc                 C   s6   || _ || _|| _|| _|rd |¡| _d S d | _d S )Nz.{}g)r   r   r    r!   ÚformatÚfloat_format)Úselfr   r   r    r!   r   r   r   r   Ú__init__�   s   
z_Printer.__init__c                 C   s   |   |¡}tj||||d�S )N)r   r   r"   )r%   ÚjsonÚdumps)r3   r   r   r   r"   Újsr   r   r   r   ­   s   
ÿz_Printer.ToJsonStringc                 C   sL   |j }|j}t|ƒr|  |¡S |tv rtt| d |ƒ| ƒS i }|  ||¡S )zEConverts message to an object according to Proto3 JSON Specification.r   )Ú
DESCRIPTORÚ	full_nameÚ_IsWrapperMessageÚ_WrapperMessageToJsonObjectÚ_WKTJSONMETHODSr   Ú_RegularMessageToJsonObject)r3   r   Úmessage_descriptorr9   r7   r   r   r   r%   ²   s   
z_Printer._MessageToJsonObjectc              
      s¶  |  ¡ }zÀ|D ]l\‰ }ˆjrˆ j}nˆ j}tˆ ƒrFˆ jjd }i }|D ]}t|tƒr2|r/d}	nd}	nt	|ƒ}	ˆ 
||| ¡||	< q#|||< qˆ jtjjkrZ‡ ‡fdd„|D ƒ||< qˆ jrkdˆ j }ˆ 
ˆ |¡||< qˆ 
ˆ |¡||< qˆjr¿|j}
|
jD ]D‰ ˆ jtjjkr�ˆ jtjjks�ˆ jr‘q}ˆjr˜ˆ j}nˆ j}||v r q}tˆ ƒr©i ||< q}ˆ jtjjkrµg ||< q}ˆ 
ˆ ˆ j¡||< q}W |S W |S  tyÚ } z
td ˆ j|¡ƒ|‚d}~ww )	z?Converts normal message according to Proto3 JSON Specification.ÚvalueÚtrueÚfalsec                    s   g | ]}ˆ  ˆ |¡‘qS r   )Ú_FieldToJsonObject)Ú.0Úk©r/   r3   r   r   Ú
<listcomp>Ø   s    ÿz8_Printer._RegularMessageToJsonObject.<locals>.<listcomp>z[%s]z#Failed to serialize {0} field: {1}.N)Ú
ListFieldsr   ÚnameÚ	json_namer0   r+   Úfields_by_nameÚ
isinstanceÚboolÚstrrB   Úlabelr   r)   ÚLABEL_REPEATEDÚis_extensionr9   r   r8   ÚfieldsÚcpp_typeÚCPPTYPE_MESSAGEÚcontaining_oneofÚdefault_valueÚ
ValueErrorr   r1   )r3   r   r7   rQ   r?   rH   Úv_fieldÚjs_mapÚkeyÚrecorded_keyr>   Úer   rE   r   r=   ½   sr   

ÿ
ÿ

ÿ

ìèüÿÿ€ÿz$_Printer._RegularMessageToJsonObjectc                 C   s.  |j tjjkr|  |¡S |j tjjkr9| jr|S |jjdkr dS |jj	 
|d¡}|dur/|jS |jjr7tdƒ‚|S |j tjjkrQ|jtjjkrOt |¡ d¡S |S |j tjjkr\t|ƒS |j tv ret|ƒS |j tv r•t |¡rw|dk rutS tS t |¡r~tS |j tjjkr•| j r�t!t"|| j ƒƒS t# $|¡S |S )z<Converts field value according to Proto3 JSON Specification.úgoogle.protobuf.NullValueNzKEnum field contains an integer value which can not mapped to an enum value.úutf-8g        )%rR   r   r)   rS   r%   ÚCPPTYPE_ENUMr    Ú	enum_typer9   Úvalues_by_numberÚgetrH   Ú	is_closedr   ÚCPPTYPE_STRINGr(   Ú
TYPE_BYTESÚbase64Ú	b64encodeÚdecodeÚCPPTYPE_BOOLrL   Ú_INT64_TYPESrM   Ú_FLOAT_TYPESÚmathÚisinfÚ_NEG_INFINITYÚ	_INFINITYÚisnanÚ_NANÚCPPTYPE_FLOATr2   Úfloatr1   r   ÚToShortestFloat)r3   r/   r?   Ú
enum_valuer   r   r   rB   ý   sB   





z_Printer._FieldToJsonObjectc                 C   s�   |  ¡ si S tƒ }|j}||d< t|| jƒ}| |j¡ |j}|j}t	|ƒr/|  
|¡|d< |S |tv rBtt| d |ƒ| ƒ|d< |S |  ||¡S )z<Converts Any message according to Proto3 JSON Specification.ú@typer?   r   )rG   r   Útype_urlÚ_CreateMessageFromTypeUrlr!   ÚParseFromStringr?   r8   r9   r:   r;   r<   r   r=   )r3   r   r7   rv   Úsub_messager>   r9   r   r   r   Ú_AnyMessageToJsonObject)  s(   ÿÿz _Printer._AnyMessageToJsonObjectc                 C   s   |  ¡ S )z8Converts message according to Proto3 JSON Specification.)r   ©r3   r   r   r   r   Ú_GenericMessageToJsonObject>  s   z$_Printer._GenericMessageToJsonObjectc                 C   sˆ   |  d¡}|du s|dkrdS |dkr|  |j¡S |dkr3|j}t |¡r)tdƒ‚t |¡r2tdƒ‚nt||ƒ}|j	j
| }|  ||¡S )z>Converts Value message according to Proto3 JSON Specification.ÚkindNÚ
null_valueÚ
list_valueÚnumber_valuezTFail to serialize Infinity for Value.number_value, which would parse as string_valuezOFail to serialize NaN for Value.number_value, which would parse as string_value)Ú
WhichOneofÚ_ListValueMessageToJsonObjectr   r€   rk   rl   rV   ro   Úgetattrr8   rJ   rB   )r3   r   Úwhichr?   Úoneof_descriptorr   r   r   Ú_ValueMessageToJsonObjectD  s   


ÿ
z"_Printer._ValueMessageToJsonObjectc                    s   ‡ fdd„|j D ƒS )zBConverts ListValue message according to Proto3 JSON Specification.c                    s   g | ]}ˆ   |¡‘qS r   )r†   )rC   r?   ©r3   r   r   rF   \  s    ÿz:_Printer._ListValueMessageToJsonObject.<locals>.<listcomp>)Úvaluesr{   r   r‡   r   r‚   Z  s   
ÿz&_Printer._ListValueMessageToJsonObjectc                 C   s*   |j }i }|D ]}|  || ¡||< q|S )z?Converts Struct message according to Proto3 JSON Specification.)rQ   r†   )r3   r   rQ   ÚretrY   r   r   r   Ú_StructMessageToJsonObject_  s
   z#_Printer._StructMessageToJsonObjectc                 C   s   |   |jjd |j¡S )Nr?   )rB   r8   rJ   r?   r{   r   r   r   r;   g  s   ÿz$_Printer._WrapperMessageToJsonObject©FFFNN)r   r   r   r   r4   r   r%   r=   rB   rz   r|   r†   r‚   rŠ   r;   r   r   r   r   r   š   s$    
ú@,r   c                 C   s   | j jdkS )Nzgoogle/protobuf/wrappers.proto)ÚfilerH   )r>   r   r   r   r:   l  s   r:   c                 C   s4   i }| D ]\}}||v rt d |¡ƒ‚|||< q|S )Nz'Failed to load JSON: duplicate key {0}.)r   r1   )r7   ÚresultrH   r?   r   r   r   Ú_DuplicateCheckerp  s   
rŽ   c              
   C   sp   t  ¡ }|du r|jn|}|  d¡d }z| |¡}W n ty/ } ztd | ¡ƒ|‚d}~ww t 	|¡}|ƒ S )z"Creates a message from a type URL.Nú/éÿÿÿÿz0Can not find message descriptor by type_url: {0})
r   ÚDefaultÚpoolÚsplitÚFindMessageTypeByNameÚKeyErrorÚ	TypeErrorr1   r   ÚGetMessageClass)rv   r!   Údbr’   Ú	type_namer>   r[   Úmessage_classr   r   r   rw   y  s   ÿþ€ÿ
rw   éd   c              
   C   sd   t | tƒs
|  d¡} z	tj| td�}W n ty) } z
td t|ƒ¡ƒ|‚d}~ww t	|||||ƒS )al  Parses a JSON representation of a protocol message into a message.

  Args:
    text: Message JSON representation.
    message: A protocol buffer message to merge into.
    ignore_unknown_fields: If True, do not raise errors for unknown fields.
    descriptor_pool: A Descriptor Pool for resolving types. If None use the
      default.
    max_recursion_depth: max recursion depth of JSON message to be
      deserialized. JSON messages over this depth will fail to be
      deserialized. Default value is 100.

  Returns:
    The same message passed as argument.

  Raises::
    ParseError: On JSON parsing problems.
  r]   )Úobject_pairs_hookzFailed to load JSON: {0}.N)
rK   rM   rg   r5   ÚloadsrŽ   rV   r   r1   Ú	ParseDict)Útextr   Úignore_unknown_fieldsr!   Úmax_recursion_depthr7   r[   r   r   r   ÚParseˆ  s   

€ÿ
ÿr¢   c                 C   s   t |||ƒ}| | |d¡ |S )a8  Parses a JSON dictionary representation into a message.

  Args:
    js_dict: Dict representation of a JSON message.
    message: A protocol buffer message to merge into.
    ignore_unknown_fields: If True, do not raise errors for unknown fields.
    descriptor_pool: A Descriptor Pool for resolving types. If None use the
      default.
    max_recursion_depth: max recursion depth of JSON message to be
      deserialized. JSON messages over this depth will fail to be
      deserialized. Default value is 100.

  Returns:
    The same message passed as argument.
  Ú )Ú_ParserÚConvertMessage)Újs_dictr   r    r!   r¡   Úparserr   r   r   rž   ©  s   rž   c                   @   s`   e Zd Z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S )r¤   z(JSON format parser for protocol message.c                 C   s   || _ || _|| _d| _d S )Nr   )r    r!   r¡   Úrecursion_depth)r3   r    r!   r¡   r   r   r   r4   È  s   
z_Parser.__init__c                 C   sœ   |  j d7  _ | j | jkrtd | j¡ƒ‚|j}|j}|s |j}t|ƒr,|  |||¡ n|t	v r>t
t	| d |||ƒ| ƒ n|  |||¡ |  j d8  _ dS )a  Convert a JSON object into a message.

    Args:
      value: A JSON object.
      message: A WKT or regular protocol message to record the data.
      path: parent path to log parse error info.

    Raises:
      ParseError: In case of convert problems.
    é   z,Message too deep. Max recursion depth is {0}N)r¨   r¡   r   r1   r8   r9   rH   r:   Ú_ConvertWrapperMessager<   r   Ú_ConvertFieldValuePair)r3   r?   r   Úpathr>   r9   r   r   r   r¥   Ï  s   ÿz_Parser.ConvertMessagec                 C   s2  g }|j }tdd„ |jD ƒƒ}|D �]}�z±| |d¡}|s%|j |d¡}|sXt |¡rX|js8td 	|j
|¡ƒ‚|dd… }	|j |	¡}|sXd |	 d¡dd… ¡}	|j |	¡}|sp| jr_W qtd 	|j
||d	d
„ |jD ƒ¡ƒ‚||v rtd 	|j j
||¡ƒ‚| |¡ || }
|jdur©|
dur©|jj}||v r¤td 	|j j
||¡ƒ‚| |¡ |
du rá|jtjjkrÄ|jj
dkrÄt||jƒ}d|_n|jtjjkrÙ|jj
dkrÙt||jdƒ n| |j¡ W qt|ƒrø| |j¡ |  |
||d 	||¡¡ nÍ|j tjj!k�r|| |j¡ t"|
t#ƒ�std 	||
|¡ƒ‚|jtjjk�rQt$|
ƒD ].\}}t||jƒ %¡ }|du �rB|j j
dk�rBtd 	|||¡ƒ‚|  &||d 	|||¡¡ �q!ntt$|
ƒD ]%\}}|du �rgtd 	|||¡ƒ‚t||jƒ t'||d 	|||¡ƒ¡ �qUnI|jtjjk�r¤|j(�rŽ|j| }nt||jƒ}| )¡  |  &|
|d 	||¡¡ n!|j(�r¶t'|
|d 	||¡ƒ|j|< nt||jt'|
|d 	||¡ƒƒ W q t�yì } z|�rá|jdu �rátd 	||¡ƒ|‚tt*|ƒƒ|‚d}~w t+�y } z	td 	||¡ƒ|‚d}~w t,�y } z	td 	||¡ƒ|‚d}~ww dS )a'  Convert field value pairs into regular message.

    Args:
      js: A JSON object to convert the field value pairs.
      message: A regular protocol message to record the data.
      path: parent path to log parse error info.

    Raises:
      ParseError: In case of problems converting.
    c                 s   s   � | ]}|j |fV  qd S r'   ©rI   ©rC   Úfr   r   r   Ú	<genexpr>÷  s   € ÿz1_Parser._ConvertFieldValuePair.<locals>.<genexpr>Nz0Message type {0} does not have extensions at {1}r©   r�   Ú.zaMessage type "{0}" has no field named "{1}" at "{2}".
 Available Fields(except extensions): "{3}"c                 S   s   g | ]}|j ‘qS r   r­   r®   r   r   r   rF     s    z2_Parser._ConvertFieldValuePair.<locals>.<listcomp>zBMessage type "{0}" should not have multiple "{1}" fields at "{2}".zHMessage type "{0}" should not have multiple "{1}" oneof fields at "{2}".úgoogle.protobuf.Valuer   r\   ú{0}.{1}z4repeated field {0} must be in [] which is {1} at {2}zPnull is not allowed to be used as an element in a repeated field at {0}.{1}[{2}]z{0}.{1}[{2}]zFailed to parse {0} field: {1}.)-r8   ÚdictrQ   ra   rJ   Ú_VALID_EXTENSION_NAMEÚmatchÚis_extendabler   r1   r9   Ú
ExtensionsÚ_FindExtensionByNameÚjoinr“   r    ÚappendrT   rH   rR   r   r)   rS   r+   rƒ   r~   r^   r_   ÚsetattrÚ
ClearFieldr0   Ú_ConvertMapFieldValuerN   rO   rK   ÚlistÚ	enumerateÚaddr¥   Ú_ConvertScalarFieldValuerP   ÚSetInParentrM   rV   r–   )r3   r7   r   r¬   Únamesr>   Úfields_by_json_namerH   r/   Ú
identifierr?   Ú
oneof_namery   ÚindexÚitemr[   r   r   r   r«   ê  s  ÿ
ÿÿþþ
ÿÿ
þÿ


ÿ
ÿ
ÿÿÿø
ÿÿÿÿûÿ
ÿþ€
ÿþ€
ÿþ€
ÿþ€ÿŒz_Parser._ConvertFieldValuePairc           	   
   C   s  t |tƒr	|s	dS z|d }W n ty# } ztd |¡ƒ|‚d}~ww zt|| jƒ}W n tyA } z	td ||¡ƒ|‚d}~ww |j}|j	}t
|ƒrY|  |d |d |¡¡ n%|tv rptt| d |d |d |¡ƒ| ƒ n|d= |  |||¡ ||d< | ¡ |_||_dS )z/Convert a JSON representation into Any message.Nru   z0@type is missing when parsing any message at {0}ú
{0} at {1}r?   ú	{0}.valuer©   )rK   r´   r•   r   r1   rw   r!   r–   r8   r9   r:   rª   r<   r   r«   ÚSerializeToStringr?   rv   )	r3   r?   r   r¬   rv   r[   ry   r>   r9   r   r   r   Ú_ConvertAnyMessager  sF   ÿþ€ÿ€ÿÿÿþ

z_Parser._ConvertAnyMessagec              
   C   s<   z|  |¡ W dS  ty } z	td ||¡ƒ|‚d}~ww )z?Convert a JSON representation into message with FromJsonString.rÊ   N)ÚFromJsonStringrV   r   r1   )r3   r?   r   r¬   r[   r   r   r   Ú_ConvertGenericMessage’  s   €ÿz_Parser._ConvertGenericMessagec                 C   s    t |tƒr|  ||j|¡ dS t |tƒr|  ||j|¡ dS |du r'd|_dS t |tƒr1||_	dS t |t
ƒr;||_dS t |tƒrE||_dS td |t|ƒ|¡ƒ‚)z1Convert a JSON representation into Value message.Nr   z(Value {0} has unexpected type {1} at {2})rK   r´   Ú_ConvertStructMessageÚstruct_valuer¿   Ú_ConvertListValueMessager   r~   rL   Ú
bool_valuerM   Ústring_valueÚ_INT_OR_FLOATr€   r   r1   r(   )r3   r?   r   r¬   r   r   r   Ú_ConvertValueMessage›  s   









ÿz_Parser._ConvertValueMessagec              	   C   sV   t |tƒstd ||¡ƒ‚| d¡ t|ƒD ]\}}|  ||j ¡ d ||¡¡ qdS )z5Convert a JSON representation into ListValue message.z+ListValue must be in [] which is {0} at {1}rˆ   ú{0}[{1}]N)	rK   r¿   r   r1   r½   rÀ   rÖ   rˆ   rÁ   )r3   r?   r   r¬   rÈ   rÉ   r   r   r   rÒ   ­  s   
ÿ

ÿÿz _Parser._ConvertListValueMessagec              	   C   sP   t |tƒstd ||¡ƒ‚| ¡  |D ]}|  || |j| d ||¡¡ qdS )z2Convert a JSON representation into Struct message.z,Struct must be in a dict which is {0} at {1}r³   N)rK   r´   r   r1   ÚClearrÖ   rQ   )r3   r?   r   r¬   rY   r   r   r   rÐ   ·  s   
ÿ
ÿz_Parser._ConvertStructMessagec              	   C   s,   |j jd }t|dt||d |¡d�ƒ dS )z3Convert a JSON representation into Wrapper message.r?   rË   ©r¬   N)r8   rJ   r¼   rÂ   r1   )r3   r?   r   r¬   r/   r   r   r   rª   Ä  s
   þz_Parser._ConvertWrapperMessagec           	   	   C   s´   t |tƒstd |j||¡ƒ‚|jjd }|jjd }|D ]:}t||d |¡dƒ}|jt	j
jkrD|  || t||jƒ| d ||¡¡ qt|| |d ||¡d�t||jƒ|< qdS )	af  Convert map field value for a message map field.

    Args:
      value: A JSON object to convert the map field value.
      message: A protocol message to record the converted data.
      field: The descriptor of the map field to be converted.
      path: parent path to log parse error info.

    Raises:
      ParseError: In case of convert problems.
    z3Map field {0} must be in a dict which is {1} at {2}rY   r?   z{0}.keyTr×   rÙ   N)rK   r´   r   r1   rH   r+   rJ   rÂ   rR   r   r)   rS   r¥   rƒ   )	r3   r?   r   r/   r¬   Ú	key_fieldÚvalue_fieldrY   Ú	key_valuer   r   r   r¾   Ë  s*   
ÿÿ
ÿ

þÿøz_Parser._ConvertMapFieldValueN)r   r   r   r   r4   r¥   r«   rÍ   rÏ   rÖ   rÒ   rÐ   rª   r¾   r   r   r   r   r¤   Å  s     	 	
r¤   c           	   
   C   sŒ  z°|j tv rt| ƒW S |j tv rt| |ƒW S |j tjjkr#t| |ƒW S |j tjj	kr\|j
tjjkrPt| tƒr<|  d¡}n| }|ddt|ƒd    }t |¡W S t | ¡rYtdƒ‚| W S |j tjjkr®|jj | d¡}|du rªzt| ƒ}|jj |d¡}W n ty” } ztd | |jj¡ƒ|‚d}~ww |du rª|jjr§td | |jj¡ƒ‚|W S |jW S W dS  tyÅ } z	td ||¡ƒ|‚d}~ww )aq  Convert a single scalar field value.

  Args:
    value: A scalar value to convert the scalar field value.
    field: The descriptor of the field to convert.
    path: parent path to log parse error info.
    require_str: If True, the field value must be a str.

  Returns:
    The converted scalar field value

  Raises:
    ParseError: In case of convert problems.
  r]   ó   =é   zUnpaired surrogateNz(Invalid enum value {0} for enum type {1}rÊ   ) rR   Ú
_INT_TYPESÚ_ConvertIntegerrj   Ú_ConvertFloatr   r)   rh   Ú_ConvertBoolrc   r(   rd   rK   rM   ÚencodeÚlenre   Úurlsafe_b64decodeÚ_UNPAIRED_SURROGATE_PATTERNÚsearchr   r^   r_   Úvalues_by_namera   Úintr`   rV   r1   r9   rb   Únumber)	r?   r/   r¬   Úrequire_strÚencodedÚpadded_valuert   rê   r[   r   r   r   rÂ   é  sV   




ÿÿ€ÿÿð€ÿrÂ   c                 C   sf   t | tƒr|  ¡ std | ¡ƒ‚t | tƒr#|  d¡dkr#td | ¡ƒ‚t | tƒr/td | ¡ƒ‚t| ƒS )z§Convert an integer.

  Args:
    value: A scalar value to convert.

  Returns:
    The integer value.

  Raises:
    ParseError: If an integer couldn't be consumed.
  zCouldn't parse integer: {0}ú r�   zCouldn't parse integer: "{0}"z2Bool value {0} is not acceptable for integer field)	rK   rr   Ú
is_integerr   r1   rM   ÚfindrL   ré   )r?   r   r   r   rà   #  s   
ÿrà   c              
   C   s  t | tƒr8t | ¡rtdƒ‚t | ¡r| dkrtdƒ‚tdƒ‚|jtjj	kr8| t
jkr/tdƒ‚| t
jk r8tdƒ‚| dkr@tdƒ‚zt| ƒW S  tyƒ } z2| tkr[td	ƒW  Y d
}~S | tkritdƒW  Y d
}~S | tkrwtdƒW  Y d
}~S td | ¡ƒ|‚d
}~ww )z!Convert an floating point number.z,Couldn't parse NaN, use quoted "NaN" insteadr   zICouldn't parse Infinity or value too large, use quoted "Infinity" insteadzKCouldn't parse -Infinity or value too small, use quoted "-Infinity" insteadzFloat value too largezFloat value too smallÚnanz-Couldn't parse float "nan", use "NaN" insteadz-infNÚinfzCouldn't parse float: {0})rK   rr   rk   ro   r   rl   rR   r   r)   rq   r   Ú
_FLOAT_MAXÚ
_FLOAT_MINrV   rm   rn   rp   r1   )r?   r/   r[   r   r   r   rá   <  s4   





€÷rá   c                 C   s@   |r| dkrdS | dkrdS t d | ¡ƒ‚t| tƒst dƒ‚| S )zÞConvert a boolean value.

  Args:
    value: A scalar value to convert.
    require_str: If True, value must be a str.

  Returns:
    The bool parsed.

  Raises:
    ParseError: If a boolean value couldn't be consumed.
  r@   TrA   Fz#Expected "true" or "false", not {0}z%Expected true or false without quotes)r   r1   rK   rL   )r?   rë   r   r   r   râ   `  s   
râ   rz   rÍ   r|   rÏ   r‚   rÒ   rŠ   rÐ   r†   rÖ   )zgoogle.protobuf.Anyzgoogle.protobuf.Durationzgoogle.protobuf.FieldMaskzgoogle.protobuf.ListValuezgoogle.protobuf.Structzgoogle.protobuf.Timestampr²   )FFr   FFNNTr‹   )FNr›   )F)8r   Ú
__author__re   Úcollectionsr   r5   rk   Úoperatorr   ÚreÚgoogle.protobuf.internalr   Úgoogle.protobufr   r   r   Ú	frozensetr)   ÚCPPTYPE_INT32ÚCPPTYPE_UINT32ÚCPPTYPE_INT64ÚCPPTYPE_UINT64rß   ri   rq   ÚCPPTYPE_DOUBLErj   rn   rm   rp   Úcompileræ   rµ   Ú	Exceptionr   r   r   r$   r&   r0   Úobjectr   r:   rŽ   rw   r¢   rž   ré   rr   rÕ   r¤   rÂ   rà   rá   râ   r<   r   r   r   r   Ú<module>   s¸   ýÿÿÿ

÷.
ú& S	
ü#
ü  
&:$ÿÿÿÿÿÿÿ
ó