B ㊇c1 @sddlZddlZddlmZddlmZddlmZddddd d d d d ddd d Zd dddddddZ ddZ Gddde Z Gddde dZ dS)N) exceptions) string_type) get_methodsbooleanarrayobjectnullstringnumberexpref) boollistdictNoneTypeunicodestrfloatintlong OrderedDict _Projection _Expression)r )r r)rr)r)rr)rrr)r)rrrrr r r csfdd}|S)Ncs |_|S)N) signature)func) argumentsm/private/var/folders/8c/hx9_v10d5x38qmnzt13b7b8j1k3n5b/T/pip-target-x6xd5gna/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#methodrrrrr2s  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)r4argsrr5rrrr3SszFunctions._validate_argumentscCs<x6tt|D]&}||d}|r|||||qWdS)Ntypes)ranger;_type_check_single)r4actualrr5i allowed_typesrrrr<]s   zFunctions._type_checkcCsN||\}}t|j}||kr6t||||||rJ|||||dS)N)_get_allowed_pytypestyper-rJMESPathTypeError_convert_to_jmespath_type_subtype_check)r4currentr>r5rCallowed_subtypesactual_typenamerrrr@ds zFunctions._type_check_singlecCsdg}g}xR|D]J}|dd}t|dkrB|\}}|t|n|d}|t|qW||fS)N-r)splitr;appendREVERSE_TYPES_MAPextend)r4r>rCrJttype_subtyperrrrD{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)NrMr)r;rEr-rrF) r4rIrJr>r5elementrKfirstsubtypesallowedrrrrHs(      zFunctions._subtype_checkr>r cCst|S)N)abs)r4argrrr _func_absszFunctions._func_absz array-numbercCs |rt|tt|SdSdS)N)sumrr;)r4r[rrr _func_avgszFunctions._func_avgT)r>r9cGsx|D]}|dk r|SqWdS)Nr)r4rZargumentrrr_func_not_nulls zFunctions._func_not_nullcCst|tr|S|gSdS)N) isinstancer )r4r[rrr_func_to_arrays zFunctions._func_to_arraycCs"t|tr|Stj|dtdSdS)N),:) separatorsdefault)r` STRING_TYPEjsondumpsr)r4r[rrr_func_to_strings zFunctions._func_to_stringc Csrt|tttfrdS|dkr dSt|ttfr2|Syt|Stk rlyt|Stk rfdSXYnXdS)N)r`r rr rr ValueError)r4r[rrr_func_to_numberszFunctions._func_to_numberrr cCs||kS)Nr)r4subjectsearchrrr_func_containsszFunctions._func_containsrcCst|S)N)r;)r4r[rrr _func_lengthszFunctions._func_lengthcCs ||S)N)endswith)r4rmsuffixrrr_func_ends_withszFunctions._func_ends_withcCs ||S)N)r))r4rmrqrrr_func_starts_withszFunctions._func_starts_withcCs(t|tr|dddStt|SdS)Nr8)r`rfr reversed)r4r[rrr _func_reverses zFunctions._func_reversecCs t|S)N)mathceil)r4r[rrr _func_ceilszFunctions._func_ceilcCs t|S)N)rvfloor)r4r[rrr _func_floorszFunctions._func_floorz array-stringcCs ||S)N)join)r4 separatorrrrr _func_joinszFunctions._func_joinr cCs*g}x |D]}|||j|q W|S)N)rPvisit expression)r4r r[resultrVrrr _func_maps zFunctions._func_mapcCs|r t|SdSdS)N)max)r4r[rrr _func_maxszFunctions._func_maxcGs i}x|D]}||q W|S)N)update)r4rmergedr[rrr _func_merges zFunctions._func_mergecCs|r t|SdSdS)N)min)r4r[rrr _func_min szFunctions._func_mincCs tt|S)N)r sorted)r4r[rrr _func_sortszFunctions._func_sortcCst|S)N)r])r4r[rrr _func_sumszFunctions._func_sumcCs t|S)N)r keys)r4r[rrr _func_keysszFunctions._func_keyscCs t|S)N)r values)r4r[rrr _func_values"szFunctions._func_valuescCsZt|trdSt|trdSt|tr*dSt|tr8dSt|ttfrJdS|dkrVdSdS)Nr rrrr r)r`rfr r rrr)r4r[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) rGrEr~rr-rrF_create_key_funcr r)r4rr Z required_typekeyfuncrrr _func_sort_by5szFunctions._func_sort_bycCs*||ddgd}|r"t||dSdSdS)Nr r Zmin_by)r)rr)r4rr rrrr _func_min_byIs  zFunctions._func_min_bycCs*||ddgd}|r"t||dSdSdS)Nr r Zmax_by)r)rr)r4rr rrrr _func_max_bySs  zFunctions._func_max_bycsfdd}|S)Ncs>j|}t|j}|}|kr:t|||S)N)r~rrEr-rGrrF)xrrKZ jmespath_type)rCr r5r4rrr^s   z+Functions._create_key_func..keyfuncr)r4r rCr5rr)rCr r5r4rr]s zFunctions._create_key_funccCs t|dS)Nunknown) TYPES_MAPr:)r4ZpyobjectrrrrGisz#Functions._convert_to_jmespath_typeN)'r-r.r/r+r7r3r<r@rDrHrr\r^r_rarirkrnrorrrsrurxrzr}rrrrrrrrrrrrrrGrrrrr1CsF      r1) metaclass)rvrgjmespathrZjmespath.compatrrfrrrQrrErr1rrrrs4