Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/site-packages/jmespath/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/site-packages/jmespath/__pycache__/parser.cpython-38.pyc
U

O��g�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�r9�</opt/cppython/lib/python3.8/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)r7�
expression�cached�
parsed_resultr9r9r:�parseTs

zParser.parsec
Cs�z|�|�WStjk
r8}z||_�W5d}~XYnZtjk
rf}z|�|��W5d}~XYn,tjk
r�}z||_�W5d}~XYnXdSr<)�_parserZ
LexerErrorrC�IncompleteExpressionErrorZset_expression�
ParseError)r7rC�er9r9r:r?^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�tokenizer4�listr5r6�_expression�_current_token�_lookahead_tokenrrI�ParsedResult)r7rC�parsed�tr9r9r:rGks

�z
Parser._parsecCs�|�d�}|��t|d|d|j�}||�}|��}||j|kr�t|d|d�}|dkrt|�d�}|�|�q8|��||�}|��}q8|S)Nrz
_token_nud_%srNz
_token_led_%s)rT�_advance�getattr�_error_nud_tokenrS�
BINDING_POWER�_error_led_token)r7rKZ
left_tokenZnud_function�left�
current_tokenZledZerror_tokenr9r9r:rRvs$

�

zParser._expressioncCst�|d�S�NrM)rr�r7�tokenr9r9r:�_token_nud_literal�szParser._token_nud_literalcCst�|d�Sr_)r�fieldr`r9r9r:�_token_nud_unquoted_identifier�sz%Parser._token_nud_unquoted_identifiercCs@t�|d�}|��dkr<|�d�}t�d|d|dd��|S)NrMr0rrNz1Quoted identifier not allowed for function names.)rrcrSrTrrI)r7rarcrWr9r9r:�_token_nud_quoted_identifier�s
�z#Parser._token_nud_quoted_identifiercCs:t��}|��dkrt��}n|�|jd�}t�||�S)Nrr*)r�identityrS�_parse_projection_rhsr[�value_projection�r7rar]�rightr9r9r:�_token_nud_star�s

zParser._token_nud_starcCs|�t���Sr<)�_token_led_filterrrfr`r9r9r:�_token_nud_filter�szParser._token_nud_filtercCs|��Sr<)�_parse_multi_select_hashr`r9r9r:�_token_nud_lbrace�szParser._token_nud_lbracecCs|��}|�d�|S)Nr)rR�_match�r7rarCr9r9r:�_token_nud_lparen�s
zParser._token_nud_lparencCs*t�t���}|�|jd�}t�||�S�Nr))rr)rfrgr[�
projectionrir9r9r:�_token_nud_flatten�s
�zParser._token_nud_flattencCs|�|jd�}t�|�S)Nr-)rRr[rZnot_expression)r7ra�exprr9r9r:�_token_nud_not�szParser._token_nud_notcCsz|��dkr$|��}|�t��|�S|��dkrn|�d�dkrn|��|��|�|jd�}t�	t��|�S|�
�SdS)N�rrr*rr)rS�_parse_index_expression�_project_if_slicerrf�
_lookaheadrXrgr[rt�_parse_multi_select_list)r7rarjr9r9r:�_token_nud_lbracket�s�zParser._token_nud_lbracketcCsR|�d�dks|�d�dkr$|��St�|�d�d�}|��|�d�|SdS)NrrrrMr)r{�_parse_slice_expressionr�indexrTrXrp)r7�noder9r9r:ry�s�
zParser._parse_index_expressioncCs�dddg}d}|��}|dks�|dkr�|dkrZ|d7}|dkrP|�|�d�d�|��n6|dkr~|�d�d||<|��n|�|�d�d�|��}q|�d�tj|�S)	Nrrr
rr�syntax errorrrM)rS�_raise_parse_error_for_tokenrTrXrpr�slice)r7�partsrr^r9r9r:r~�s,
�

�

zParser._parse_slice_expressioncCst��Sr<)rZcurrent_noder`r9r9r:�_token_nud_current�szParser._token_nud_currentcCs|�|jd�}t�|�S)Nr)rRr[rrrqr9r9r:�_token_nud_expref�szParser._token_nud_exprefcCsr|��dksJ|�|jd�}|ddkr:|d�|�|St�||g�Sn$|��|�|jd�}t�||�SdS)Nr*r,rN�
subexpression�children)	rS�_parse_dot_rhsr[�appendrr�rXrgrh�r7r]rjr9r9r:�_token_led_dot�s�zParser._token_led_dotcCs|�|jd�}t�||�S)Nr )rRr[rr r�r9r9r:�_token_led_pipeszParser._token_led_pipecCs|�|jd�}t�||�S)Nr!)rRr[rZ
or_expressionr�r9r9r:�
_token_led_or	szParser._token_led_orcCs|�|jd�}t�||�S)Nr")rRr[rZand_expressionr�r9r9r:�_token_led_and
szParser._token_led_andcCs�|ddkr:|�d�}t�|d|d|dd|d��|d}g}|��dks||��}|��dkrp|�d�|�|�qF|�d�t�||�}|S)	NrNrc���rLrMzInvalid function name '%s'rr)	rTrrIrSrRrpr�rZfunction_expression)r7r]Zprev_t�name�argsrCZ
function_noder9r9r:�_token_led_lparens$

�

zParser._token_led_lparencCsH|�d�}|�d�|��dkr*t��}n|�|jd�}t�|||�S)Nrrr)r+)rRrprSrrfrgr[Zfilter_projection)r7r]�	conditionrjr9r9r:rl%s


zParser._token_led_filtercCs|�|d�S)Nr#��_parse_comparator�r7r]r9r9r:�
_token_led_eq/szParser._token_led_eqcCs|�|d�S)Nr(r�r�r9r9r:�
_token_led_ne2szParser._token_led_necCs|�|d�S)Nr$r�r�r9r9r:�
_token_led_gt5szParser._token_led_gtcCs|�|d�S)Nr&r�r�r9r9r:�_token_led_gte8szParser._token_led_gtecCs|�|d�S)Nr%r�r�r9r9r:�
_token_led_lt;szParser._token_led_ltcCs|�|d�S)Nr'r�r�r9r9r:�_token_led_lte>szParser._token_led_ltecCs&t�|�}|�|jd�}t�||�Srs)rr)rgr[rtr�r9r9r:�_token_led_flattenAs

�zParser._token_led_flattencCs~|�d�}|ddkrJ|��}|ddkr<|d�|�|S|�||�Sn0|�d�|�d�|�|jd�}t�||�SdS)NrrNrx�index_expressionr�r*r)	rTryr�rzrprgr[rrt)r7r]rarjr9r9r:�_token_led_lbracketGs


zParser._token_led_lbracketcCs:t�||g�}|ddkr2t�||�|jd��S|SdS)NrNr�r*)rr�rtrgr[)r7r]rjZ
index_exprr9r9r:rzZs�zParser._project_if_slicecCs|�|j|�}t�|||�Sr<)rRr[r�
comparator)r7r]r�rjr9r9r:r�cszParser._parse_comparatorcCsFg}|��}|�|�|��dkr&q2q|�d�q|�d�t�|�S)Nrr)rRr�rSrprZmulti_select_list)r7ZexpressionsrCr9r9r:r|gs

zParser._parse_multi_select_listcCs�g}|�d�}|jddgd�|d}|�d�|�d�}tj||d�}|�|�|��dkrj|�d�q|��d	kr|�d	�q�qtj|d
�S)Nrrr)�token_typesrMr)�key_namer�rr)Znodes)	rT�_match_multiple_tokensrprRrZkey_val_pairr�rSZmulti_select_dict)r7�pairsZ	key_tokenr�rMr�r9r9r:rnss 
�



zParser._parse_multi_select_hashcCs�|j|��|jkrt��}nd|��dkr6|�|�}nL|��dkrN|�|�}n4|��dkrp|�d�|�|�}n|�|�	d�d�|S)Nr/r+r,rr�)
r[rS�_PROJECTION_STOPrrfrRrpr�r�rT)r7rKrjr9r9r:rg�s

�zParser._parse_projection_rhscCs�|��}|dkr|�|�S|dkr4|�d�|��S|dkrN|�d�|��S|�d�}ddddg}d||df}|�||�dS)	N)rrr*r/r.rrr�Expecting: %s, got: %srN)rSrRrpr|rnrTr�)r7rKr8rW�allowed�msgr9r9r:r��s"	



��zParser._parse_dot_rhscCs6|ddkr&t�|d|d|d��|�|d�dS)NrNrrLrM�
invalid token)rrHr�r`r9r9r:rZ�s�zParser._error_nud_tokencCs|�|d�dS)Nr�)r�r`r9r9r:r\�szParser._error_led_tokenNcCs,|��|kr|��n|�||�d��dSr3)rSrX�_raise_parse_error_maybe_eofrT)r7�
token_typer9r9r:rp�s
�z
Parser._matchcCs*|��|kr|�||�d��|��dSr3)rSr�rTrX)r7r�r9r9r:r��s�zParser._match_multiple_tokenscCs|jd7_dS)Nr)r6�r7r9r9r:rX�szParser._advancecCs|j|jdS�NrN�r5r6r�r9r9r:rS�szParser._current_tokencCs|j|j|dSr�r��r7rr9r9r:r{�szParser._lookaheadcCs|j|j|Sr<r�r�r9r9r:rT�szParser._lookahead_tokencCs,|d}|d}|d}t�||||��dS)NrLrMrN)rrI)r7ra�reason�lex_position�actual_value�actual_typer9r9r:r��s�z#Parser._raise_parse_error_for_tokencCsN|d}|d}|d}|dkr.t�|||��d||f}t�||||��dS)NrLrMrNrr�)rrHrI)r7�
expected_typerar�r�r��messager9r9r:r��s$���z#Parser._raise_parse_error_maybe_eofcCs8t�t|j���t|jd��D]}|j�|d�q dS)Nr	)�random�samplerQr=�keys�intrA�pop)r7�keyr9r9r:rB�s$zParser._free_cache_entriescCs|j��dS)z'Clear the expression compilation cache.N)r=�clear)�clsr9r9r:�purge�szParser.purge)r	)r)N);�__name__�
__module__�__qualname__r[r�r=rAr;rFr?rGrRrbrdrerkrmrorrrurwr}ryr~r�r�r�r�r�r�r�rlr�r�r�r�r�r�r�r�rzr�r|rnrgr�rZr\rpr�rXrSr{rTr�r�rB�classmethodr�r9r9r9r:r%s��"




	
	rc@s.eZdZdd�Zd
dd�Zdd�Zdd	�ZdS)rUcCs||_||_dSr<)rCrV)r7rCrVr9r9r:r;�szParsedResult.__init__NcCst�|�}|�|j|�}|Sr<)rZTreeInterpreter�visitrV)r7rM�options�interpreter�resultr9r9r:�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�rV)r7�renderer�contentsr9r9r:�_render_dot_files
zParsedResult._render_dot_filecCs
t|j�Sr<)�reprrVr�r9r9r:�__repr__szParsedResult.__repr__)N)r�r�r�r;r�r�r�r9r9r9r:rU�s
rU)�__doc__r��jmespathrZjmespath.compatrrrr�objectrrUr9r9r9r:�<module>sS

F1le Man4ger