U kf @sddlmZddlmZddlZddlZddlZddlmZddlm Z ddlm Z ddlm Z ddlm Z ddlm Z dd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&dd l'm(Z(ejrdd!lm)Z)dd"lm*Z*dd#lm+Z+dd$lm,Z,dd%lm-Z-dd&lm.Z.dd'lm/Z/dd(lm0Z0dd)lm1Z1dd*l2m3Z3dd+l)m4Z4dd,l)m5Z5dd-l)m6Z6dd.l)m7Z7dd/l)m8Z8dd0l)m9Z9dd1l)m:Z:dd2l+m;Z;dd3l,mZ>dd6l,m?Z?dd7l,m@Z@dd8l,mAZAdd9lmBZBed:ejCd;ZDedejFd;ZGed?ed;ZHd@dAZIdBdCZJdDdDdDdEdFdGdHZKdDdDdIdJdKdLdMZLedNdOdOdDdPdQdRZMed=dSdTdOdUdOdDdVdWdRZMedXdOdOdYdPdZdRZMed[dOdOd\dPd]dRZMed^dOdOd_dPd`dRZMedadOdOdbdPdcdRZMedddedOdfdPdgdRZMedhdedOdidPdjdRZMedkdOdOdldPdmdRZMedndodOdpdPdqdRZMedrdsdOdsdPdtdRZMedudvdOdvdPdwdRZMedxdydOdzdPd{dRZMed=d|dxdvdUdOd}d~ddRZMedddOddPddRZMedddOddPddRZMeddOdOdOdPddRZMdddddddOdddddOdOdddRZMdTdOdOdDdPddZNd^dddddZOGdddZPGdddZQGdddZRGdddePZSGdddePZTde$jUddfdOddddddddZVGdddePZWGdddePZXGdddePZYGdddePZZGdddePZ[GdddePZ\GdddeTePZ]Gddde]ePZ^GdddePZ_GdddeTePZ`GdddeXeTePZaGdddeXePZbGdddeWePZcGdd„deSePZdGddĄdeXePZeGddƄdeXeTePejfZgGddȄdegePZhGddʄdegePZiGdd̄deSePZjGdd΄dePZkGddЄdeRePZlGdd҄deQeXePZmGddԄdeQeSePZnGddքdenZoGdd؄dePZpGddڄde]ZqGdd܄deZeXePZrGddބdePZsGdddeXePZtGdddeWePZuGdddesZvGdddePZwGdddePZxGdddeZeWePZyGdddeyZzGdddezZ{GdddeZeWePZ|GdddeWePZ}GdddeWePZ~iZeeD]JZeeeZedrFeddZeekrFeeeZeee<qFeseejZeeeefD]Zeeeje<qdS)) annotationsN)Any)Callable)cast)Dict)Iterable)Iterator)List)NoReturn)Optional)overload)Sequence)Tuple)Type) TYPE_CHECKING)TypeVar)Union) operators)roles)visitors)is_from_clause)ExecutableOption)Options) HasCacheKey) Visitable)exc) inspection)util)Literal)elements)lambdas)schema) selectable)_ColumnExpressionArgument)_ColumnsClauseArgument)_DDLColumnArgument)_DMLTableArgument)_FromClauseArgument)_DMLTableElement) BindParameter) ClauseElement) ColumnClause) ColumnElement)DQLDMLClauseElement) NamedColumn)SQLCoreOperations)Column)_ColumnsClauseElement)_JoinTargetProtocol) FromClause)HasCTE) SelectBase)Subquery)_TraverseCallableType_SR)bound_F. _StringOnlyR_TcCst|ttjf ot|d S)zhReturn whether or not the element is a "literal" in the context of a SQL expression construct. __clause_element__) isinstancerr#SchemaEventTargethasattr)elementrDH/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/sql/coercions.py _is_literalOs  rFcCsrt|tjr2t|ts2|D]}t|sdSqdSt|ttjtt t j j f opt |d opt|t ppt|t S)aReturn whether or not the element is a "literal" in the context of a SQL expression construct. does a deeper more esoteric check than _is_literal. is used for lambda elements that have to distinguish values that would be bound vs. not without any context. FTr?)r@collections_abcr str_deep_is_literalrr#rArrrZ langhelperssymbolrBtype issubclass)rCelemrDrDrErI[s,    rIrHzCallable[[_F], _F]) paramnamemeth_rst param_rstreturncCst|d||fS)Nz.. warning:: The %s argument to %s can be passed as a Python string argument, which will be treated as **trusted SQL text** and rendered as given. **DO NOT PASS UNTRUSTED INPUT TO THIS PARAMETER**.)rZadd_parameter_text)rNrOrPrDrDrE_document_text_coercions rRz+Union[Sequence[_T], Sequence[Sequence[_T]]] Sequence[_T])attrnamefnnameargsrQcCsb|rXt|dtttfrXt|dkrXt|dtrJtd|d|dtd|dStd|S)NrrzThe "z" argument to zt(), when referring to a sequence of items, is now passed as a series of positional elements, rather than as a list. rS)r@listsetdictlenr ArgumentErrorr)rTrUrVrDrDrE!_expression_collection_was_a_lists$r\zType[roles.TruncatedLabelRole]r)rolerCkwrQcKsdSNrDr]rCr^rDrDrEexpectsraas_keyzType[roles.DMLColumnRole]z Literal[True])r]rCrcr^rQcKsdSr_rD)r]rCrcr^rDrDrEraszType[roles.LiteralValueRole]zBindParameter[Any]cKsdSr_rDr`rDrDrErasz!Type[roles.DDLReferredColumnRole]z Column[Any]cKsdSr_rDr`rDrDrErasz#Type[roles.DDLConstraintColumnRole]zUnion[Column[Any], str]cKsdSr_rDr`rDrDrEraszType[roles.StatementOptionRole]r/cKsdSr_rDr`rDrDrErasz&Type[roles.LabeledColumnExprRole[Any]]z_ColumnExpressionArgument[_T]zNamedColumn[_T]cKsdSr_rDr`rDrDrEraszgUnion[Type[roles.ExpressionElementRole[Any]], Type[roles.LimitOffsetRole], Type[roles.WhereHavingRole]]zColumnElement[_T]cKsdSr_rDr`rDrDrEras zUnion[Type[roles.ExpressionElementRole[Any]], Type[roles.LimitOffsetRole], Type[roles.WhereHavingRole], Type[roles.OnClauseRole], Type[roles.ColumnArgumentRole]]zColumnElement[Any]cKsdSr_rDr`rDrDrEras zType[roles.DMLTableRole]r(r*cKsdSr_rDr`rDrDrEraszType[roles.HasCTERole]r6cKsdSr_rDr`rDrDrEraszType[roles.SelectStatementRole]r7cKsdSr_rDr`rDrDrEraszType[roles.FromClauseRole]r)r5cKsdSr_rDr`rDrDrEras)explicit_subqueryr8)r]rCrdr^rQcKsdSr_rD)r]rCrdr^rDrDrEraszType[roles.ColumnsClauseRole]z_ColumnsClauseArgument[Any]r3cKsdSr_rDr`rDrDrEra!szType[roles.JoinTargetRole]r4cKsdSr_rDr`rDrDrEra)sz Type[_SR]cKsdSr_rDr`rDrDrEra2sF)apply_propagate_attrsargname post_inspectdisable_inspectionzOptional[ClauseElement] Optional[str]bool)r]rCrerfrgrhr^rQc Ks|jr2t|r2t|dr2tj||tjf||dSt|}|}t|tj t j t j tj fsRd} |jrt|j|f|} n|}d} |jrt||rt|drd} n(t|drd} t|dds|}qqq| sL|jr*|s*tj|dd} | dk r*|r| jz | } Wn"tk r(|||YnX| dkrP|j|fd|i|} n|} n t|tj rn|jf|} n|} |dk rtjrt| ttfst|jst| d dr| j|_|j | j!j"kr|j#r|j#| f||d |} | S|j$|| fd|i|SdS) N__code__)reFr?Tis_clause_element)Zraiseerrrf_propagate_attrs)rforiginal_element)% allows_lambdacallablerBr"Z LambdaElementZ LambdaOptions _impl_lookupr@r!ZCompilerElementr#Z SchemaItemZ FetchedValueZ PyWrapper_resolve_literal_only_literal_coercion$_skip_clauseelement_for_target_matchgetattrr?_use_inspectionrinspectZ _post_inspectAttributeError_raise_for_expectedZ_sa__py_wrapper_literaltypingrr1r,AssertionErrorrm _role_class __class____mro___post_coercion_implicit_coercions) r]rCrerfrgrhr^implrnresolvedrlZinsprDrDrEra:s             cKs"|ddt||fddi|S)NrcT)poprar`rDrDrE expect_as_keys rzIterable[_DDLColumnArgument]zwIterator[Tuple[Union[str, Column[Any]], Optional[ColumnClause[Any]], Optional[str], Optional[Union[Column[Any], str]]]])r] expressionsrQc cs|D]~}d}d}t||}t|trcs z3InElementImpl._literal_coercion..T) expanding) rZis_non_string_iterablerWrFr@rZColumnOperatorsryr!r ClauseListr)rrCrrr^rrDrrErsNs&    zInElementImpl._literal_coercioncKs||jr|St|tjr8t|jdkr,t|j|dSt|tj r`|j dd}d|_ ||_ |St|t jrt|S|SdS)Nr)ZagainstT)Z maintain_key)rrr@r!rrZZclausesr{Z self_groupr+Z_clonerZ expand_opr$rZ scalar_values)rrCrrr^rDrDrErrs     zInElementImpl._post_coercion)N)rrrrrrrsrrDrDrDrEr0s $rc@s*eZdZdZdZddZddddZdS) OnClauseImplrDTcKs||dSr_rrrDrDrErsszOnClauseImpl._literal_coercionN)rncKst|tjr|S|Sr_)r@rJoinTargetRole)rrrnr^rDrDrErs zOnClauseImpl._post_coercion)rrrrrrsrrDrDrDrErsrc@seZdZdZdZdddZdS)WhereHavingImplrDTNcCs t||Sr_rrrDrDrErszWhereHavingImpl._text_coercion)NrrrrrrrDrDrDrErsrc@seZdZdZdZdddZdS)StatementOptionImplrDTNcCs t|Sr_r!rrrDrDrErsz"StatementOptionImpl._text_coercion)NrrDrDrDrErsrc@seZdZdZdS)ColumnArgumentImplrDNrrrrrDrDrDrErsrc@seZdZdZdS)ColumnArgumentOrKeyImplrDNrrDrDrDrErsrc@seZdZdZdddZdS)StrAsPlainColumnImplrDNcCs t|Sr_)r!r-rrDrDrErsz#StrAsPlainColumnImpl._text_coercion)N)rrrrrrDrDrDrErsrc@seZdZdZdZdddZdS)ByOfImplrDTNcCs t|Sr_)r!Z_textual_label_referencerrDrDrErszByOfImpl._text_coercion)NrrDrDrDrErsrc@seZdZdZddZdS) OrderByImplrDcKs(t||jr |jdk r t|S|SdSr_)r@r|Z_order_by_label_elementr!Z_label_reference)rrr^rDrDrErs   zOrderByImpl._post_coercionNrrDrDrDrErsrc@s(eZdZdZdddddddddZdS) GroupByImplrDNrrircKst|rtj|jS|SdSr_)rr!rcrrDrDrErs zGroupByImpl._implicit_coercions)NrrrrrrDrDrDrErsrc@seZdZdZddddZdS) DMLColumnImplrDFrbcKs|r |jS|SdSr_)key)rrCrcr^rDrDrErszDMLColumnImpl._post_coercionNrrDrDrDrErsrc@seZdZdZddddZdS) ConstExprImplrDNrcKs@|dkrtS|dkr tS|dkr0tS|||dS)NFT)r!rrrryrrDrDrErsszConstExprImpl._literal_coercionrrDrDrDrErsrc@s0eZdZdZd ddddddddZdd ZdS) TruncatedLabelImplrDNrrircKs t|tr|S||||dSr_rrrDrDrErs z&TruncatedLabelImpl._implicit_coercionscKst|tjr|St|SdS)zcoerce the given value to :class:`._truncated_label`. Existing :class:`._truncated_label` and :class:`._anonymous_label` objects are passed unchanged. N)r@r!Z_truncated_labelrrDrDrErss z$TruncatedLabelImpl._literal_coercion)NrrDrDrDrErs rc@seZdZdZdZdddZdS)DDLExpressionImplrDTNcCs t|Sr_rrrDrDrErsz DDLExpressionImpl._text_coercion)NrrDrDrDrErsrc@seZdZdZdS)DDLConstraintColumnImplrDNrrDrDrDrEr#src@seZdZdZdS)DDLReferredColumnImplrDNrrDrDrDrEr'src@s0eZdZdZd ddddddddZdd ZdS) LimitOffsetImplrDNrrircKs|dkr dS||||dSr_rrrDrDrEr.sz#LimitOffsetImpl._implicit_coercionscKs,|dkr dSt|}tj|||ddSdS)NT)rr)rZasintr$Z_OffsetLimitParam)rrCrrr^valuerDrDrErs:s z!LimitOffsetImpl._literal_coercion)NrrDrDrDrEr+s rcs0eZdZdZdddddddfdd ZZS) LabeledColumnExprImplrDNrrirc sXt|tjr|dStj||fd|i|}t|tjrF|dS||||dSNrf)r@rExpressionElementRolelabelrrry)rrCrrfr^newrrDrErIs    z)LabeledColumnExprImpl._implicit_coercions)N)rrrrrrrDrDrrErFsrcsLeZdZdZdZdZdZedej Z d ddfdd Z d dd Z Z S) ColumnsClauseImplrDTz^\w\S*$N)rc sF|s*t|tr*dddd|Dd}tj|f|||d|S)NzDid you mean to say select(z, css|]}t|VqdSr_)r)rerDrDrE jsz8ColumnsClauseImpl._raise_for_expected..z)?r)r@rWjoinrry)rrCrfrrr^rrDrEryesz%ColumnsClauseImpl._raise_for_expectedcCsLt|}|j| }tdt||r2d|fnd|reZdZdZddddZd ddddddfd d ZZS) StatementImplrDNrcKsF||k rBt|tsBz |jWn$tk r@td|dYnX|S)NaObject %r should not be used directly in a SQL statement context, such as passing to methods such as session.execute(). This usage will be disallowed in a future release. Please use Core select() / update() / delete() etc. with Session.execute() and other statement execution methods.1.4)r@rHZ_execute_on_connectionrxrwarn_deprecated)rrrnrfr^rDrDrErs   zStatementImpl._post_coercionrrirc s(|jr |Stj||fd|i|SdSr)rrrrrrDrErsz!StatementImpl._implicit_coercions)N)rrrrrrrrDrDrrErs  rc@s(eZdZdZdddddddddZdS) SelectStatementImplrDNrrircKs |jr|S||||dSr_)_is_text_clausecolumnsryrrDrDrErsz'SelectStatementImpl._implicit_coercions)NrrDrDrDrErsrc@seZdZdZdS) HasCTEImplrDNrrDrDrDrErsrc@seZdZdZdS) IsCTEImplrDNrrDrDrDrErsrc @sBeZdZdZdZddddZdddd d d d d d d d dZdS)JoinTargetImplrDTNrcKs|||dSr_rrrDrDrErssz JoinTargetImpl._literal_coercionF)legacyrrirj)rCrrfrr^rQcKs>t|tjr|S|r,|jr,tjddd|S||||dSNzImplicit coercion of SELECT and textual SELECT constructs into FROM clauses is deprecated; please call .subquery() on any Core select or ORM Query object in order to produce a subquery object.r)version)r@rrrrrry)rrCrrfrr^rDrDrErs   z"JoinTargetImpl._implicit_coercions)N)rrrrrtrsrrDrDrDrErsrc @sBeZdZdZdddddddddddd d d Zdd d dZdS)FromClauseImplrDNFT)rd allow_selectrrirj)rCrrfrdrr^rQcKsH|jr,|r|S|rDtjddd|jSn|jr6|S||||dSr)rZsubqueryrr_implicit_subqueryrry)rrCrrfrdrr^rDrDrErs z"FromClauseImpl._implicit_coercions) deannotatecKs|r |S|SdSr_)Z _deannotate)rrCr!r^rDrDrErszFromClauseImpl._post_coercion)N)rrrrrrrDrDrDrErsrc @s0eZdZdZd dddddddddd d ZdS) StrictFromClauseImplrDNF)rrrirj)rCrrfrr^rQcKs0|jr|rtjddd|jS||||dSr)rrrr ry)rrCrrfrr^rDrDrErs z(StrictFromClauseImpl._implicit_coercions)NrrDrDrDrEr"s r"c@s eZdZdZdddddZdS)AnonymizedFromClauseImplrDFN)flatrcKs|dks t|j|dS)N)r$)r{Z_anonymous_fromclause)rrCr$rr^rDrDrEr3s z'AnonymizedFromClauseImpl._post_coercionrrDrDrDrEr#0sr#c@seZdZdZddZdS) DMLTableImplrDcKsd|jkr|jdS|SdS)NZ dml_table)Z _annotationsrrDrDrEr<s  zDMLTableImpl._post_coercionNrrDrDrDrEr%9sr%c@s(eZdZdZdddddddddZdS) DMLSelectImplrDNrrircKs<|jr*t|tjr |jjr |jS|Sn||||dSr_)rr@r$rrCrrryrrDrDrErFs  z!DMLSelectImpl._implicit_coercions)NrrDrDrDrEr&Csr&cs"eZdZdZdfdd ZZS)CompoundElementImplrDNc s>t|tjr|jrd}q"d}nd}tj|f|||d|S)NzFUse the plain select() object without calling .subquery() or .alias().z9To SELECT from any FROM clause, use the .select() method.r)r@rZFromClauseRoleZ _is_subqueryrryrrrDrEry\s  z'CompoundElementImpl._raise_for_expected)NNrrDrDrrEr'Ysr'ZRoleZImpl) __future__rcollections.abcabcrGrrrzrrrrrrr r r r r rrrrrrrrrZ_typingrbaserr cache_keyrrrrrZ util.typingr r!r"r#r$r%r&r'r(r)Zdmlr*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9ZSQLRoler:r<Z StringRoler=r>rFrIrRr\rarrrrrrrr[rrrrrrrrrrrrrrrrZByOfRolerrrrrrrrrrrrrrrrrrrr"r#r%r&r'rqdirrruclsendswithreplaceglobalsrrZee_implintrjrHfloatZpy_typerDrDrDrE sT                                                         &      t7   )+W      )*'%