
    h=&                         S SK Jr  S SKJr  S SKJr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
/r " S S\5      r " S S
\5      rg)    )NoneType)ValidationError)DEFAULT_DB_ALIASNotSupportedError)Expressions	StatementTable)BaseConstraint
DeferrableFQ)ExistsExpressionList)IndexExpression)PostgresOperatorLookup)Query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       U/var/www/html/env/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S rS 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X l	        U=(       d    S	U l
        X@l        XPl        U(       a  [        U5      OS
U l        [        T	U ]=  UUUS9  g )N>   gistspgistz;Exclusion constraints only support GiST 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>.   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.GISTr   )namer&   r'   )lower
ValueErrorallr-   r   r   r   r.   r/   expressionsr"   r#   r$   r%   super__init__)
selfr6   r:   r"   r#   r$   r%   r&   r'   	__class__s
            r   r<   ExclusionConstraint.__init__   s    ***,4FFM     
KV
 
 
 JKK)h]33RSS*x&<==O  'HdE#:;;STT&$."$)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:   r-   strr   r   set_wrapper_classes
connectionappendr   resolve_expression)r=   schema_editorqueryr:   idx
expressionrA   s          r   _get_expressions$ExclusionConstraint._get_expressionsE   s    +4T5E5E+F'C'**c**z]
6zUJ**=+C+CDz* ,G {+>>uEEr   c                     [        5       nU R                   HE  u  pE[        U[        5      (       a  [	        U5      nUR                  UR                  U5      5        MG     U R                  X5      $ N)setr:   r-   rC   r   update_get_expr_references_check_references)r=   modelrE   
referencesr2   _s         r   _checkExclusionConstraint._checkO   s]    U
''GD$$$we88>? ( %%e88r   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rO   )quote_value)r1   prH   s     r   r3   9ExclusionConstraint._get_condition_sql.<locals>.<genexpr>\   s     HA=44Q77s   !)r#   build_whereas_sqlrE   r/   )r=   compilerrH   rI   wheresqlparamss     `    r   _get_condition_sql&ExclusionConstraint._get_condition_sqlW   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)rE   z WHERE (%s) )tabler6   r"   r:   ra   r%   r$   )r   get_compilerrE   rL   _metadb_tablerd   r%   	get_fieldcolumnr   r   r	   
quote_namer6   r"   r   r[   _index_include_sql_deferrable_constraint_sqlr$   )
r=   rT   rH   rI   r`   r:   ri   r#   
field_namer%   s
             r   constraint_sql"ExclusionConstraint.constraint_sql^   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                     U R                  U5        [        S[        UR                  R                  UR
                  5      U R                  X5      S9$ )Nz(ALTER TABLE %(table)s ADD %(constraint)s)ri   
constraint)check_supportedr   r	   rk   rl   ro   rs   r=   rT   rH   s      r   
create_sqlExclusionConstraint.create_sqlt   sH    ]+6,,m.F.FG**5@
 	
r   c                 n    UR                  UR                  UUR                  U R                  5      5      $ rO   )_delete_constraint_sqlsql_delete_checkro   r6   rx   s      r   
remove_sqlExclusionConstraint.remove_sql|   s3    33**$$TYY/
 	
r   c                     U R                   (       aP  U R                  R                  5       S:X  a1  UR                  R                  R
                  (       d  [        S5      eg g g )Nr*   zMCovering exclusion constraints using an SP-GiST index require PostgreSQL 14+.)r%   r"   r7   rE   features supports_covering_spgist_indexesr   )r=   rH   s     r   rw   #ExclusionConstraint.check_supported   sU    LL%%'83!,,55VV#*  W 4 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"   r7   r$   r%   )r=   pathargskwargsr>   s       r   r   ExclusionConstraint.deconstruct   s    "W02F $ 0 0}>>%"&..F;??  "f,#'??F< ??#'??F< << $F96!!r   c                 H  > [        XR                  5      (       a  U R                  UR                  :H  =(       a    U R                  UR                  :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 ]-  U5      $ rO   )r-   r>   r6   r"   r:   r#   r$   r%   r&   r'   r;   __eq__)r=   otherr>   s     r   r   ExclusionConstraint.__eq__   s    e^^,,		UZZ' ROOu'7'77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=rh   z condition=%sz deferrable=%rz include=%sz violation_error_code=%rz violation_error_message=%r>)r>   r   reprr"   r:   r6   r#   r$   r%   r&   r'   default_violation_error_message)r=   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                 2   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                  5       GH  u  nu  p[        U[        5      (       a  [        U5      nU(       ai  [        U[
        5      (       a  UR                  U;   a    g OAUR                  5        H-  n[        U[
        5      (       d  M  UR                  U;   d  M,      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UUl        U
R#                  U5        GM     UR$                  " U
6 nUR'                  UR                  5      nUR(                  R*                  (       d  Ub  UR-                  US9nU R.                  (       d8  UR1                  5       (       a"  [3        U R5                  5       U R6                  S9eg U R.                  [9        UR%                  U R.                  5      5      -  R;                  XdS9(       a"  [3        U R5                  5       U R6                  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_maprk   itemsr   rB   r:   r-   rC   r6   flattenreplace_expressionshasattrr   r   postgres_operatorrF   filter_get_pk_val_stateaddingr   r#   existsr   get_violation_error_messager&   r   check)r=   rT   instancer   r   querysetreplacement_mapfieldvaluereplacementslookupsrJ   rK   rA   r2   rhs_expressionlookupmodel_class_pks                     r   validateExclusionConstraint.validate   s<   ))//6"<<g = 
 =L<Q<Q<ST<SLE%%<ST+4T5E5E+F'C'**c**z]
j!,,!'1 2 !+ 2 2 4%dA..4993G" !5 (;;LINz#BCC'EEG
~'FGG!/!M!M!O+
OF'/F$NN6"% ,G& ??G,!--ekk:%%.*D''>':H~~  %446T=V=V  !
 (G!HHOO P  &446T=V=V ? Us   	J)r#   r$   r:   r%   r"   )r   r   r   r   r   r<   rL   rW   rd   rs   ry   r~   rw   r   r   r   r   r   r   __classcell__)r>   s   @r   r   r      sr    	>  ! $*
 *
XF9I
,

	"%
, 15<L ) )r   N)typesr   django.core.exceptionsr   	django.dbr   r   !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   __all__r   r   r   r   r   <module>r      sH     2 9 K K = = ? 4 ; & 
!3O 3U. Ur   