
    j(                         S SK Jr  S SKJr  S SKJr  S SKJrJrJ	r	  S SK
JrJrJrJr  S SKJrJr  S SKJr  S SKJr  S S	KJr  S
SKJr  S
SKJr  S/r " S S\5      r " S S\\5      rg)    )NoneType)ValidationError)DEFAULT_DB_ALIAS)Expressions	StatementTable)BaseConstraint
DeferrableFQ)ExistsExpressionList)IndexExpression)PostgresOperatorLookup)Query   )RangeOperators)CheckPostgresInstalledMixinExclusionConstraintc                       \ rS rSrSrSrg)ExclusionConstraintExpression   z!%(expressions)s WITH %(operator)s N)__name__
__module____qualname____firstlineno__template__static_attributes__r       [/var/www/html/KUNJ/venv/lib/python3.13/site-packages/django/contrib/postgres/constraints.pyr   r      s    2Hr    r   c                      ^  \ rS rSrSrSSSSSSS.U 4S jjrS rU 4S jrS rS	 r	S
 r
S rU 4S jrU 4S jrS rS\4S jrSrU =r$ )r      zdCONSTRAINT %(name)s EXCLUDE USING %(index_type)s (%(expressions)s)%(include)s%(where)s%(deferrable)sN)
index_type	condition
deferrableincludeviolation_error_codeviolation_error_messagec                $  > U(       a  UR                  5       S;  a  [        S5      eU(       d  [        S5      e[        S U 5       5      (       d  [        S5      e[        U[        [
        45      (       d  [        S5      e[        U[        [        45      (       d  [        S5      e[        U[        [        [        45      (       d  [        S5      eU(       am  UR                  5       S	:X  aY  U(       a  [        S
5      eU(       d  O?[        U5      S:  a  [        S5      eUS   S   [        R                  :w  a  [        S5      eX l        U=(       d    SU l        X@l        XPl        U(       a  [        U5      OSU l        ["        T	U ]I  UUUS9  g )N>   gisthashspgistzBExclusion constraints only support GiST, Hash, or SP-GiST indexes.zFAt least one expression is required to define an exclusion constraint.c              3   x   #    U  H0  n[        U[        [        45      =(       a    [        U5      S :H  v   M2     g7f)   N)
isinstancelisttuplelen).0exprs     r!   	<genexpr>/ExclusionConstraint.__init__.<locals>.<genexpr>1   s.      
KV4JtdE]+>D	Q>;s   8:z+The expressions must be a list of 2-tuples.z3ExclusionConstraint.condition must be a Q instance.z=ExclusionConstraint.deferrable must be a Deferrable instance.z4ExclusionConstraint.include must be a list or tuple.r,   zDCovering exclusion constraints using Hash indexes are not supported.r   zEComposite exclusion constraints using Hash indexes are not supported.r   zIExclusion constraints using Hash indexes only support the EQUAL operator.GISTr   )namer(   r)   )lower
ValueErrorallr0   r   r   r
   r1   r2   r3   r   EQUALexpressionsr$   r%   r&   r'   super__init__)
selfr9   r>   r$   r%   r&   r'   r(   r)   	__class__s
            r!   r@   ExclusionConstraint.__init__   s    ***,4NNT     
KV
 
 
 JKK)h]33RSS*x&<==O  'HdE#:;;STT***,6 !  [!A% !  Q"n&:&::    '$."$)0uW~b!5$; 	 	
r    c                     / n[        U R                  5       H]  u  nu  pV[        U[        5      (       a  [	        U5      n[        XVS9nUR                  UR                  5        UR                  U5        M_     [        U6 R                  U5      $ )N)operator)	enumerater>   r0   strr   r   set_wrapper_classes
connectionappendr   resolve_expression)rA   schema_editorqueryr>   idx
expressionrE   s          r!   _get_expressions$ExclusionConstraint._get_expressionsZ   s    +4T5E5E+F'C'**c**z]
6zUJ**=+C+CDz* ,G {+>>uEEr    c                 $  > [         TU ]  X5      n[        5       nU R                   HE  u  pV[	        U[
        5      (       a  [        U5      nUR                  UR                  U5      5        MG     UR                  U R                  X5      5        U$ N)r?   checksetr>   r0   rG   r   update_get_expr_referencesextend_check_references)rA   modelrI   errors
referencesr5   _rB   s          r!   rT   ExclusionConstraint.checkd   sw    u1U
''GD$$$we88>? ( 	d,,U?@r    c                    ^ U R                   c  g UR                  U R                   5      nUR                  UTR                  5      u  pVU[	        U4S jU 5       5      -  $ )Nc              3   F   >#    U  H  nTR                  U5      v   M     g 7frS   )quote_value)r4   prL   s     r!   r6   9ExclusionConstraint._get_condition_sql.<locals>.<genexpr>s   s     HA=44Q77s   !)r%   build_whereas_sqlrI   r2   )rA   compilerrL   rM   wheresqlparamss     `    r!   _get_condition_sql&ExclusionConstraint._get_condition_sqln   sR    >>!!!$..1ll8]-E-EFUHHHHHr    c                 p   [        USS9nUR                  UR                  S9nU R                  X#5      nUR                  R
                  nU R                  XBU5      nU R                   Vs/ s H'  oR                  R                  U5      R                  PM)     n	n[        U R                  [        XbR                  5      UR                  U R                  5      U R                  [!        XeXBR"                  5      U(       a  SU-  OSUR%                  X5      UR'                  U R(                  5      S9$ s  snf )NF)
alias_cols)rI   z WHERE (%s) )tabler9   r$   r>   rg   r'   r&   )r   get_compilerrI   rP   _metadb_tablerj   r'   	get_fieldcolumnr   r   r   
quote_namer9   r$   r   ra   _index_include_sql_deferrable_constraint_sqlr&   )
rA   rZ   rL   rM   rf   r>   ro   r%   
field_namer'   s
             r!   constraint_sql"ExclusionConstraint.constraint_sqlu   s   e.%%1I1I%J++MA$$++HUK	GK||
GSKK!!*-44| 	 
 MM778))$))4#H.G.G 09-)+b!44UD$??P
 	

s   +.D3c                     [        S[        UR                  R                  UR                  5      U R                  X5      S9$ )Nz(ALTER TABLE %(table)s ADD %(constraint)s)ro   
constraint)r   r   rq   rr   ru   ry   rA   rZ   rL   s      r!   
create_sqlExclusionConstraint.create_sql   s:    6,,m.F.FG**5@
 	
r    c                 n    UR                  UR                  UUR                  U R                  5      5      $ rS   )_delete_constraint_sqlsql_delete_checkru   r9   r}   s      r!   
remove_sqlExclusionConstraint.remove_sql   s3    33**$$TYY/
 	
r    c                 ^  > [         TU ]  5       u  pnU R                  US'   U R                  b  U R                  US'   U R                  R                  5       S:w  a  U R                  US'   U R                  (       a  U R                  US'   U R                  (       a  U R                  US'   XU4$ )Nr>   r%   r+   r$   r&   r'   )r?   deconstructr>   r%   r$   r:   r&   r'   )rA   pathargskwargsrB   s       r!   r   ExclusionConstraint.deconstruct   s    "W02F $ 0 0}>>%"&..F;??  "f,#'??F< ??#'??F< << $F96!!r    c                   > [        XR                  5      (       Ga  U R                  UR                  :H  =(       a    U R                  R	                  5       UR                  R	                  5       :H  =(       a    U R
                  UR
                  :H  =(       a    U R                  UR                  :H  =(       ay    U R                  UR                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ [        TU ]1  U5      $ rS   )r0   rB   r9   r$   r:   r>   r%   r&   r'   r(   r)   r?   __eq__)rA   otherrB   s     r!   r   ExclusionConstraint.__eq__   s    e^^,,		UZZ' ROO))+u/?/?/E/E/GGR$$(9(99R NNeoo5R OOu'7'77	R
 LLEMM1R --1K1KKR 00E4Q4QQ	 w~e$$r    c                 F   SU R                   R                  < S[        U R                  5      < S[        U R                  5      < S[        U R
                  5      < U R                  c  SOSU R                  -  < U R                  c  SOSU R                  -  < U R                  (       d  SOS[        U R                  5      -  < U R                  c  SOS	U R                  -  < U R                  b  U R                  U R                  :X  a  SOS
U R                  -  < S3$ )N<z: index_type=z expressions=z name=rn   z condition=%sz deferrable=%rz include=%sz violation_error_code=%rz violation_error_message=%r>)rB   r   reprr$   r>   r9   r%   r&   r'   r(   r)   default_violation_error_message)rA   s    r!   __repr__ExclusionConstraint.__repr__   s    NN''!!!"O..(Bo.NN//)B/?$///QQllBT\\8J(JJ ,,4 /$2K2KKL //7//43W3WW  3T5Q5QQR
 	
r    c                     UR                   R                  U5      nUR                  UR                  US9nUR	                  5        VVs0 s H  u  px[        U5      U_M     n	nn/ n
U R                   H  u  p[        U[        5      (       a  [        U5      nU(       a  U R                  XU5      (       a    g UR                  U	5      n[        US5      (       a  UR                  5       n[        US5      (       a  UR                  5       n[        XS9nXl        U
R                  U5        M     UR                   " U
6 nUR#                  UR                  5      nUR$                  R&                  (       d/  UR)                  UR                  5      (       a  UR+                  US9nU R,                  (       d8  UR/                  5       (       a"  [1        U R3                  5       U R4                  S9eg U(       a"  U R                  XR,                  U5      (       a  g U R,                  [7        UR!                  U R,                  5      5      -  R9                  XdS9(       a"  [1        U R3                  5       U R4                  S9eg s  snnf )N)metaexcludeget_expression_for_validation)lhsrhs)pk)code)using)_default_managerr   _get_field_expression_maprq   itemsr   r>   r0   rG   _expression_refs_excludereplace_expressionshasattrr   r   postgres_operatorrJ   filter_get_pk_val_stateadding
_is_pk_setr   r%   existsr   get_violation_error_messager(   r   rT   )rA   rZ   instancer   r   querysetreplacement_mapfieldvaluereplacementslookupsrO   rE   rhs_expressionlookupmodel_class_pks                   r!   validateExclusionConstraint.validate   s#   ))//6"<<g = 
 =L<Q<Q<ST<SLE%%<ST$($4$4 J*c**z]
488GTT';;LINz#BCC'EEG
~'FGG!/!M!M!O+
OF'/$NN6" %5 ??G,!--ekk:%%(*=*=ekk*J*J''>':H~~  %446T=V=V  ! 488~~w  (G!HHOO P  &446T=V=V = Us   	I:)r%   r&   r>   r'   r$   )r   r   r   r   r   r@   rP   rT   rj   ry   r~   r   r   r   r   r   r   r   __classcell__)rB   s   @r!   r   r      sm    	>  ! $<
 <
|FI
,

"%
, 15<L ( (r    N)typesr   django.core.exceptionsr   	django.dbr   !django.db.backends.ddl_referencesr   r   r   django.db.modelsr	   r
   r   r   django.db.models.expressionsr   r   django.db.models.indexesr   django.db.models.lookupsr   django.db.models.sqlr   fieldsr   utilsr   __all__r   r   r   r    r!   <module>r      sQ     2 & K K = = ? 4 ; & " . 
!3O 3\5~ \r    