B “äî\*ã@s ddlZddlmZddlmZddlmZdd„Zdd„Zd d „Z d d „Z Gd d„de ƒZ Gdd„de ƒZ Gdd„de ƒZGdd„deƒZGdd„deƒZdS)éN)Ú functions)Ú string_type)ÚNumbercCst||ƒrdS||kSdS)NF)Ú_is_special_integer_case)ÚxÚy©rú4/tmp/pip-build-uw_ogi45/jmespath/jmespath/visitor.pyÚ_equalss r cCsD|dks|dkr |dkp|dkS|dks0|dkr@|dkp>|dkSdS)NréTFr)rrrrr rsrcCst|ƒpt|tƒS)N)Ú_is_actual_numberÚ isinstancer)rrrr Ú_is_comparable&srcCs|dks|dkrdSt|tƒS)NTF)r r)rrrr r .sr c@seZdZdZddd„ZdS)ÚOptionsz8Options to control how a JMESPath function is evaluated.NcCs||_||_dS)N)Údict_clsÚcustom_functions)Úselfrrrrr Ú__init__=s zOptions.__init__)NN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrr r;src@seZdZdd„Zdd„ZdS)Ú _ExpressioncCs||_||_dS)N)Ú expressionÚ interpreter)rrrrrr rKsz_Expression.__init__cOs|jj|f|ž|ŽS)N)rÚvisit)rÚnodeÚargsÚkwargsrrr rOsz_Expression.visitN)rrrrrrrrr rJsrc@s$eZdZdd„Zdd„Zdd„ZdS)ÚVisitorcCs i|_dS)N)Ú _method_cache)rrrr rTszVisitor.__init__cOsL|d}|j |¡}|dkrgózTreeInterpreter.)ÚeqÚneÚltÚgtZlteZgter*r+Ncsbtt|ƒ ¡|j|_|dkr$tƒ}||_|jdk r>|jj|_|jdk rT|jj|_ n t   ¡|_ dS)N) Úsuperr'rÚMAP_TYPEÚ _dict_clsrÚ_optionsrrÚ _functionsrZ Functions)rÚoptions)Ú __class__rr rps    zTreeInterpreter.__init__cOst|dƒ‚dS)Nr!)r&)rrrrrrr r$}szTreeInterpreter.default_visitcCs&|}x|dD]}| ||¡}qW|S)NÚchildren)r)rrÚvalueÚresultrrr Úvisit_subexpression€sz#TreeInterpreter.visit_subexpressioncCs(y| |d¡Stk r"dSXdS)Nr6)r"ÚAttributeError)rrr6rrr Ú visit_field†szTreeInterpreter.visit_fieldcCs˜|j|d}|d|jkrF|| |dd|¡| |dd|¡ƒS| |dd|¡}| |dd|¡}ttf}t|ƒr†t|ƒsŠdS|||ƒSdS)Nr6r5rr )ÚCOMPARATOR_FUNCÚ _EQUALITY_OPSrÚintÚfloatr)rrr6Zcomparator_funcÚleftÚrightZ num_typesrrr Úvisit_comparatorŒsz TreeInterpreter.visit_comparatorcCs|S)Nr)rrr6rrr Ú visit_current szTreeInterpreter.visit_currentcCst|dd|ƒS)Nr5r)r)rrr6rrr Ú visit_expref£szTreeInterpreter.visit_exprefcCs>g}x&|dD]}| ||¡}| |¡qW|j |d|¡S)Nr5r6)rÚappendr2Ú call_function)rrr6Z resolved_argsÚchildÚcurrentrrr Úvisit_function_expression¦s  z)TreeInterpreter.visit_function_expressioncCs|| |dd|¡}t|tƒs"dS|dd}g}xD|D]<}| | ||¡¡r8| |dd|¡}|dk r8| |¡q8W|S)Nr5rér )rr ÚlistÚ_is_truerD)rrr6ÚbaseZcomparator_nodeÚ collectedÚelementrGrrr Úvisit_filter_projection­s   z'TreeInterpreter.visit_filter_projectioncCsX| |dd|¡}t|tƒs"dSg}x,|D]$}t|tƒrF| |¡q,| |¡q,W|S)Nr5r)rr rJÚextendrD)rrr6rLZ merged_listrNrrr Ú visit_flattenºs    zTreeInterpreter.visit_flattencCs|S)Nr)rrr6rrr Úvisit_identityÇszTreeInterpreter.visit_identitycCs4t|tƒsdSy ||dStk r.dSXdS)Nr6)r rJÚ IndexError)rrr6rrr Ú visit_indexÊs   zTreeInterpreter.visit_indexcCs&|}x|dD]}| ||¡}qW|S)Nr5)r)rrr6r7rrr Úvisit_index_expressionÔsz&TreeInterpreter.visit_index_expressioncCs"t|tƒsdSt|dŽ}||S)Nr5)r rJÚslice)rrr6Úsrrr Ú visit_sliceÚs  zTreeInterpreter.visit_slicecCs| |dd|¡S)Nr5r)r)rrr6rrr Úvisit_key_val_pairàsz"TreeInterpreter.visit_key_val_paircCs|dS)Nr6r)rrr6rrr Ú visit_literalãszTreeInterpreter.visit_literalcCs>|dkr dS| ¡}x$|dD]}| ||¡||d<qW|S)Nr5r6)r0r)rrr6rMrFrrr Úvisit_multi_select_dictæs z'TreeInterpreter.visit_multi_select_dictcCs8|dkr dSg}x"|dD]}| | ||¡¡qW|S)Nr5)rDr)rrr6rMrFrrr Úvisit_multi_select_listîs z'TreeInterpreter.visit_multi_select_listcCs6| |dd|¡}| |¡r2| |dd|¡}|S)Nr5rr )rÚ _is_false)rrr6Úmatchedrrr Úvisit_or_expressionös z#TreeInterpreter.visit_or_expressioncCs6| |dd|¡}| |¡r"|S| |dd|¡S)Nr5rr )rr])rrr6r^rrr Úvisit_and_expressionüs z$TreeInterpreter.visit_and_expressioncCs&| |dd|¡}|dkr dS| S)Nr5rF)r)rrr6Zoriginal_resultrrr Úvisit_not_expressionsz$TreeInterpreter.visit_not_expressioncCs&|}x|dD]}| ||¡}qW|S)Nr5)r)rrr6r7rrr Ú visit_pipe szTreeInterpreter.visit_pipecCs^| |dd|¡}t|tƒs"dSg}x2|D]*}| |dd|¡}|dk r,| |¡q,W|S)Nr5rr )rr rJrD)rrr6rLrMrNrGrrr Úvisit_projections  z TreeInterpreter.visit_projectioncCsr| |dd|¡}y | ¡}Wntk r4dSXg}x2|D]*}| |dd|¡}|dk r@| |¡q@W|S)Nr5rr )rÚvaluesr9rD)rrr6rLrMrNrGrrr Úvisit_value_projections  z&TreeInterpreter.visit_value_projectioncCs(|dkp&|gkp&|ikp&|dkp&|dkS)NÚFr)rr6rrr r](s zTreeInterpreter._is_falsecCs | |¡ S)N)r])rr6rrr rK/szTreeInterpreter._is_true)N)(rrrr Úoperatorr,r-ÚleÚger;r<Údictr/rr$r8r:rArBrCrHrOrQrRrTrUrXrYrZr[r\r_r`rarbrcrer]rKÚ __classcell__rr)r4r r'dsD       r'cs,eZdZ‡fdd„Zdd„Zdd„Z‡ZS)ÚGraphvizVisitorcstt|ƒ ¡g|_d|_dS)Nr )r.rlrÚ_linesÚ_count)r)r4rr r4szGraphvizVisitor.__init__cOsP|j d¡d|d|jf}|jd7_| ||¡|j d¡d |j¡S)Nz digraph AST {z%s%sr!r Ú}Ú )rmrDrnÚ_visitÚjoin)rrrrrGrrr r9s    zGraphvizVisitor.visitc Cs||j d||d| dd¡f¡xT| dg¡D]D}d|d|jf}|jd7_|j d||f¡| ||¡q0WdS) Nz%s [label="%s(%s)"]r!r6rfr5z%s%sr z %s -> %s)rmrDr"rnrq)rrrGrFZ child_namerrr rqAszGraphvizVisitor._visit)rrrrrrqrkrr)r4r rl3s rl)rgZjmespathrZjmespath.compatrZnumbersrr rrr Úobjectrrrr'rlrrrr Ús     P