U kf.@sdZddlmZddlmZddlmZddlm Z ddlm Z ddlmZdd lm Z dd l m Z dd l mZdd lmZdd lmZddlmZGdddejZGdddejZGdddejZeZeZGdddZdddddZdS)zEvaluation functions used **INTERNALLY** by ORM DML use cases. This module is **private, for internal use by SQLAlchemy**. .. versionchanged:: 2.0.4 renamed ``EvaluatorCompiler`` to ``_EvaluatorCompiler``. ) annotations)Type)exc)LoaderCallableStatus) PassiveFlag)inspect)and_) operators)Integer)Numeric)warn_deprecatedc@s eZdZdS)UnevaluatableErrorN)__name__ __module__ __qualname__rrH/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/orm/evaluator.pyr$src@seZdZddZddZdS) _NoObjectcOsdSNrselfargkwrrroperate)sz_NoObject.operatecOsdSrrrrrrreverse_operate,sz_NoObject.reverse_operateNrrrrrrrrrr(src@seZdZddZddZdS)_ExpiredObjectcOs|Srrrrrrr1sz_ExpiredObject.operatecOs|Srrrrrrr4sz_ExpiredObject.reverse_operateNrrrrrr0src@s eZdZd6ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'ZeZeZeZeZeZeZeZeZeZeZeZ d(d)Z!d*d+Z"d,d-Z#d.d/Z$d0d1Z%d2d3Z&d4d5Z'dS)7_EvaluatorCompilerNcCs ||_dSr) target_cls)rr rrr__init__=sz_EvaluatorCompiler.__init__cGsF|rt|f|}t|d|jd}|s>tdt|j||S)Nvisit_Cannot evaluate )r getattrZ__visit_name__rtyper)rclauseclausesmethrrrprocess@sz_EvaluatorCompiler.processcCs ||jSr)r)elementrr&rrrvisit_groupingKsz!_EvaluatorCompiler.visit_groupingcCsddS)NcSsdSrrobjrrrOz/_EvaluatorCompiler.visit_null..rr+rrr visit_nullNsz_EvaluatorCompiler.visit_nullcCsddS)NcSsdS)NFrr-rrrr/Rr0z0_EvaluatorCompiler.visit_false..rr+rrr visit_falseQsz_EvaluatorCompiler.visit_falsecCsddS)NcSsdS)NTrr-rrrr/Ur0z/_EvaluatorCompiler.visit_true..rr+rrr visit_trueTsz_EvaluatorCompiler.visit_truec sz|jd}Wn2tk r@}ztd||W5d}~XYnX|jrft|j|jsftd|j|z|j|j}Wn4t j k r}ztd||W5d}~XYnX|j |j fdd}|S)N parentmapperzCannot evaluate column: z0Can't evaluate criteria against alternate class zCannot evaluate expression: cs>|dkr tSt|}|j}j||tjd}|tjkr:tS|S)N)Zpassive) _NO_OBJECTr dictgetrZPASSIVE_NO_FETCHrZPASSIVE_NO_RESULT_EXPIRED_OBJECT)r.stateZdict_valueimplrrget_corresponding_attr~s z?_EvaluatorCompiler.visit_column..get_corresponding_attr) Z _annotationsKeyErrorrr issubclassclass_Z_check_configureZ_columntopropertykeyorm_excZUnmappedColumnErrorZ class_managerr<)rr&r4ZkerAerrr=rr;r visit_columnWs6    z_EvaluatorCompiler.visit_columncCs ||Srvisit_clauselistr+rrr visit_tuplesz_EvaluatorCompiler.visit_tuplecCs ||SrrEr+rrrvisit_expression_clauselistsz._EvaluatorCompiler.visit_expression_clauselistcs\fdd|jD}d|jjdd}t|d}|rH||j||Std|jdS)Ncsg|]}|qSr)r)).0r&rrr sz7_EvaluatorCompiler.visit_clauselist..r"_Z_clauselist_opz)Cannot evaluate clauselist with operator )r'operatorrrstripr$r)rr& evaluatorsdispatchr(rrJrrFs  z#_EvaluatorCompiler.visit_clauselistcCsn||j}||j}d|jjdd}t||d}|rN||j|||Stdt|jd|jdS)Nr"rLZ _binary_opr# with operator ) r)leftrightrMrrNr$rr%)rr& eval_left eval_rightrPr(rrr visit_binarys   z_EvaluatorCompiler.visit_binarycsfdd}|S)NcsHd}D]2}||}|tkr$tS|r.dS|p8|dk}q|rDdSdSNFTr8)r.Zhas_null sub_evaluater:rOrrevaluatesz;_EvaluatorCompiler.visit_or_clauselist_op..evaluaterrrMrOr&r[rrZrvisit_or_clauselist_ops z)_EvaluatorCompiler.visit_or_clauselist_opcsfdd}|S)NcsFD]<}||}|tkr tS|s|dks4|tkr:dSdSqdSrW)r8r5)r.rYr:rZrrr[sz<_EvaluatorCompiler.visit_and_clauselist_op..evaluaterr\rrZrvisit_and_clauselist_ops z*_EvaluatorCompiler.visit_and_clauselist_opcsfdd}|S)NcsNg}D]<}||}|tkr$tS|dks4|tkr:dS||qt|Sr)r8r5appendtuple)r.valuesrYr:rZrrr[s zA_EvaluatorCompiler.visit_comma_op_clauselist_op..evaluaterr\rrZrvisit_comma_op_clauselist_ops z/_EvaluatorCompiler.visit_comma_op_clauselist_opcCs,|jr|||||Std|jddS)NzCustom operator zR can't be evaluated in Python unless it specifies a callable using `.python_impl`.)Z python_impl_straight_evaluaterZopstringrrMrTrUr&rrrvisit_custom_op_binary_ops z,_EvaluatorCompiler.visit_custom_op_binary_opcsfdd}|S)Ncs,|}|}|tks |tkr$tS||kSrrXr.Zleft_valZ right_valrTrUrrr[s z7_EvaluatorCompiler.visit_is_binary_op..evaluaterrrMrTrUr&r[rrgrvisit_is_binary_opsz%_EvaluatorCompiler.visit_is_binary_opcsfdd}|S)Ncs,|}|}|tks |tkr$tS||kSrrXrfrgrrr[s z;_EvaluatorCompiler.visit_is_not_binary_op..evaluaterrhrrgrvisit_is_not_binary_opsz)_EvaluatorCompiler.visit_is_not_binary_opcsfdd}|S)NcsJ|}|}|tks |tkr$tS|dks4|dkr8dS||SrrXrfrTrUrMrrr[sz7_EvaluatorCompiler._straight_evaluate..evaluaterrhrrkrrcs z%_EvaluatorCompiler._straight_evaluatecCsX|jjjttfks$|jjjttfkrHtd|jd|jjd|jj|||||S)NzCannot evaluate math operator "z" for datatypes z, ) rRr%Z_type_affinityr r rSrrrcrdrrr_straight_evaluate_numeric_only sz2_EvaluatorCompiler._straight_evaluate_numeric_onlycCs|dd|||S)NcSs|tk r||kSdSrr5abrrrr/'r0z:_EvaluatorCompiler.visit_in_op_binary_op..rcrdrrrvisit_in_op_binary_op%s z(_EvaluatorCompiler.visit_in_op_binary_opcCs|dd|||S)NcSs|tk r||kSdSrrmrnrrrr/1r0z>_EvaluatorCompiler.visit_not_in_op_binary_op..rqrdrrrvisit_not_in_op_binary_op-s z,_EvaluatorCompiler.visit_not_in_op_binary_opcCs|dd|||S)NcSs||Srrrnrrrr/;r0z>_EvaluatorCompiler.visit_concat_op_binary_op..rqrdrrrvisit_concat_op_binary_op7s z,_EvaluatorCompiler.visit_concat_op_binary_opcCs|dd|||S)NcSs ||Sr) startswithrnrrrr/Br0zB_EvaluatorCompiler.visit_startswith_op_binary_op..rqrdrrrvisit_startswith_op_binary_op>s z0_EvaluatorCompiler.visit_startswith_op_binary_opcCs|dd|||S)NcSs ||Sr)endswithrnrrrr/Ir0z@_EvaluatorCompiler.visit_endswith_op_binary_op..rqrdrrrvisit_endswith_op_binary_opEs z._EvaluatorCompiler.visit_endswith_op_binary_opcsH||j|jtjkr(fdd}|Stdt|jd|jdS)Ncs&|}|tkrtS|dkr dS| SrrX)r.r:Z eval_innerrrr[Ps z0_EvaluatorCompiler.visit_unary..evaluater#rQ)r)r*rMr invrr%r)rr&r[rryr visit_unaryLs   z_EvaluatorCompiler.visit_unarycs"|jr|n|jfddS)NcsSrrr-valrrr/cr0z4_EvaluatorCompiler.visit_bindparam..)callabler:r+rr|rvisit_bindparam^s z"_EvaluatorCompiler.visit_bindparam)N)(rrrr!r)r,r1r2r3rDrGrHrFrVr]r^rbrerirjrcrlZvisit_add_binary_opZvisit_mul_binary_opZvisit_sub_binary_opZvisit_mod_binary_opZvisit_truediv_binary_opZvisit_lt_binary_opZvisit_le_binary_opZvisit_ne_binary_opZvisit_gt_binary_opZvisit_ge_binary_opZvisit_eq_binary_oprrrsrtrvrxr{rrrrrr<sJ  6    rstrzType[_EvaluatorCompiler])namereturncCs.|dkrtddtStdtd|dS)NZEvaluatorCompilerzDirect use of 'EvaluatorCompiler' is not supported, and this name will be removed in a future release. '_EvaluatorCompiler' is for internal use onlyz2.0zmodule z has no attribute )rrAttributeErrorr)rrrr __getattr__fsrN)__doc__ __future__rtypingrrrBbaserrr sqlr r Z sql.sqltypesr r utilrZInvalidRequestErrorrZColumnOperatorsrrr5r8rrrrrr s*            ,