o ^1 @sddlZddlZddlmZddlmZddlmZmZddddd d d d d ddd d Z d dddddddZ ddZ Gddde Z Gdddee eZdS)N) exceptions) string_type) get_methodswith_metaclassbooleanarrayobjectnullstringnumberexpref) boollistdictNoneTypeunicodestrfloatintlong OrderedDict _Projection _Expression)r )rr)rr)r)rr)rrr)r)rrrr r r r csfdd}|S)Ncs |_|SN) signature)func arguments4/usr/lib/python3/dist-packages/jmespath/functions.py_record_signature'sz$signature.._record_signaturer)rr rrrr&s rcs$eZdZfddZddZZS)FunctionRegistrycs |tt||||dSr)_populate_function_tablesuperr!__init__)clsnamebasesattrs __class__rrr$.szFunctionRegistry.__init__cCsVi}t|D]\}}|dsqt|dd}|dur%||d||dd<q||_dS)N_func_r)functionr)r startswithgetattrFUNCTION_TABLE)r%function_tabler&methodrrrrr"2s   z)FunctionRegistry._populate_function_table)__name__ __module__ __qualname__r$r" __classcell__rrr)rr!-s r!c@seZdZiZddZddZddZddZd d Zd d Z e d dgiddZ e d dgiddZ e gddddZ e d giddZe d giddZe d giddZe d ddgid gid d!Ze d gd"id#d$Ze d dgid dgid%d&Ze d dgid dgid'd(Ze d ddgid)d*Ze d dgid+d,Ze d dgid-d.Ze d dgid d/gid0d1Ze d d2gid dgid3d4Ze d dd/gid5d6Ze d7gddd8d9Ze d dd/gid:d;Ze d d/dgidd?Ze d d7gid@dAZe d d7gidBdCZ e d gidDdEZ!e d dgid d2gidFdGZ"e d dgid d2gidHdIZ#e d dgid d2gidJdKZ$dLdMZ%dNdOZ&dPS)Q FunctionscCsZz|j|}Wntytd|w|d}|d}||||||g|RS)NzUnknown function: %s()r,r)r0KeyErrorrUnknownFunctionError_validate_arguments)self function_name resolved_argsspecr,rrrr call_functionHs zFunctions.call_functioncCsn|r|ddrt|t|krtt|t||nt|t|kr0tt|t||||||S)Nvariadic)getlenrVariadictArityError ArityError _type_check)r;argsrr<rrrr:SszFunctions._validate_argumentscCs8tt|D]}||d}|r|||||qdS)Ntypes)rangerC_type_check_single)r;actualrr<i allowed_typesrrrrF]s  zFunctions._type_checkcCsR||\}}t|j}||vrt||||||r'|||||dSdSr)_get_allowed_pytypestyper3rJMESPathTypeError_convert_to_jmespath_type_subtype_check)r;currentrHr<rMallowed_subtypesactual_typenamerrrrJds  zFunctions._type_check_singlecCs`g}g}|D]%}|dd}t|dkr |\}}|t|n|d}|t|q||fS)N-r)splitrCappendREVERSE_TYPES_MAPextend)r;rHrMrTttype_subtyperrrrN{s  zFunctions._get_allowed_pytypesc Cst|dkr"|d}|D]}t|j}||vrt||||q dSt|dkr^|r`t|dj}|D] }||vr=|} n q3t||d|||D]}t|j}|| vr]t||||qJdSdSdS)NrWr)rCrOr3rrP) r;rSrTrHr<elementrUfirstsubtypesallowedrrrrRs:     zFunctions._subtype_checkrHr cCt|Sr)absr;argrrr _func_abszFunctions._func_absz array-numbercCs|r t|tt|SdSr)sumrrCrfrrr _func_avgszFunctions._func_avgT)rHrAcGs|D] }|dur |SqdSrr)r;rargumentrrr_func_not_nulls zFunctions._func_not_nullcCst|tr|S|gSr) isinstancerrfrrr_func_to_arrays zFunctions._func_to_arraycCst|tr|Stj|dtdS)N),:) separatorsdefault)rn STRING_TYPEjsondumpsrrfrrr_func_to_strings zFunctions._func_to_stringc Csrt|tttfr dS|durdSt|ttfr|Szt|WSty8zt|WYSty7YYdSwwr)rnrrr rr ValueErrorrfrrr_func_to_numbers   zFunctions._func_to_numberrr cCs||vSrr)r;subjectsearchrrr_func_containsrizFunctions._func_contains)r rrcCrdr)rCrfrrr _func_lengthrizFunctions._func_lengthcC ||Sr)endswithr;r{suffixrrr_func_ends_with zFunctions._func_ends_withcCr~r)r.rrrr_func_starts_withrzFunctions._func_starts_withcCs$t|tr |dddStt|S)Nr@)rnrtrreversedrfrrr _func_reverses  zFunctions._func_reversecC t|Sr)mathceilrfrrr _func_ceilrzFunctions._func_ceilcCrr)rfloorrfrrr _func_floorrzFunctions._func_floorz array-stringcCr~r)join)r; separatorrrrr _func_joinrzFunctions._func_joinr cCs&g}|D] }|||j|q|Sr)rZvisit expression)r;r rgresultr`rrr _func_mapszFunctions._func_mapcC|rt|SdSr)maxrfrrr _func_maxzFunctions._func_maxrcGsi}|D]}||q|Sr)update)r;rmergedrgrrr _func_merges zFunctions._func_mergecCrr)minrfrrr _func_min rzFunctions._func_mincCs tt|Sr)rsortedrfrrr _func_sort zFunctions._func_sortcCrdr)rjrfrrr _func_sumrizFunctions._func_sumcC t|Sr)rkeysrfrrr _func_keyss zFunctions._func_keyscCrr)rvaluesrfrrr _func_values"rzFunctions._func_valuescCsZt|trdSt|trdSt|trdSt|trdSt|ttfr%dS|dur+dSdS)Nr rrrr r )rnrtr rrrrrfrrr _func_type&s    zFunctions._func_typecCsf|s|S|t||j|dj}|dvr#td|d|ddg|||gd}tt ||dS)Nr)r r sort_byr r key) rQrOrrr3rrP_create_key_funcrr)r;rr required_typekeyfuncrrr _func_sort_by5szFunctions._func_sort_bycC&||ddgd}|rt||dSdS)Nr r min_byr)rrr;rr rrrr _func_min_byI zFunctions._func_min_bycCr)Nr r max_byr)rrrrrr _func_max_bySrzFunctions._func_max_bycsfdd}|S)Ncs>j|}t|j}|}|vrt|||Sr)rrrOr3rQrrP)xrrU jmespath_typerMr r<r;rrr^s  z+Functions._create_key_func..keyfuncr)r;r rMr<rrrrr]s zFunctions._create_key_funccCs t|dS)Nunknown) TYPES_MAPrB)r;pyobjectrrrrQis z#Functions._convert_to_jmespath_typeN)'r3r4r5r0r?r:rFrJrNrRrrhrkrmrorwryr|r}rrrrrrrrrrrrrrrrrrrrQrrrrr7Cs|                                         r7)rrujmespathrjmespath.compatrrtrrrr[rrOr!rr7rrrrs: