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ú7/tmp/pip-target-7cdyy134/lib/python/jmespath/visitor.pyÚ_equalss r cCs\t|ƒtkr,|dks|dkr,|dkp*|dkSt|ƒtkrX|dksH|dkrX|dkpV|dkSdS)NréTF)ÚtypeÚint)rrrrr rsrcCst|ƒpt|tƒS)N)Ú_is_actual_numberÚ isinstancer)rrrr Ú_is_comparable&srcCs|dks|dkrdSt|tƒS)NTF)rr)rrrr r.src@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')rrrr rrr 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)Nr7)r#ÚAttributeError)rrr7rrr Ú visit_field†szTreeInterpreter.visit_fieldcCs˜|j|d}|d|jkrF|| |dd|¡| |dd|¡ƒS| |dd|¡}| |dd|¡}ttf}t|ƒr†t|ƒsŠdS|||ƒSdS)Nr7r6rr )ÚCOMPARATOR_FUNCÚ _EQUALITY_OPSrr Úfloatr)rrr7Zcomparator_funcÚleftÚrightZ num_typesrrr Úvisit_comparatorŒsz TreeInterpreter.visit_comparatorcCs|S)Nr)rrr7rrr Ú visit_current szTreeInterpreter.visit_currentcCst|dd|ƒS)Nr6r)r)rrr7rrr Ú visit_expref£szTreeInterpreter.visit_exprefcCs>g}x&|dD]}| ||¡}| |¡qW|j |d|¡S)Nr6r7)rÚappendr3Ú call_function)rrr7Z 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)Nr6rér )rrÚlistÚ_is_truerD)rrr7Ú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)Nr6r)rrrJÚextendrD)rrr7rLZ merged_listrNrrr Ú visit_flattenºs    zTreeInterpreter.visit_flattencCs|S)Nr)rrr7rrr Úvisit_identityÇszTreeInterpreter.visit_identitycCs4t|tƒsdSy ||dStk r.dSXdS)Nr7)rrJÚ IndexError)rrr7rrr Ú visit_indexÊs   zTreeInterpreter.visit_indexcCs&|}x|dD]}| ||¡}qW|S)Nr6)r)rrr7r8rrr Úvisit_index_expressionÔsz&TreeInterpreter.visit_index_expressioncCs"t|tƒsdSt|dŽ}||S)Nr6)rrJÚslice)rrr7Úsrrr Ú visit_sliceÚs  zTreeInterpreter.visit_slicecCs| |dd|¡S)Nr6r)r)rrr7rrr Úvisit_key_val_pairàsz"TreeInterpreter.visit_key_val_paircCs|dS)Nr7r)rrr7rrr Ú visit_literalãszTreeInterpreter.visit_literalcCs>|dkr dS| ¡}x$|dD]}| ||¡||d<qW|S)Nr6r7)r1r)rrr7rMrFrrr Úvisit_multi_select_dictæs z'TreeInterpreter.visit_multi_select_dictcCs8|dkr dSg}x"|dD]}| | ||¡¡qW|S)Nr6)rDr)rrr7rMrFrrr Úvisit_multi_select_listîs z'TreeInterpreter.visit_multi_select_listcCs6| |dd|¡}| |¡r2| |dd|¡}|S)Nr6rr )rÚ _is_false)rrr7Úmatchedrrr Úvisit_or_expressionös z#TreeInterpreter.visit_or_expressioncCs6| |dd|¡}| |¡r"|S| |dd|¡S)Nr6rr )rr])rrr7r^rrr Úvisit_and_expressionüs z$TreeInterpreter.visit_and_expressioncCs2| |dd|¡}t|ƒtkr,|dkr,dS| S)Nr6rF)rr r )rrr7Zoriginal_resultrrr Úvisit_not_expressionsz$TreeInterpreter.visit_not_expressioncCs&|}x|dD]}| ||¡}qW|S)Nr6)r)rrr7r8rrr Ú visit_pipe szTreeInterpreter.visit_pipecCs^| |dd|¡}t|tƒs"dSg}x2|D]*}| |dd|¡}|dk r,| |¡q,W|S)Nr6rr )rrrJrD)rrr7rLrMrNrGrrr Úvisit_projections  z TreeInterpreter.visit_projectioncCsr| |dd|¡}y | ¡}Wntk r4dSXg}x2|D]*}| |dd|¡}|dk r@| |¡q@W|S)Nr6rr )rÚvaluesr:rD)rrr7rLrMrNrGrrr Úvisit_value_projections  z&TreeInterpreter.visit_value_projectioncCs(|dkp&|gkp&|ikp&|dkp&|dkS)NÚFr)rr7rrr r](s zTreeInterpreter._is_falsecCs | |¡ S)N)r])rr7rrr rK/szTreeInterpreter._is_true)N)(rrrr Úoperatorr-r.ÚleÚger<r=Údictr0rr%r9r;rArBrCrHrOrQrRrTrUrXrYrZr[r\r_r`rarbrcrer]rKÚ __classcell__rr)r5r r(dsD       r(cs,eZdZ‡fdd„Zdd„Zdd„Z‡ZS)ÚGraphvizVisitorcstt|ƒ ¡g|_d|_dS)Nr )r/rlrÚ_linesÚ_count)r)r5rr r4szGraphvizVisitor.__init__cOsP|j d¡d|d|jf}|jd7_| ||¡|j d¡d |j¡S)Nz digraph AST {z%s%sr r Ú}Ú )rmrDrnÚ_visitÚjoin)rrrr rGrrr 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 r7rfr6z%s%sr z %s -> %s)rmrDr#rnrq)rrrGrFZ child_namerrr rqAszGraphvizVisitor._visit)rrrrrrqrkrr)r5r rl3s rl)rgZjmespathrZjmespath.compatrZnumbersrr rrrÚobjectrrr!r(rlrrrr Ús     P