HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3.6/site-packages/jmespath/__pycache__/parser.cpython-36.pyc
3

g�V`M�@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�eZdZdddddddddddddddddddddddd	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/dcdd�Z0dedf�Z1dzdhdi�Z2djdk�Z3dldm�Z4dndo�Z5dpdq�Z6drds�Z7dtdu�Z8e9dvdw��Z:dgS){�Parserr�����	���(�-�2�7�<)�eof�unquoted_identifier�quoted_identifier�rbracket�rparen�comma�rbrace�numberZcurrent�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�r6�/usr/lib/python3.6/parser.py�__init__MszParser.__init__cCsH|jj|�}|dk	r|S|j|�}||j|<t|j�|jkrD|j�|S)N)�_CACHE�get�	_do_parse�len�	_MAX_SIZE�_free_cache_entries)r4�
expression�cachedZ
parsed_resultr6r6r7�parseSs

zParser.parsecCs�y
|j|�Stjk
r6}z||_�WYdd}~XnZtjk
rd}z|j|��WYdd}~Xn,tjk
r�}z||_�WYdd}~XnXdS)N)�_parserZ
LexerErrorr?�IncompleteExpressionErrorZset_expression�
ParseError)r4r?�er6r6r7r;]s

zParser._do_parsecCsrtj�j|�|_t|j�|_d|_|jdd�}|j�dksh|j	d�}t
j|d|d|dd|d��t||�S)Nr)�
binding_powerr�start�value�typezUnexpected token: %s)
rZLexer�tokenizer1�listr2r3�_expression�_current_token�_lookahead_tokenrrD�ParsedResult)r4r?�parsed�tr6r6r7rBjs
z
Parser._parsecCs�|jd�}|j�t|d|d|j�}||�}|j�}xX||j|kr�t|d|d�}|dkrv|jd�}|j|�q:|j�||�}|j�}q:W|S)Nrz
_token_nud_%srIz
_token_led_%s)rN�_advance�getattr�_error_nud_tokenrM�
BINDING_POWER�_error_led_token)r4rFZ
left_tokenZnud_function�left�
current_tokenZledZerror_tokenr6r6r7rLus 

zParser._expressioncCstj|d�S)NrH)r�literal)r4�tokenr6r6r7�_token_nud_string_literal�sz Parser._token_nud_string_literalcCstj|d�S)NrH)rrY)r4rZr6r6r7�_token_nud_literal�szParser._token_nud_literalcCstj|d�S)NrH)r�field)r4rZr6r6r7�_token_nud_unquoted_identifier�sz%Parser._token_nud_unquoted_identifiercCs@tj|d�}|j�dkr<|jd�}tjd|d|dd��|S)NrHr.rrIz1Quoted identifier not allowed for function names.)rr]rMrNrrD)r4rZr]rQr6r6r7�_token_nud_quoted_identifier�s
z#Parser._token_nud_quoted_identifiercCs:tj�}|j�dkrtj�}n|j|jd�}tj||�S)Nrr()r�identityrM�_parse_projection_rhsrU�value_projection)r4rZrW�rightr6r6r7�_token_nud_star�s

zParser._token_nud_starcCs|jtj��S)N)�_token_led_filterrr`)r4rZr6r6r7�_token_nud_filter�szParser._token_nud_filtercCs|j�S)N)�_parse_multi_select_hash)r4rZr6r6r7�_token_nud_lbrace�szParser._token_nud_lbracecCs|j�}|jd�|S)Nr)rL�_match)r4rZr?r6r6r7�_token_nud_lparen�s
zParser._token_nud_lparencCs*tjtj��}|j|jd�}tj||�S)Nr')rr'r`rarU�
projection)r4rZrWrcr6r6r7�_token_nud_flatten�szParser._token_nud_flattencCs|j|jd�}tj|�S)Nr+)rLrUrZnot_expression)r4rZ�exprr6r6r7�_token_nud_not�szParser._token_nud_notcCsz|j�dkr$|j�}|jtj�|�S|j�dkrn|jd�dkrn|j�|j�|j|jd�}tj	tj�|�S|j
�SdS)Nrrr(rr)rr)rM�_parse_index_expression�_project_if_slicerr`�
_lookaheadrRrarUrk�_parse_multi_select_list)r4rZrcr6r6r7�_token_nud_lbracket�szParser._token_nud_lbracketcCsR|jd�dks|jd�dkr$|j�Stj|jd�d�}|j�|jd�|SdS)NrrrrHr)rq�_parse_slice_expressionr�indexrNrRri)r4�noder6r6r7ro�s
zParser._parse_index_expressioncCs�dddg}d}|j�}x�|dkr�|dkr�|dkrD|d7}|j�nV|dkrh|jd�d||<|j�n2|jd�}|d}|d}|d	}tj|||d
��|j�}qW|jd�tj|�S)Nrrr
rrrrHrGrIzsyntax error)rMrRrNrrDrir�slice)r4�partsrurXrQ�lex_position�actual_value�actual_typer6r6r7rt�s&




zParser._parse_slice_expressioncCstj�S)N)rZcurrent_node)r4rZr6r6r7�_token_nud_current�szParser._token_nud_currentcCs|j|jd�}tj|�S)Nr)rLrUrr)r4rZr?r6r6r7�_token_nud_expref�szParser._token_nud_exprefcCsr|j�dksJ|j|jd�}|ddkr:|dj|�|Stj||g�Sn$|j�|j|jd�}tj||�SdS)Nr(r*rI�
subexpression�children)	rM�_parse_dot_rhsrU�appendrr~rRrarb)r4rWrcr6r6r7�_token_led_dot�szParser._token_led_dotcCs|j|jd�}tj||�S)Nr)rLrUrr)r4rWrcr6r6r7�_token_led_pipeszParser._token_led_pipecCs|j|jd�}tj||�S)Nr)rLrUrZ
or_expression)r4rWrcr6r6r7�
_token_led_orszParser._token_led_orcCs|j|jd�}tj||�S)Nr )rLrUrZand_expression)r4rWrcr6r6r7�_token_led_andszParser._token_led_andcCs`|d}g}x8|j�dksD|j�}|j�dkr8|jd�|j|�qW|jd�tj||�}|S)NrHrr)rMrLrir�rZfunction_expression)r4rW�name�argsr?Z
function_noder6r6r7�_token_led_lparens

zParser._token_led_lparencCsH|jd�}|jd�|j�dkr*tj�}n|j|jd�}tj|||�S)Nrrr'r))rLrirMrr`rarUZfilter_projection)r4rWZ	conditionrcr6r6r7re s


zParser._token_led_filtercCs|j|d�S)Nr!)�_parse_comparator)r4rWr6r6r7�
_token_led_eq*szParser._token_led_eqcCs|j|d�S)Nr&)r�)r4rWr6r6r7�
_token_led_ne-szParser._token_led_necCs|j|d�S)Nr")r�)r4rWr6r6r7�
_token_led_gt0szParser._token_led_gtcCs|j|d�S)Nr$)r�)r4rWr6r6r7�_token_led_gte3szParser._token_led_gtecCs|j|d�S)Nr#)r�)r4rWr6r6r7�
_token_led_lt6szParser._token_led_ltcCs|j|d�S)Nr%)r�)r4rWr6r6r7�_token_led_lte9szParser._token_led_ltecCs&tj|�}|j|jd�}tj||�S)Nr')rr'rarUrk)r4rWrcr6r6r7�_token_led_flatten<s
zParser._token_led_flattencCs~|jd�}|dd	krJ|j�}|ddkr<|dj|�|S|j||�Sn0|jd�|jd�|j|jd�}tj||�SdS)
NrrIrr�index_expressionrr(r)rr)	rNror�rprirarUrrk)r4rWrZrcr6r6r7�_token_led_lbracketBs


zParser._token_led_lbracketcCs:tj||g�}|ddkr2tj||j|jd��S|SdS)NrIrwr()rr�rkrarU)r4rWrcZ
index_exprr6r6r7rpUszParser._project_if_slicecCs|j|j|�}tj|||�S)N)rLrUr�
comparator)r4rWr�rcr6r6r7r�^szParser._parse_comparatorcCsJg}x0|j�}|j|�|j�dkr(Pq|jd�qW|jd�tj|�S)Nrr)rLr�rMrirZmulti_select_list)r4Zexpressionsr?r6r6r7rrbs

zParser._parse_multi_select_listcCs�g}x�|jd�}|jddgd�|d}|jd�|jd�}tj||d�}|j|�|j�dkrl|jd�q|j�d	kr|jd	�PqWtj|d
�S)Nrrr)�token_typesrHr)�key_namervrr)Znodes)	rN�_match_multiple_tokensrirLrZkey_val_pairr�rMZmulti_select_dict)r4ZpairsZ	key_tokenr�rHrvr6r6r7rgns 




zParser._parse_multi_select_hashcCs�|j|j�|jkrtj�}n�|j�dkr6|j|�}nl|j�dkrN|j|�}nT|j�dkrp|jd�|j|�}n2|jd�}|d}|d}|d}t	j
|||d��|S)	Nr-r)r*rrGrHrIzsyntax error)rUrM�_PROJECTION_STOPrr`rLrir�rNrrD)r4rFrcrQryrzr{r6r6r7ra�s 


zParser._parse_projection_rhscCs�|j�}|dkr|j|�S|dkr4|jd�|j�S|dkrN|jd�|j�S|jd�}ddddg}|d}|d}|d	}tj|||d
||f��dS)Nrrr(r-r,rrGrHrIzExpecting: %s, got: %s)rrr()rMrLrirrrgrNrrD)r4rFr5rQZallowedryrzr{r6r6r7r��s&	



zParser._parse_dot_rhscGsJ|j�|krF|jd�}|d}|d}|d}tj|||d||f��dS)NrrGrHrIzToken %s not allowed to be: %s)rMrNrrD)r4r�rQryrzr{r6r6r7�_assert_not_token�s
zParser._assert_not_tokencCsF|ddkr&tj|d|d|d��tj|d|d|dd��dS)NrIrrGrHzInvalid token.)rrCrD)r4rZr6r6r7rT�s
zParser._error_nud_tokencCs tj|d|d|dd��dS)NrGrHrIz
Invalid token)rrD)r4rZr6r6r7rV�szParser._error_led_tokenNcCsp|j�|kr|j�nV|jd�}|d}|d}|d}|dkrPtj|||��nd||f}tj||||��dS)NrrGrHrIrzExpecting: %s, got: %s)rMrRrNrrCrD)r4�
token_typerQryrzr{�messager6r6r7ri�s

z
Parser._matchcCsn|j�|krb|jd�}|d}|d}|d}|dkrFtj|||��nd||f}tj||||��|j�dS)NrrGrHrIrzExpecting: %s, got: %s)rMrNrrCrDrR)r4r�rQryrzr{r�r6r6r7r��s
zParser._match_multiple_tokenscCs|jd7_dS)Nr)r3)r4r6r6r7rR�szParser._advancecCs|j|jdS)NrI)r2r3)r4r6r6r7rM�szParser._current_tokencCs|j|j|dS)NrI)r2r3)r4rr6r6r7rq�szParser._lookaheadcCs|j|j|S)N)r2r3)r4rr6r6r7rN�szParser._lookahead_tokencCs2x,tj|jj�t|jd��D]}|j|=qWdS)Nr	)�randomZsampler9�keys�intr=)r4�keyr6r6r7r>�s"zParser._free_cache_entriescCs|jj�dS)z'Clear the expression compilation cache.N)r9�clear)�clsr6r6r7�purge�szParser.purge)r	)r)N);�__name__�
__module__�__qualname__rUr�r9r=r8rAr;rBrLr[r\r^r_rdrfrhrjrlrnrsrortr|r}r�r�r�r�r�rer�r�r�r�r�r�r�r�rpr�rrrgrar�r�rTrVrir�rRrMrqrNr>�classmethodr�r6r6r6r7r%s�




	

rc@s.eZdZdd�Zd
dd�Zdd�Zdd	�ZdS)rOcCs||_||_dS)N)r?rP)r4r?rPr6r6r7r8szParsedResult.__init__NcCstj|�}|j|j|�}|S)N)rZTreeInterpreter�visitrP)r4rHZoptionsZinterpreter�resultr6r6r7�search
s
zParsedResult.searchcCstj�}|j|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�rP)r4Zrenderer�contentsr6r6r7�_render_dot_files
zParsedResult._render_dot_filecCs
t|j�S)N)�reprrP)r4r6r6r7�__repr__szParsedResult.__repr__)N)r�r�r�r8r�r�r�r6r6r6r7rOs
rO)�__doc__r�ZjmespathrZjmespath.compatrrrr�objectrrOr6r6r6r7�<module>sb