B -<`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 |_|S)N) signature)func) arguments9/tmp/pip-target-7cdyy134/lib/python/jmespath/functions.py_record_signature'sz$signature.._record_signaturer)rrr)rrr&s rcs$eZdZfddZddZZS)FunctionRegistrycs |tt||||dS)N)_populate_function_tablesuperr__init__)clsnamebasesattrs) __class__rrr".szFunctionRegistry.__init__cCsZi}xJt|D]>\}}|ds"qt|dd}|dk r||d||dd<qW||_dS)NZ_func_r)functionr)r startswithgetattrFUNCTION_TABLE)r#Zfunction_tabler$methodrrrrr 2s  z)FunctionRegistry._populate_function_table)__name__ __module__ __qualname__r"r __classcell__rr)r'rr-s rc@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 ddd"gid#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 d"gddd7d8Ze d dd/gid9d:Ze d d/dgid;d<Ze d dgid=d>Ze d d"gid?d@Ze d d"gidAdBZ e d gidCdDZ!e d dgid d2gidEdFZ"e d dgid d2gidGdHZ#e d dgid d2gidIdJZ$dKdLZ%dMdNZ&dOS)P FunctionscCs^y|j|}Wn"tk r0td|YnX|d}|d}||||||f|S)NzUnknown function: %s()r(r)r,KeyErrorrZUnknownFunctionError_validate_arguments)self function_nameZ resolved_argsspecr(rrrr call_functionHszFunctions.call_functioncCsn|r:|ddr:t|t|kr`tt|t||n&t|t|kr`tt|t||||||S)Nvariadic)getlenrZVariadictArityErrorZ ArityError _type_check)r5argsrr6rrrr4SszFunctions._validate_argumentscCs<x6tt|D]&}||d}|r|||||qWdS)Ntypes)ranger<_type_check_single)r5actualrr6i allowed_typesrrrr=]s   zFunctions._type_checkcCsN||\}}t|j}||kr6t||||||rJ|||||dS)N)_get_allowed_pytypestyper.rJMESPathTypeError_convert_to_jmespath_type_subtype_check)r5currentr?r6rDallowed_subtypesactual_typenamerrrrAds zFunctions._type_check_singlecCsdg}g}xR|D]J}|dd}t|dkrB|\}}|t|n|d}|t|qW||fS)N-r)splitr<appendREVERSE_TYPES_MAPextend)r5r?rDrKttype_subtyperrrrE{s   zFunctions._get_allowed_pytypesc Cst|dkrF|d}x|D]&}t|j}||krt||||qWn~t|dkr|rt|dj}x.|D]}||krj|} PqjWt||d||x.|D]&}t|j}|| krt||||qWdS)NrNr)r<rFr.rrG) r5rJrKr?r6elementrLfirstZsubtypesallowedrrrrIs(      zFunctions._subtype_checkr?r cCst|S)N)abs)r5argrrr _func_absszFunctions._func_absz array-numbercCs |rt|tt|SdSdS)N)sumrr<)r5r[rrr _func_avgszFunctions._func_avgT)r?r:cGsx|D]}|dk r|SqWdS)Nr)r5rargumentrrr_func_not_nulls zFunctions._func_not_nullcCst|tr|S|gSdS)N) isinstancer)r5r[rrr_func_to_arrays zFunctions._func_to_arraycCs"t|tr|Stj|dtdSdS)N),:) separatorsdefault)ra STRING_TYPEjsondumpsr)r5r[rrr_func_to_strings zFunctions._func_to_stringc Csrt|tttfrdS|dkr dSt|ttfr2|Syt|Stk rlyt|Stk rfdSXYnXdS)N)rarrr rr ValueError)r5r[rrr_func_to_numberszFunctions._func_to_numberrr cCs||kS)Nr)r5subjectsearchrrr_func_containsszFunctions._func_containsrcCst|S)N)r<)r5r[rrr _func_lengthszFunctions._func_lengthcCs ||S)N)endswith)r5rnsuffixrrr_func_ends_withszFunctions._func_ends_withcCs ||S)N)r*)r5rnrrrrr_func_starts_withszFunctions._func_starts_withcCs(t|tr|dddStt|SdS)Nr9)rargrreversed)r5r[rrr _func_reverses zFunctions._func_reversecCs t|S)N)mathceil)r5r[rrr _func_ceilszFunctions._func_ceilcCs t|S)N)rwfloor)r5r[rrr _func_floorszFunctions._func_floorz array-stringcCs ||S)N)join)r5 separatorrrrr _func_joinszFunctions._func_joinr cCs*g}x |D]}|||j|q W|S)N)rQvisit expression)r5r r[resultrWrrr _func_maps zFunctions._func_mapcCs|r t|SdSdS)N)max)r5r[rrr _func_maxszFunctions._func_maxcGs i}x|D]}||q W|S)N)update)r5rmergedr[rrr _func_merges zFunctions._func_mergecCs|r t|SdSdS)N)min)r5r[rrr _func_min szFunctions._func_mincCs tt|S)N)rsorted)r5r[rrr _func_sortszFunctions._func_sortcCst|S)N)r])r5r[rrr _func_sumszFunctions._func_sumcCs t|S)N)rkeys)r5r[rrr _func_keysszFunctions._func_keyscCs t|S)N)rvalues)r5r[rrr _func_values"szFunctions._func_valuescCsZt|trdSt|trdSt|tr*dSt|tr8dSt|ttfrJdS|dkrVdSdS)Nr rrrr r )rargr rrrr)r5r[rrr _func_type&s    zFunctions._func_typecCsf|s|S|t||j|dj}|dkrFtd|d|ddg|||gd}tt ||dS)Nr)r r Zsort_byr r )key) rHrFrrr.rrG_create_key_funcrr)r5rr Z required_typekeyfuncrrr _func_sort_by5szFunctions._func_sort_bycCs*||ddgd}|r"t||dSdSdS)Nr r Zmin_by)r)rr)r5rr rrrr _func_min_byIs  zFunctions._func_min_bycCs*||ddgd}|r"t||dSdSdS)Nr r Zmax_by)r)rr)r5rr rrrr _func_max_bySs  zFunctions._func_max_bycsfdd}|S)Ncs>j|}t|j}|}|kr:t|||S)N)rrrFr.rHrrG)xrrLZ jmespath_type)rDr r6r5rrr^s   z+Functions._create_key_func..keyfuncr)r5r rDr6rr)rDr r6r5rr]s zFunctions._create_key_funccCs t|dS)Nunknown) TYPES_MAPr;)r5ZpyobjectrrrrHisz#Functions._convert_to_jmespath_typeN)'r.r/r0r,r8r4r=rArErIrr\r^r`rbrjrlrorprsrtrvryr{r~rrrrrrrrrrrrrrHrrrrr2CsF      r2)rwrhZjmespathrZjmespath.compatrrgrrrrRrrFrrr2rrrrs4