https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/db/models/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/db/models/__pycache__/expressions.cpython-310.pyc
o

��Ih��@s�ddlZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
ddlmZm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZddlmZGdd
�d
�ZGdd�d�ZGdd�d�ZeGdd�dee��Zdd�ejejej ej!fD�Z"ej#dd�dd��Z$Gdd�dee�Z%Gdd�de%�Z&Gdd�de%�Z'eGd d!�d!e��Z(Gd"d#�d#e(�Z)Gd$d%�d%e(�Z*Gd&d'�d'ee�Z+Gd(d)�d)e�Z,Gd*d+�d+e�Z-Gd,d-�d-e�Z.Gd.d/�d/e�Z/Gd0d1�d1e�Z0Gd2d3�d3e+�Z1Gd4d5�d5e�Z2Gd6d7�d7e�Z3Gd8d9�d9e�Z4Gd:d;�d;ee�Z5Gd<d=�d=e5�Z6Gd>d?�d?e�Z7Gd@dA�dAee�Z8GdBdC�dCe�Z9GdDdE�dEe9�Z:GdFdG�dGe9�Z;dS)H�N��Decimal)�UUID)�EmptyResultSet�
FieldError)�NotSupportedError�
connection)�fields)�
LOOKUP_SEP)�Q)�deconstructible)�cached_property)�
make_hashablec@�eZdZdZdd�ZdS)�SQLiteNumericMixinzp
    Some expressions with output_field=DecimalField() must be cast to
    numeric to be properly filtered.
    cKs\|j||fi|��\}}z|j��dkrd|}W||fSW||fSty-Y||fSw)N�DecimalFieldzCAST(%s AS NUMERIC))�as_sql�output_field�get_internal_typer)�self�compilerr�
extra_context�sql�params�r�>/usr/lib/python3/dist-packages/django/db/models/expressions.py�	as_sqlites
���zSQLiteNumericMixin.as_sqliteN)�__name__�
__module__�__qualname__�__doc__rrrrrrsrc@s�eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1d2�Z!d3d4�Z"d5d6�Z#d7d8�Z$d9d:�Z%d;S)<�
Combinablezu
    Provide the ability to combine one or two objects with
    some connector. For example F('foo') + F('bar').
    �+�-�*�/�^z%%�&�|z<<z>>�#cCs.t|d�s	t|�}|rt|||�St|||�S)N�resolve_expression)�hasattr�Value�CombinedExpression)r�other�	connector�reversedrrr�_combine:s

zCombinable._combinecCs|�d|jd�S)N���F�r1�MUL�rrrr�__neg__G�zCombinable.__neg__cC�|�||jd�S�NF�r1�ADD�rr.rrr�__add__Jr7zCombinable.__add__cCr8r9�r1�SUBr<rrr�__sub__Mr7zCombinable.__sub__cCr8r9r3r<rrr�__mul__Pr7zCombinable.__mul__cCr8r9�r1�DIVr<rrr�__truediv__Sr7zCombinable.__truediv__cCr8r9�r1�MODr<rrr�__mod__Vr7zCombinable.__mod__cCr8r9�r1�POWr<rrr�__pow__Yr7zCombinable.__pow__cCs0t|dd�rt|dd�rt|�t|�@Std���N�conditionalF�:Use .bitand() and .bitor() for bitwise logical operations.��getattrr�NotImplementedErrorr<rrr�__and__\�
�zCombinable.__and__cCr8r9)r1�BITANDr<rrr�bitandcr7zCombinable.bitandcCr8r9)r1�BITLEFTSHIFTr<rrr�bitleftshiftfr7zCombinable.bitleftshiftcCr8r9)r1�
BITRIGHTSHIFTr<rrr�
bitrightshiftir7zCombinable.bitrightshiftcCr8r9)r1�BITXORr<rrr�bitxorlr7zCombinable.bitxorcCs0t|dd�rt|dd�rt|�t|�BStd��rKrNr<rrr�__or__orRzCombinable.__or__cCr8r9)r1�BITORr<rrr�bitorvr7zCombinable.bitorcCr8�NTr:r<rrr�__radd__yr7zCombinable.__radd__cCr8r^r>r<rrr�__rsub__|r7zCombinable.__rsub__cCr8r^r3r<rrr�__rmul__r7zCombinable.__rmul__cCr8r^rBr<rrr�__rtruediv__�r7zCombinable.__rtruediv__cCr8r^rEr<rrr�__rmod__�r7zCombinable.__rmod__cCr8r^rHr<rrr�__rpow__�r7zCombinable.__rpow__cC�td���NrM�rPr<rrr�__rand__���zCombinable.__rand__cCrerfrgr<rrr�__ror__�rizCombinable.__ror__N)&rrrr r;r?r4rCrIrFrSr\rUrWrYr1r6r=r@rArDrGrJrQrTrVrXrZr[r]r_r`rarbrcrdrhrjrrrrr!!sH
r!c@s2eZdZdZdZdZdZdZd?dd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zedd��Zedd��Zedd��Zd@dd�Zedd��Zedd��Zedd ��Zed!d"��Zd#d$�Zed%d&��Zed'd(��Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d?d1d2�Z!d3d4�Z"d5d6�Z#d7d8�Z$d9d:�Z%d;d<�Z&d=d>�Z'dS)A�BaseExpressionz%Base class for all query expressions.FTNcCs|dur	||_dSdS�N�r�rrrrr�__init__�s
�zBaseExpression.__init__cCs|j��}|�dd�|S)N�
convert_value)�__dict__�copy�pop)r�staterrr�__getstate__��
zBaseExpression.__getstate__cCs$|j|jurgn|jg|j�|�Srl)rp�_convert_value_noopr�get_db_converters�rrrrrrx�s
�
�z BaseExpression.get_db_converterscC�gSrlrr5rrr�get_source_expressions��z%BaseExpression.get_source_expressionscCs|rJ�dSrlr�r�exprsrrr�set_source_expressions��z%BaseExpression.set_source_expressionscGsdd�|D�S)NcSs4g|]}t|d�r|nt|t�rt|�nt|��qS�r*)r+�
isinstance�str�Fr,��.0�argrrr�
<listcomp>�s
��z5BaseExpression._parse_expressions.<locals>.<listcomp>r)r�expressionsrrr�_parse_expressions�s�z!BaseExpression._parse_expressionscCre)a�
        Responsible for returning a (sql, [params]) tuple to be included
        in the current query.

        Different backends can provide their own implementation, by
        providing an `as_{vendor}` method and patching the Expression:

        ```
        def override_as_sql(self, compiler, connection):
            # custom logic
            return super().as_sql(compiler, connection)
        setattr(Expression, 'as_' + connection.vendor, override_as_sql)
        ```

        Arguments:
         * compiler: the query compiler responsible for generating the query.
           Must have a compile method, returning a (sql, [params]) tuple.
           Calling compiler(value) will return a quoted `value`.

         * connection: the database connection used for the current query.

        Return: (sql, params)
          Where `sql` is a string containing ordered sql parameters to be
          replaced with the elements of the list `params`.
        z"Subclasses must implement as_sql()rg�rrrrrrr�szBaseExpression.as_sqlcC�tdd�|��D��S)Ncs��|]}|o|jVqdSrl)�contains_aggregate�r��exprrrr�	<genexpr>���z4BaseExpression.contains_aggregate.<locals>.<genexpr>��anyr{r5rrrr���z!BaseExpression.contains_aggregatecCr�)Ncsr�rl)�contains_over_clauser�rrrr��r�z6BaseExpression.contains_over_clause.<locals>.<genexpr>r�r5rrrr��r�z#BaseExpression.contains_over_clausecCr�)Ncsr�rl)�contains_column_referencesr�rrrr��r�z<BaseExpression.contains_column_references.<locals>.<genexpr>r�r5rrrr��r�z)BaseExpression.contains_column_referencescs4|��}�|_|�����fdd�|��D��|S)a

        Provide the chance to do any preprocessing or validation before being
        added to the query.

        Arguments:
         * query: the backend query implementation
         * allow_joins: boolean allowing or denying use of joins
           in this query
         * reuse: a set of reusable joins for multijoins
         * summarize: a terminal aggregate clause
         * for_save: whether this expression about to be used in a save or update

        Return: an Expression to be added to the query.
        cs$g|]}|r|������nd�qSrlr�r���allow_joins�query�reuse�	summarizerrr��s���z5BaseExpression.resolve_expression.<locals>.<listcomp>)rr�
is_summaryrr{�rr�r�r�r��for_save�crr�rr*�s�z!BaseExpression.resolve_expressioncCst|jtj�Srl)r�rr	�BooleanFieldr5rrrrL�szBaseExpression.conditionalcC�|jSrlrmr5rrr�fieldszBaseExpression.fieldcCs"|��}|durd|_td��|S)z+Return the output type of this expressions.NTz4Cannot resolve expression type, unknown output_field)�_resolve_output_field�_output_field_resolved_to_nonerrnrrrrs
zBaseExpression.output_fieldcCs&z|jWSty|js�YdSw)z�
        Return the output field of this expression, or None if
        _resolve_output_field() didn't return an output type.
        N)rrr�r5rrr�_output_field_or_nones��z$BaseExpression._output_field_or_nonecCsTdd�|��D�}|D]}|D]}t||j�s#td|jj|jjf��q|SdS)a�
        Attempt to infer the output type of the expression. If the output
        fields of all source fields match then, simply infer the same type
        here. This isn't always correct, but it makes sense most of the time.

        Consider the difference between `2 + 2` and `2 / 3`. Inferring
        the type here is a convenience for the common case. The user should
        supply their own output_field with more complex computations.

        If a source's output field resolves to None, exclude it from this check.
        If all sources are None, then an error is raised higher up the stack in
        the output_field property.
        css�|]	}|dur|VqdSrlr)r��sourcerrrr�)s�z7BaseExpression._resolve_output_field.<locals>.<genexpr>zCExpression contains mixed types: %s, %s. You must set output_field.N)�get_source_fieldsr��	__class__rr)r�sources_iterrr�rrrr�s�����z$BaseExpression._resolve_output_fieldcC�|Srlr��value�
expressionrrrrrw6�z"BaseExpression._convert_value_noopcCsF|j}|��}|dkrdd�S|�d�rdd�S|dkr dd�S|jS)z�
        Expressions provide their own converters because users have the option
        of manually specifying the output_field which may be a different type
        from the one the database returns.
        �
FloatFieldcS�|durdSt|�Srl)�floatr�rrr�<lambda>D�z.BaseExpression.convert_value.<locals>.<lambda>�IntegerFieldcSr�rl)�intr�rrrr�Fr�rcSr�rlrr�rrrr�Hr�)rr�endswithrw)rr��
internal_typerrrrp:s
zBaseExpression.convert_valuecC�|j�|�Srl)r�
get_lookup)r�lookuprrrr�Kr�zBaseExpression.get_lookupcCr�rl)r�
get_transform�r�namerrrr�Nr�zBaseExpression.get_transformcs(|��}|��fdd�|��D��|S)Ncs"g|]
}|dur
|���nd�qSrl)�relabeled_clone�r��e��
change_maprrr�Ss��z2BaseExpression.relabeled_clone.<locals>.<listcomp>)rrrr{)rr��clonerr�rr�Qs
�zBaseExpression.relabeled_clonecCs
t�|�Srl)rrr5rrrrrY�
zBaseExpression.copycCs0|js|gSg}|��D]	}|�|���q|Srl)r�r{�extend�get_group_by_cols�r�alias�colsr�rrrr�\sz BaseExpression.get_group_by_colscCsdd�|��D�S)z9Return the underlying field types used by this aggregate.cSsg|]}|j�qSr)r�r�rrrr�fsz4BaseExpression.get_source_fields.<locals>.<listcomp>)r{r5rrrr�d�z BaseExpression.get_source_fieldscK�t|fi|��Srl��OrderBy�r�kwargsrrr�aschr7zBaseExpression.asccK�t|fddi|��S�N�
descendingTr�r�rrr�desck�zBaseExpression.desccCr�rlrr5rrr�reverse_orderingnr|zBaseExpression.reverse_orderingccs>�|V|��D]}|rt|d�r|��EdHq|VqdS)zi
        Recursively yield this expression and all subexpressions, in
        depth-first order.
        �flattenN)r{r+r�)rr�rrrr�qs�
��zBaseExpression.flattencCs$t|jd�r|j�|||�S||fS)z�
        Custom format for select clauses. For example, EXISTS expressions need
        to be wrapped in CASE WHEN on Oracle.
        �
select_format)r+rr��rrrrrrrr�~szBaseExpression.select_formatrl�NTNFF)(rrrr r�r��
filterable�window_compatiblerorurxr{rr�rr
r�r�r�r*�propertyrLr�rr�r��staticmethodrwrpr�r�r�rrr�r�r�r�r�r�r�rrrrrk�sX












rkc@s,eZdZdZedd��Zdd�Zdd�ZdS)	�
Expressionz:An expression that can be combined with other expressions.c	Cs�t�|j�}|j\}}|j|i|��}|��|j��}|jg}|D])\}}t	|t
j�r@|jr;|j
r;|j
jj|jf}n	t|�}nt|�}|�||f�q"t|�Srl)�inspect�	signaturero�_constructor_args�bind_partial�apply_defaults�	arguments�itemsr�r�r	�Fieldr��model�_meta�label�typer�append�tuple)	r�constructor_signature�argsr�r�r��identityr�r�rrrr��s


zExpression.identitycCst|t�stS|j|jkSrl)r�r��NotImplementedr�r<rrr�__eq__�s
zExpression.__eq__cC�
t|j�Srl)�hashr�r5rrr�__hash__�r�zExpression.__hash__N)rrrr r
r�r�r�rrrrr��s
r�c
CsXi|](}|tjtjtjftjtjtjftjtjtjftjtjtjftjtjtjfg�qSr)r	r�rr�)r�r/rrr�
<dictcomp>�s���r��)�maxsizecCs<t�|d�}|D]\}}}t||�rt||�r|SqdS)Nr)�_connector_combinators�get�
issubclass)r/�lhs_type�rhs_type�combinators�combinator_lhs_type�combinator_rhs_type�
combined_typerrr�_resolve_combined_type�s��rcs\eZdZd�fdd�	Zdd�Zdd�Zdd	�Zd
d�Z�fdd
�Zdd�Z	ddd�Z
�ZS)r-Ncs$t�j|d�||_||_||_dS�Nrm)�superror/�lhs�rhs)rrr/rr�r�rrro�s
zCombinedExpression.__init__cCsd�|jj|�S)Nz<{}: {}>)�formatr�rr5rrr�__repr__�r7zCombinedExpression.__repr__cCsd�|j|j|j�S)Nz{} {} {})r	rr/rr5rrr�__str__�r�zCombinedExpression.__str__cC�|j|jgSrl�rrr5rrrr{�r�z)CombinedExpression.get_source_expressionscC�|\|_|_dSrlr
r}rrrr�r7z)CombinedExpression.set_source_expressionscsNzt���WSty&t|jt|jj�t|jj��}|dur!�|�YSwrl)	rr�rrr/r�rrr)rrrrrr��s

�
�z(CombinedExpression._resolve_output_fieldcCspg}g}|�|j�\}}|�|�|�|�|�|j�\}}|�|�|�|�d}|j�|j|�}|||fS�Nz(%s))�compilerr�r�r�ops�combine_expressionr/�rrrr��expression_paramsrr�expression_wrapperrrrr�s



zCombinedExpression.as_sqlTFc	Cs|j�|||||�}|j�|||||�}t|ttf�sz|j��}Wn
tt	fy/d}Ynwz|j��}	Wn
tt	fyDd}	Ynwd||	hvr_||	kr_t|j|j
|j��|||||�Shd�}
|j
|jkr||
vr||	krt|j|j��|||||�S|��}||_
||_||_|S)N�
DurationField>�	DateField�	TimeField�
DateTimeField)rr*rr��DurationExpression�TemporalSubtractionrr�AttributeErrorrr/r?rrr�)rr�r�r�r�r�rrr�r��datetime_fieldsr�rrrr*�s6��
�
�z%CombinedExpression.resolve_expressionrlr�)rrrror
rr{rr�rr*�
__classcell__rrrrr-�s
r-cs$eZdZdd�Z�fdd�Z�ZS)rcCsRz|j}Wn	tyYnw|��dkr$|�|�\}}|j�|�|fS|�|�S)Nr)rrrrr�format_for_duration_arithmetic)r�siderr�outputrrrrrrs
�
zDurationExpression.compilecs�|jjrt��||�S|j�|�g}g}|�|j||�\}}|�|�|�	|�|�|j
||�\}}|�|�|�	|�d}|j�|j|�}|||fSr)
�features�has_native_duration_fieldrrr�check_expression_supportrrr�r�r�combine_duration_expressionr/rrrrrs



zDurationExpression.as_sql)rrrrrrrrrrrsrcs,eZdZe��Z�fdd�Zdd�Z�ZS)rcst��||j|�dSrl)rror?)rrrrrrro(�zTemporalSubtraction.__init__cCs<|j�|�|�|j�}|�|j�}|j�|jj��||�Srl)rr$rrr�subtract_temporalsrr)rrrrrrrrr+szTemporalSubtraction.as_sql)	rrrr	rrrorrrrrrr%src@sNeZdZdZdd�Zdd�Z		dd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dS)r�zDAn object capable of resolving references to existing query objects.cCs
||_dS)z^
        Arguments:
         * name: the name of the field this expression references
        N)r�r�rrrro6s
z
F.__init__cC�d�|jj|j�S�N�{}({}))r	r�rr�r5rrrr
=�z
F.__repr__NTFcCs|�|j|||�Srl)�resolve_refr��rr�r�r�r�r�rrrr*@r�zF.resolve_expressioncKr�rlr�r�rrrr�Dr7zF.asccKr�r�r�r�rrrr�Gr�zF.desccCs|j|jko|j|jkSrl)r�r�r<rrrr�J�zF.__eq__cCr�rl)r�r�r5rrrr�Mr�z
F.__hash__r�)rrrr ror
r*r�r�r�r�rrrrr�2s
�r�cs>eZdZdZdZdd�Z�fdd�Zdd�Zdd
d�Z�Z	S)
�ResolvedOuterRefz�
    An object that contains a reference to an outer query.

    In this case, the reference to the outer query has been resolved because
    the inner query has been used as a subquery.
    FcOre)NzXThis queryset contains a reference to an outer query and may only be used in a subquery.)�
ValueError�rr�r�rrrrZrizResolvedOuterRef.as_sqlcs"t�j|i|��}t|jv|_|Srl)rr*r
r��possibly_multivalued)rr�r��colrrrr*`sz#ResolvedOuterRef.resolve_expressioncCr�rlr�r�relabelsrrrr�hr|z ResolvedOuterRef.relabeled_cloneNcCrzrlr�rr�rrrr�kr|z"ResolvedOuterRef.get_group_by_colsrl)
rrrr r�rr*r�r�rrrrrr/Qsr/c@s eZdZdZdd�Zdd�ZdS)�OuterRefFcOst|j|j�r
|jSt|j�Srl)r�r�r�r/r1rrrr*rs
zOuterRef.resolve_expressioncCr�rlrr4rrrr�wr|zOuterRef.relabeled_cloneN)rrrr�r*r�rrrrr7osr7csveZdZdZdZdZdZdZdd��fdd�
Zdd	�Z	d
d�Z
dd
�Zdd�Zddd�Z
ddd�Z�fdd�Z�ZS)�FunczAn SQL function call.Nz%(function)s(%(expressions)s)�, rmcsh|jdur"t|�|jkr"td|jj|j|jdkrdndt|�f��t�j|d�|j|�|_||_	dS)Nz#'%s' takes exactly %s %s (%s given)��argumentr�rm)
�arity�len�	TypeErrorr�rrror��source_expressions�extra)rrr�r@rrrro�s��
z
Func.__init__cCsl|j�dd�|jD��}i|j�|���}|r.d�dd�t|���D��}d�|jj	||�Sd�|jj	|�S)Ncs��|]}t|�VqdSrl�r�r�rrrr����z Func.__repr__.<locals>.<genexpr>r9css(�|]\}}t|�dt|�VqdS)�=NrB)r��key�valrrrr��s�&�
{}({}, {})r*)
�
arg_joiner�joinr?r@�_get_repr_options�sortedr�r	r�r)rr�r@rrrr
�sz
Func.__repr__cCsiS)zAReturn a dict of extra __init__() options to include in the repr.rr5rrrrJ�r�zFunc._get_repr_optionscCr�rl�r?r5rrrr{��zFunc.get_source_expressionscCs
||_dSrlrLr}rrrr�r�zFunc.set_source_expressionsTFc	Cs>|��}||_t|j�D]\}}|�|||||�|j|<q|Srl)rrr��	enumerater?r*)	rr�r�r�r�r�r��posr�rrrr*�s
zFunc.resolve_expressionc
Ks�|j�|�g}g}|jD]}	|�|	�\}
}|�|
�|�|�q
i|j�|�}|dur1||d<n|�d|j�|p@|�	d|j
�}|pI|�	d|j�}|�|�|d<|d<|||fS)N�function�templaterHr�r�)
rr$r?rr�r�r@�
setdefaultrPr�rQrHrI)
rrrrPrQrHr�	sql_partsrr��arg_sql�
arg_params�datarrrr�s


zFunc.as_sqlcs*t���}|jdd�|_|j��|_|Srl)rrrr?r@)rrrrrrrr�s
z	Func.copyr�)NNN)rrrr rPrQrHr<ror
rJr{rr*rrrrrrrrr8{s

r8csVeZdZdZdZd�fdd�	Zdd�Zdd	�Zd�fdd�	Zdd
d�Z	dd�Z
�ZS)r,z9Represent a wrapped value as a node within an expression.FNcst�j|d�||_dS)a:
        Arguments:
         * value: the value this expression represents. The value will be
           added into the sql parameter list and properly quoted.

         * output_field: an instance of the model field type that this
           expression will return, such as IntegerField() or CharField().
        rmN)rror�)rr�rrrrro�s	
zValue.__init__cCr(r))r	r�rr�r5rrrr
�r+zValue.__repr__cCs||j�|�|j}|j}|dur1|jr|j||d�}n|j||d�}t|d�r1|�|||�|gfS|dur9dgfSd|gfS)N)r�get_placeholder�NULLz%s)	rr$r�r�r��get_db_prep_save�get_db_prep_valuer+rW)rrrrFrrrrr�s

zValue.as_sqlTcst��|||||�}||_|Srl)rr*r�r�rrrr*�szValue.resolve_expressioncCrzrlrr6rrrr��r|zValue.get_group_by_colscCs�t|jt�r
t��St|jt�rt��St|jt�rt��St|jt	�r(t�
�St|jtj�r3t��St|jtj
�r>t��St|jtj�rIt��St|jtj�rTt��St|jt�r^t��St|jt�rht��St|jt�rrt��SdSrl)r�r�r�r	�	CharField�boolr�r�r�r�r��datetimer�dater�timer�	timedeltarrr�bytes�BinaryFieldr�	UUIDFieldr5rrrr��s.�zValue._resolve_output_fieldrlr�)rrrr r�ror
rr*r�r�rrrrrr,�s
r,csFeZdZd�fdd�	Zdd�Zdd�Zddd	�Zd�fdd
�	Z�ZS)�RawSQLNcs0|durt��}|||_|_t�j|d�dSr)r	r�rrrro)rrrrrrrroszRawSQL.__init__cC�d�|jj|j|j�S�NrG)r	r�rrrr5rrrr
r&zRawSQL.__repr__cCsd|j|jfSr)rrr�rrrrr7z
RawSQL.as_sqlcC�|gSrlrr6rrrr�rMzRawSQL.get_group_by_colsTFc
sh|jj��D]#}|jjD]}|��\}}	|	��|j��vr(|�|j|||�nqqt	��
|||||�Srl)r�r��get_parent_list�local_fields�get_attname_column�lowerrr,r�rr*)
rr�r�r�r�r��parent�parent_field�_�column_namerrrr*s��zRawSQL.resolve_expressionrlr�)	rrrror
rr�r*rrrrrrd
s
rdc@seZdZdd�Zdd�ZdS)�StarcCsdS)Nz'*'rr5rrrr
)r|z
Star.__repr__cCsdgfS)Nr$rr�rrrr,�zStar.as_sqlN)rrrr
rrrrrrp(srpcsPeZdZdZdZd�fdd�	Zdd�Zdd	�Zd
d�Zddd
�Z	dd�Z
�ZS)�ColTFNcs,|dur|}t�j|d�|||_|_dSr)rror��target)rr�rsrrrrro5szCol.__init__cCs>|j|j}}|r|t|�fnt|�f}d�|jjd�|��S)Nr*r9)r�rsr�r	r�rrI)rr�rs�identifiersrrrr
;szCol.__repr__cCs<|j|jj}}|r||fn|f}d�t|j|��}|gfS)N�.)r�rs�columnrI�map�quote_name_unless_alias)rrrr�rvrtrrrrr@sz
Col.as_sqlcCs,|jdur|S|�|�|j|j�|j|j�Srl)r�r�r�rsrr4rrrr�Fs
zCol.relabeled_clonecCrgrlrr6rrrr�KrMzCol.get_group_by_colscCs0|j|jkr|j�|�S|j�|�|j�|�Srl)rsrrxryrrrrxNs


�zCol.get_db_convertersrl)rrrr�r2ror
rr�r�rxrrrrrrr0s
rrcs\eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zdd
d�Zdd�Z	dd�Z
ddd�Z�ZS)�Refz~
    Reference to column alias of the query. For example, Ref('sum_cost') in
    qs.annotate(sum_cost=Sum('cost')) query.
    cst���|||_|_dSrl)rro�refsr�)rrzr�rrrroZs
zRef.__init__cCrerf)r	r�rrzr�r5rrrr
^r&zRef.__repr__cC�|jgSrl�r�r5rrrr{arqzRef.get_source_expressionscCs|\|_dSrlr|r}rrrrdr�zRef.set_source_expressionsNTFcCr�rlrr-rrrr*gszRef.resolve_expressioncCr�rlrr4rrrr�lr|zRef.relabeled_clonecCs|j�|j�gfSrl)r�
quote_namerzr�rrrror+z
Ref.as_sqlcCrgrlrr6rrrr�rrMzRef.get_group_by_colsr�rl)
rrrr ror
r{rr*r�rr�rrrrrryUs
rycs4eZdZdZdZ�fdd�Zdd�Zdd�Z�ZS)	�ExpressionListz�
    An expression containing multiple expressions. Can be used to provide a
    list of expressions as an argument to another expression, like an
    ordering clause.
    z%(expressions)scs*|s
td|jj��t�j|i|��dS)Nz$%s requires at least one expression.)r0r�rrro)rr�r@rrrro~szExpressionList.__init__cCs|j�dd�|jD��S)NcsrArlrBr�rrrr��rCz)ExpressionList.__str__.<locals>.<genexpr>)rHrIr?r5rrrr�r.zExpressionList.__str__cKs|j||fi|��Srl)r)rrrrrrrr�szExpressionList.as_sqlite)	rrrr rQrorrrrrrrr~vsr~csNeZdZdZ�fdd�Zdd�Zdd�Zd�fd	d
�	Zdd�Zd
d�Z	�Z
S)�ExpressionWrapperz�
    An expression that can wrap another expression so that it can provide
    extra context to the inner expression, such as the output_field.
    cst�j|d�||_dSr)rror�)rr�rrrrro�s
zExpressionWrapper.__init__cC�|d|_dS�Nr�r�r}rrrr��z(ExpressionWrapper.set_source_expressionscCr{rlr�r5rrrr{�rqz(ExpressionWrapper.get_source_expressionsNcs4t|jt�r|j��}|j|_|j|d�St���S)N)r�)r�r�r�rrrr�r)rr�r�rrrr��s


z#ExpressionWrapper.get_group_by_colscCs|�|j�Srl)rr�r�rrrr�r�zExpressionWrapper.as_sqlcCr(r))r	r�rr�r5rrrr
�r+zExpressionWrapper.__repr__rl)rrrr rorr{r�rr
rrrrrr�s	rcsleZdZdZdZd�fdd�	Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
ddd�Zddd�Zddd�Z
�ZS)�Whenz"WHEN %(condition)s THEN %(result)sFNcs�|r"|durtdi|��d}}nt|dd�r"t|fi|��d}}|dus.t|dd�r.|r2td��t|t�r=|s=td��t�jdd�||_|�|�d|_	dS)NrLFzLWhen() supports a Q object, a boolean expression, or lookups as a condition.z1An empty Q() can't be used as a When() condition.rmrr)
rrOr>r�r0rro�	conditionr��result)rr��then�lookupsrrrro�s�z
When.__init__cCsd|j|jfS)NzWHEN %r THEN %r�r�r�r5rrrr�r7zWhen.__str__cC�d|jj|fS�Nz<%s: %s>�r�rr5rrrr
�r7z
When.__repr__cCrrlr�r5rrrr{�r�zWhen.get_source_expressionscCrrlr�r}rrrr�r7zWhen.set_source_expressionscCs
|jjgSrl)r�r�r5rrrr��s
zWhen.get_source_fieldsTcCsJ|��}||_t|jd�r|j�||||d�|_|j�|||||�|_|S)Nr*F)rrr�r+r�r*r�r�rrrr*�szWhen.resolve_expressioncKsn|j�|�|}g}|�|j�\}}||d<|�|�|�|j�\}	}
|	|d<|�|
�|p0|j}|||fS)Nr�r�)rr$rr�r�r�rQ)rrrrQr�template_params�
sql_params�
condition_sql�condition_params�
result_sql�
result_paramsrrrr�s


zWhen.as_sqlcC�$g}|��D]	}|�|���q|Srl�r{r�r�r�rrrr��szWhen.get_group_by_cols�NNr�rl)rrrrQrLrorr
r{rr�r*rr�rrrrrr��s


r�cs~eZdZdZdZdZddd��fdd�
Zdd	�Zd
d�Zdd
�Z	dd�Z
ddd�Z�fdd�Zddd�Z
d�fdd�	Z�ZS)�Casez�
    An SQL searched CASE expression:

        CASE
            WHEN n > 0
                THEN 'positive'
            WHEN n < 0
                THEN 'negative'
            ELSE 'zero'
        END
    z#CASE %(cases)s ELSE %(default)s END� N)�defaultrcsJtdd�|D��s
td��t��|�t|�|_|�|�d|_||_dS)Ncss�|]}t|t�VqdSrl)r�r�)r��caserrrr��r�z Case.__init__.<locals>.<genexpr>z.Positional arguments must all be When objects.r)	�allr>rro�list�casesr�r�r@)rr�rr�r@rrrro�s

z
Case.__init__cCs dd�dd�|jD��|jfS)NzCASE %s, ELSE %rr9csrArlrB)r�r�rrrr�rCzCase.__str__.<locals>.<genexpr>)rIr�r�r5rrrrs zCase.__str__cCr�r�r�r5rrrr
r7z
Case.__repr__cCs|j|jgSrl�r�r�r5rrrr{r�zCase.get_source_expressionscCs|�^|_|_dSrlr�r}rrrrr+zCase.set_source_expressionsTFc	CsT|��}||_t|j�D]\}}|�|||||�|j|<q|j�|||||�|_|Srl)rrr�rNr�r*r�)	rr�r�r�r�r�r�rOr�rrrr*szCase.resolve_expressioncst���}|jdd�|_|Srl)rrrr�)rr�rrrrrs
z	Case.copyc	Ks�|j�|�|js|�|j�Si|j�|�}g}g}|jD]}	z	|�|	�\}
}Wn	ty1Yqw|�|
�|�|�q|�|j�\}}
|sK||
fS|pO|j	}|�
|�|d<||d<|�|
�|ph|�d|j�}||}|j
dur{|j�|j�|}||fS)Nr�r�rQ)rr$r�rr�r@rr�r��case_joinerrIr�rQr��unification_cast_sqlr)rrrrQr�rr��
case_partsr�r��case_sql�case_params�default_sql�default_paramsrrrrrs4
�



zCase.as_sqlcs|js	|j�|�St��|�Srl)r�r�r�rr6rrrr�9szCase.get_group_by_colsr�r�rl)rrrr rQr�rorr
r{rr*rrrr�rrrrrr��s

r�csveZdZdZdZdZd�fdd�	Zdd�Zd	d
�Zdd�Z	�fd
d�Z
edd��Zdd�Z
ddd�Zddd�Z�ZS)�Subqueryz�
    An explicit subquery. It may contain OuterRef() references to the outer
    query which will be resolved when it is applied to that query.
    z(%(subquery)s)FNcs$t|d|�|_||_t��|�dS)Nr�)rOr�r@rro)r�querysetrr@rrrroGszSubquery.__init__cCr{rl�r�r5rrrr{MrqzSubquery.get_source_expressionscCr�r�r�r}rrrrPr�zSubquery.set_source_expressionscC�|jjSrl)r�rr5rrrr�SrqzSubquery._resolve_output_fieldcst���}|j��|_|Srl)rrrr�r��rr�rrrrrVrvz
Subquery.copycCr�rl)r��external_aliasesr5rrrr�[szSubquery.external_aliasescCs
|j��Srl)r��get_external_colsr5rrrr�_r�zSubquery.get_external_colsc
Ksf|j�|�i|j�|�}|p|j}|�||�\}}|dd�|d<|p*|�d|j�}||}	|	|fS)Nr:r2�subqueryrQ)rr$r@r�rr�rQ)
rrrrQr�rr��subquery_sqlr�rrrrrbs
zSubquery.as_sqlcCs|rt||�gS|j��Srl)ryr�r�r6rrrr�ms
zSubquery.get_group_by_colsrlr�)rrrr rQr�ror{rr�rrr�r�r�rr�rrrrrr�?s

r�csHeZdZdZe��Zd�fdd�	Zdd�Zd
�fdd	�	Z	d
d�Z
�ZS)�ExistszEXISTS(%(subquery)s)Fcs||_t�j|fi|��dSrl)�negatedrro)rr�r�r�rrrro{szExists.__init__cCs|��}|j|_|Srl)rrr�r�rrr�
__invert__s
zExists.__invert__NcsH|jj|jd�}t�j||f||d�|��\}}|jr d�|�}||fS)N)�using)rQr�zNOT {})r��existsr�rrr�r	)rrrrQrr�rrrrrr�s��
�
z
Exists.as_sqlcCs|jjjs
d�|�}||fS)NzCASE WHEN {} THEN 1 ELSE 0 END)rr"�&supports_boolean_expr_in_select_clauser	r�rrrr��s

zExists.select_format)Frl)rrrrQr	r�rror�rr�rrrrrr�ws
r�c@sjeZdZdZdZddd�Zdd�Zdd�Zd	d
�Zddd
�Z	dd�Z
ddd�Zdd�Zdd�Z
dd�ZdS)r�z%(expression)s %(ordering)sFcCs>|r|rtd��||_||_||_t|d�std��||_dS)Nz1nulls_first and nulls_last are mutually exclusiver*z%expression must be an expression type)r0�nulls_first�
nulls_lastr�r+r�)rr�r�r�r�rrrro�s

zOrderBy.__init__cCre)Nz{}({}, descending={}))r	r�rr�r�r5rrrr
�s�zOrderBy.__repr__cCr�r�r�r}rrrr�r�zOrderBy.set_source_expressionscCr{rlr�r5rrrr{�rqzOrderBy.get_source_expressionsNcKs�|p|j}|jjr|jrd|}n%|jrd|}n|jr(|jr#|jjs(d|}n|jr6|js2|jjs6d|}|j�|�|�	|j
�\}}||jrJdndd�|�}|pT|j}||�d�9}||��|fS)	Nz
%s NULLS LASTz%s NULLS FIRSTz%%(expression)s IS NULL, %sz%%(expression)s IS NOT NULL, %s�DESC�ASC)r��orderingz%(expression)s)
rQr"� supports_order_by_nulls_modifierr�r�r��order_by_nulls_firstrr$rr��count�rstrip)rrrrQr�expression_sqlr�placeholdersrrrr�s:

���
����
zOrderBy.as_sqlcCsDt|jt�r|��}tt|jdd�dd�|_|�||�S|�||�S)NT)r�F)r�)r�r�r�rrr�r�r)rrrrrrrr�	as_oracle�s�zOrderBy.as_oraclecCr�rlr�r�rrrr��szOrderBy.get_group_by_colscCs.|j|_|js|jr|j|_|j|_|Srl)r�r�r�r5rrrr��s



zOrderBy.reverse_orderingcC�
d|_dSr9�r�r5rrrr��r�zOrderBy.asccCr�r^r�r5rrrr��r�zOrderBy.desc)FFFrl)rrrrQrLror
rr{rr�r�r�r�r�rrrrr��s



r�csveZdZdZdZdZdZd�fdd�	Zdd�Zd	d
�Z	dd�Z
dd
d�Z�fdd�Zdd�Z
dd�Zddd�Z�ZS)�Windowz %(expression)s OVER (%(window)s)FTNcs�||_||_||_t|dd�std|jj��|jdur/t|jtt	f�s)|jf|_t
|j�|_|jdurMt|jt	tf�rCt
|j�|_n
t|jt�sMtd��t�j
|d�|�|�d|_dS)Nr�Fz3Expression '%s' isn't compatible with OVER clauses.zCorder_by must be either an Expression or a sequence of expressions.rmr)�partition_by�order_by�framerOr0r�rr�r�r�r~rkrror��source_expression)rr�r�r�r�rrrrro�s,��


�zWindow.__init__cCr�rl)r�rr5rrrr�rqzWindow._resolve_output_fieldcCs|j|j|j|jgSrl�r�r�r�r�r5rrrr{r�zWindow.get_source_expressionscCs|\|_|_|_|_dSrlr�r}rrrrr.zWindow.set_source_expressionscCs|j�|�|jjstd��|�|j�\}}gg}}|jdur5|jj||dd�\}}	|�	|�|�	|	�|j
durQ|�d�|�|j
�\}
}|�	|
�|�	|�|jrh|�|j�\}}
|�d|�|�	|
�|�	|�|pq|j
}||d�|���d�|fS)Nz1This backend does not support window expressions.zPARTITION BY %(expressions)s)rrrQz
 ORDER BY r��)r��window)rr$r"�supports_over_clauserrr�r�rr�r�r�r�rQrI�strip)rrrrQ�expr_sqlr�
window_sql�
window_params�sql_exprr��	order_sql�order_params�	frame_sql�frame_paramsrrrrs:


�








��z
Window.as_sqlcsTt|jtj�r$|��}|��}t��|d_|�|�tt	|��
||�S|�||�Sr�)r�rr	rrrr{r�rrr�rr)rrrrrr?rrrr<s
zWindow.as_sqlitecCsHd�t|j�|jrdt|j�nd|jrdt|j�ndt|jp!d��S)Nz{} OVER ({}{}{})z
PARTITION BY r�z	ORDER BY )r	r�r�r�r�r�r5rrrrFs�zWindow.__str__cCr�r�r�r5rrrr
Nr7zWindow.__repr__cCrzrlrr6rrrr�Qr|zWindow.get_group_by_cols)NNNNrl)rrrrQr�r�r�ror�r{rrrrr
r�rrrrrr��s
"
r�c@sXeZdZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Z	ddd�Z
dd�Zdd�ZdS)�WindowFrameaV
    Model the frame clause in window expressions. There are two types of frame
    clauses which are subclasses, however, all processing and validation (by no
    means intended to be complete) is done here. Thus, providing an end for a
    frame is optional (the default is UNBOUNDED FOLLOWING, which is the last
    row in the frame).
    z,%(frame_type)s BETWEEN %(start)s AND %(end)sNcCst|�|_t|�|_dSrl)r,�start�end�rr�r�rrrro_s
zWindowFrame.__init__cCrrl�r�r�r}rrrrcr7z"WindowFrame.set_source_expressionscCrrlr�r5rrrr{fr�z"WindowFrame.get_source_expressionscCs>|j�|�|�||jj|jj�\}}|j|j||d�gfS)N��
frame_typer�r�)rr$�window_frame_start_endr�r�r�rQr�)rrrr�r�rrrris��zWindowFrame.as_sqlcCr�r�r�r5rrrr
rr7zWindowFrame.__repr__cCrzrlrr6rrrr�ur|zWindowFrame.get_group_by_colscCs�|jjdur|jjdkrdt|jj�tjjf}n|jjdur*|jjdkr*tjj}ntjj}|jjdurE|jjdkrEd|jjtjj	f}n|jjdurV|jjdkrVtjj}ntjj
}|j|j||d�S)Nrz%d %sr�)
r�r��absrr�	PRECEDING�CURRENT_ROW�UNBOUNDED_PRECEDINGr��	FOLLOWING�UNBOUNDED_FOLLOWINGrQr�r�rrrrxs

�zWindowFrame.__str__cCre)Nz3Subclasses must implement window_frame_start_end().rg�rrr�r�rrrr��rqz"WindowFrame.window_frame_start_endr�rl)
rrrr rQrorr{rr
r�rr�rrrrr�Us
	
r�c@r)�RowRange�ROWScC�|j�||�Srl)r�window_frame_rows_start_endr�rrrr��r�zRowRange.window_frame_start_endN�rrrr�r�rrrrr���r�c@r)�
ValueRange�RANGEcCr�rl)r�window_frame_range_start_endr�rrrr��r�z!ValueRange.window_frame_start_endNr�rrrrr��r�r�)<rrr]�	functoolsr��decimalr�uuidr�django.core.exceptionsrr�	django.dbrr�django.db.modelsr	�django.db.models.constantsr
�django.db.models.query_utilsr�django.utils.deconstructr�django.utils.functionalr
�django.utils.hashablerrr!rkr�r;r?r4rCr��	lru_cacherr-rrr�r/r7r8r,rdrprrryr~rr�r�r�r�r�r�r�r�r�rrrr�<module>sbus�

K
JH%! CQ8#Sh;

https://t.me/RX1948 - 2025