HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/jmespath/__pycache__/parser.cpython-37.pyc
B

�P�e�J�@spdZddlZddlmZddlmZddlmZddlmZddlmZGdd	�d	e	�Z
eGd
d�de	��ZdS)a�Top down operator precedence parser.

This is an implementation of Vaughan R. Pratt's
"Top Down Operator Precedence" parser.
(http://dl.acm.org/citation.cfm?doid=512927.512931).

These are some additional resources that help explain the
general idea behind a Pratt parser:

* http://effbot.org/zone/simple-top-down-parsing.htm
* http://javascript.crockford.com/tdop/tdop.html

A few notes on the implementation.

* All the nud/led tokens are on the Parser class itself, and are dispatched
  using getattr().  This keeps all the parsing logic contained to a single
  class.
* We use two passes through the data.  One to create a list of token,
  then one pass through the tokens to create the AST.  While the lexer actually
  yields tokens, we convert it to a list so we can easily implement two tokens
  of lookahead.  A previous implementation used a fixed circular buffer, but it
  was significantly slower.  Also, the average jmespath expression typically
  does not have a large amount of token so this is not an issue.  And
  interestingly enough, creating a token list first is actually faster than
  consuming from the token iterator one token at a time.

�N)�lexer)�with_repr_method)�ast)�
exceptions)�visitorc@s�eZdZddddddddddddddddddddddddd	d
ddd
d�ZdZiZdZdxdd�Zdd�Zdd�Z	dd�Z
dydd�Zdd�Zdd�Z
dd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Zd?d@�ZdAdB�ZdCdD�Z dEdF�Z!dGdH�Z"dIdJ�Z#dKdL�Z$dMdN�Z%dOdP�Z&dQdR�Z'dSdT�Z(dUdV�Z)dWdX�Z*dYdZ�Z+d[d\�Z,d]d^�Z-d_d`�Z.dadb�Z/dzddde�Z0dfdg�Z1dhdi�Z2djdk�Z3dldm�Z4dndo�Z5dpdq�Z6drds�Z7dtdu�Z8e9dvdw��Z:dcS){�Parserr�����	���(�-�2�7�<)�eof�unquoted_identifier�quoted_identifier�literal�rbracket�rparen�comma�rbrace�number�current�expref�colon�pipe�or�and�eq�gt�lt�gte�lte�ne�flatten�star�filter�dot�not�lbrace�lbracket�lparen�
�cCs"d|_dg||_||_d|_dS)Nr)�	tokenizer�_tokensZ_buffer_size�_index)�self�	lookahead�r8�@/opt/alt/python37/lib/python3.7/site-packages/jmespath/parser.py�__init__NszParser.__init__cCsH|j�|�}|dk	r|S|�|�}||j|<t|j�|jkrD|��|S)N)�_CACHE�get�	_do_parse�len�	_MAX_SIZE�_free_cache_entries)r6�
expression�cached�
parsed_resultr8r8r9�parseTs

zParser.parsec
Cs�y
|�|�Stjk
r6}z||_�Wdd}~XYnZtjk
rd}z|�|��Wdd}~XYn,tjk
r�}z||_�Wdd}~XYnXdS)N)�_parserZ
LexerErrorrA�IncompleteExpressionErrorZset_expression�
ParseError)r6rA�er8r8r9r=^s

zParser._do_parsecCsrt���|�|_t|j�|_d|_|jdd�}|��dksh|�	d�}t
�|d|d|dd|d��t||�S)Nr)�
binding_powerr�start�value�typezUnexpected token: %s)
r�Lexer�tokenizer3�listr4r5�_expression�_current_token�_lookahead_tokenrrG�ParsedResult)r6rA�parsed�tr8r8r9rEks
z
Parser._parsecCs�|�d�}|��t|d|d|j�}||�}|��}xX||j|kr�t|d|d�}|dkrv|�d�}|�|�q:|��||�}|��}q:W|S)Nrz
_token_nud_%srLz
_token_led_%s)rR�_advance�getattr�_error_nud_tokenrQ�
BINDING_POWER�_error_led_token)r6rIZ
left_tokenZnud_function�left�
current_tokenZledZerror_tokenr8r8r9rPvs 

zParser._expressioncCst�|d�S)NrK)rr)r6�tokenr8r8r9�_token_nud_literal�szParser._token_nud_literalcCst�|d�S)NrK)r�field)r6r]r8r8r9�_token_nud_unquoted_identifier�sz%Parser._token_nud_unquoted_identifiercCs@t�|d�}|��dkr<|�d�}t�d|d|dd��|S)NrKr0rrLz1Quoted identifier not allowed for function names.)rr_rQrRrrG)r6r]r_rUr8r8r9�_token_nud_quoted_identifier�s
z#Parser._token_nud_quoted_identifiercCs:t��}|��dkrt��}n|�|jd�}t�||�S)Nrr*)r�identityrQ�_parse_projection_rhsrY�value_projection)r6r]r[�rightr8r8r9�_token_nud_star�s

zParser._token_nud_starcCs|�t���S)N)�_token_led_filterrrb)r6r]r8r8r9�_token_nud_filter�szParser._token_nud_filtercCs|��S)N)�_parse_multi_select_hash)r6r]r8r8r9�_token_nud_lbrace�szParser._token_nud_lbracecCs|��}|�d�|S)Nr)rP�_match)r6r]rAr8r8r9�_token_nud_lparen�s
zParser._token_nud_lparencCs*t�t���}|�|jd�}t�||�S)Nr))rr)rbrcrY�
projection)r6r]r[rer8r8r9�_token_nud_flatten�szParser._token_nud_flattencCs|�|jd�}t�|�S)Nr-)rPrYrZnot_expression)r6r]�exprr8r8r9�_token_nud_not�szParser._token_nud_notcCsz|��dkr$|��}|�t��|�S|��dkrn|�d�dkrn|��|��|�|jd�}t�	t��|�S|�
�SdS)N)rrr*rr)rQ�_parse_index_expression�_project_if_slicerrb�
_lookaheadrVrcrYrm�_parse_multi_select_list)r6r]rer8r8r9�_token_nud_lbracket�szParser._token_nud_lbracketcCsR|�d�dks|�d�dkr$|��St�|�d�d�}|��|�d�|SdS)NrrrrKr)rs�_parse_slice_expressionr�indexrRrVrk)r6�noder8r8r9rq�s
zParser._parse_index_expressioncCs�dddg}d}|��}x�|dks�|dkr�|dkr\|d7}|dkrR|�|�d�d�|��n6|dkr�|�d�d||<|��n|�|�d�d�|��}qW|�d�tj|�S)	Nrrr
rrzsyntax errorrrK)rQ�_raise_parse_error_for_tokenrRrVrkr�slice)r6�partsrwr\r8r8r9rv�s$



zParser._parse_slice_expressioncCst��S)N)rZcurrent_node)r6r]r8r8r9�_token_nud_current�szParser._token_nud_currentcCs|�|jd�}t�|�S)Nr)rPrYrr)r6r]rAr8r8r9�_token_nud_expref�szParser._token_nud_exprefcCsr|��dksJ|�|jd�}|ddkr:|d�|�|St�||g�Sn$|��|�|jd�}t�||�SdS)Nr*r,rL�
subexpression�children)	rQ�_parse_dot_rhsrY�appendrr~rVrcrd)r6r[rer8r8r9�_token_led_dot�szParser._token_led_dotcCs|�|jd�}t�||�S)Nr )rPrYrr )r6r[rer8r8r9�_token_led_pipeszParser._token_led_pipecCs|�|jd�}t�||�S)Nr!)rPrYrZ
or_expression)r6r[rer8r8r9�
_token_led_or	szParser._token_led_orcCs|�|jd�}t�||�S)Nr")rPrYrZand_expression)r6r[rer8r8r9�_token_led_and
szParser._token_led_andcCs�|ddkr:|�d�}t�|d|d|dd|d��|d}g}x8|��dks~|��}|��dkrr|�d�|�|�qHW|�d�t�||�}|S)	NrLr_���rJrKzInvalid function name '%s'rr)	rRrrGrQrPrkr�rZfunction_expression)r6r[Zprev_t�name�argsrAZ
function_noder8r8r9�_token_led_lparens


zParser._token_led_lparencCsH|�d�}|�d�|��dkr*t��}n|�|jd�}t�|||�S)Nrrr)r+)rPrkrQrrbrcrYZfilter_projection)r6r[�	conditionrer8r8r9rg%s


zParser._token_led_filtercCs|�|d�S)Nr#)�_parse_comparator)r6r[r8r8r9�
_token_led_eq/szParser._token_led_eqcCs|�|d�S)Nr()r�)r6r[r8r8r9�
_token_led_ne2szParser._token_led_necCs|�|d�S)Nr$)r�)r6r[r8r8r9�
_token_led_gt5szParser._token_led_gtcCs|�|d�S)Nr&)r�)r6r[r8r8r9�_token_led_gte8szParser._token_led_gtecCs|�|d�S)Nr%)r�)r6r[r8r8r9�
_token_led_lt;szParser._token_led_ltcCs|�|d�S)Nr')r�)r6r[r8r8r9�_token_led_lte>szParser._token_led_ltecCs&t�|�}|�|jd�}t�||�S)Nr))rr)rcrYrm)r6r[rer8r8r9�_token_led_flattenAs
zParser._token_led_flattencCs~|�d�}|ddkrJ|��}|ddkr<|d�|�|S|�||�Sn0|�d�|�d�|�|jd�}t�||�SdS)NrrL)rr�index_expressionrr*r)	rRrqr�rrrkrcrYrrm)r6r[r]rer8r8r9�_token_led_lbracketGs


zParser._token_led_lbracketcCs:t�||g�}|ddkr2t�||�|jd��S|SdS)NrLrzr*)rr�rmrcrY)r6r[reZ
index_exprr8r8r9rrZszParser._project_if_slicecCs|�|j|�}t�|||�S)N)rPrYr�
comparator)r6r[r�rer8r8r9r�cszParser._parse_comparatorcCsJg}x0|��}|�|�|��dkr(Pq|�d�qW|�d�t�|�S)Nrr)rPr�rQrkrZmulti_select_list)r6ZexpressionsrAr8r8r9rtgs

zParser._parse_multi_select_listcCs�g}x�|�d�}|jddgd�|d}|�d�|�d�}tj||d�}|�|�|��dkrl|�d�q|��d	kr|�d	�PqWtj|d
�S)Nrrr)�token_typesrKr)�key_namerxrr)Znodes)	rR�_match_multiple_tokensrkrPrZkey_val_pairr�rQZmulti_select_dict)r6�pairsZ	key_tokenr�rKrxr8r8r9riss 




zParser._parse_multi_select_hashcCs�|j|��|jkrt��}nd|��dkr6|�|�}nL|��dkrN|�|�}n4|��dkrp|�d�|�|�}n|�|�	d�d�|S)Nr/r+r,rzsyntax error)
rYrQ�_PROJECTION_STOPrrbrPrkr�ryrR)r6rIrer8r8r9rc�s

zParser._parse_projection_rhscCs�|��}|dkr|�|�S|dkr4|�d�|��S|dkrN|�d�|��S|�d�}ddddg}d||df}|�||�dS)	N)rrr*r/r.rrrzExpecting: %s, got: %srL)rQrPrkrtrirRry)r6rIr7rU�allowed�msgr8r8r9r��s	



zParser._parse_dot_rhscCs6|ddkr&t�|d|d|d��|�|d�dS)NrLrrJrKz
invalid token)rrFry)r6r]r8r8r9rX�szParser._error_nud_tokencCs|�|d�dS)Nz
invalid token)ry)r6r]r8r8r9rZ�szParser._error_led_tokenNcCs,|��|kr|��n|�||�d��dS)Nr)rQrV�_raise_parse_error_maybe_eofrR)r6�
token_typer8r8r9rk�s
z
Parser._matchcCs*|��|kr|�||�d��|��dS)Nr)rQr�rRrV)r6r�r8r8r9r��szParser._match_multiple_tokenscCs|jd7_dS)Nr)r5)r6r8r8r9rV�szParser._advancecCs|j|jdS)NrL)r4r5)r6r8r8r9rQ�szParser._current_tokencCs|j|j|dS)NrL)r4r5)r6rr8r8r9rs�szParser._lookaheadcCs|j|j|S)N)r4r5)r6rr8r8r9rR�szParser._lookahead_tokencCs,|d}|d}|d}t�||||��dS)NrJrKrL)rrG)r6r]�reason�lex_position�actual_value�actual_typer8r8r9ry�s
z#Parser._raise_parse_error_for_tokencCsN|d}|d}|d}|dkr.t�|||��d||f}t�||||��dS)NrJrKrLrzExpecting: %s, got: %s)rrFrG)r6�
expected_typer]r�r�r��messager8r8r9r��s
z#Parser._raise_parse_error_maybe_eofcCs<x6t�t|j���t|jd��D]}|j�|d�q"WdS)Nr	)�random�samplerOr;�keys�intr?�pop)r6�keyr8r8r9r@�s&zParser._free_cache_entriescCs|j��dS)z'Clear the expression compilation cache.N)r;�clear)�clsr8r8r9�purge�szParser.purge)r	)r)N);�__name__�
__module__�__qualname__rYr�r;r?r:rDr=rErPr^r`rarfrhrjrlrnrprurqrvr|r}r�r�r�r�r�rgr�r�r�r�r�r�r�r�rrr�rtrircr�rXrZrkr�rVrQrsrRryr�r@�classmethodr�r8r8r8r9r%s�




	
	rc@s.eZdZdd�Zd
dd�Zdd�Zdd	�ZdS)rScCs||_||_dS)N)rArT)r6rArTr8r8r9r:�szParsedResult.__init__NcCst�|�}|�|j|�}|S)N)rZTreeInterpreter�visitrT)r6rK�options�interpreter�resultr8r8r9�search�s
zParsedResult.searchcCst��}|�|j�}|S)afRender the parsed AST as a dot file.

        Note that this is marked as an internal method because
        the AST is an implementation detail and is subject
        to change.  This method can be used to help troubleshoot
        or for development purposes, but is not considered part
        of the public supported API.  Use at your own risk.

        )rZGraphvizVisitorr�rT)r6�renderer�contentsr8r8r9�_render_dot_files
zParsedResult._render_dot_filecCs
t|j�S)N)�reprrT)r6r8r8r9�__repr__szParsedResult.__repr__)N)r�r�r�r:r�r�r�r8r8r8r9rS�s
rS)�__doc__r��jmespathrZjmespath.compatrrrr�objectrrSr8r8r8r9�<module>sS