
    h>B                         S SK r S SK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 SKJr  \R                   \R"                  -   r " S	 S
\5      r " S S\5      r " S S5      rg)    N)datetime	timedelta)sync_to_async)settings)signing)timezone)get_random_string)import_stringc                       \ rS rSrSrSrg)CreateError   z{
Used internally as a consistent exception type to catch from save (see the
docstring for SessionBase.save() for details).
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       W/var/www/html/env/lib/python3.13/site-packages/django/contrib/sessions/backends/base.pyr   r      s    
 	r   r   c                       \ rS rSrSrSrg)UpdateError   z>
Occurs if Django tries to update a session that was deleted.
r   Nr   r   r   r   r   r      s     	r   r   c                   @   \ rS rSrSrSrSr\" 5       rSJS jr	S r
S rS	 rS
 rS r\S 5       rSJS jrSJS jr\4S jr\4S jrS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"S r#S  r$S! r%S" r&S# r'S$ r(S% r)S& r*S' r+S( r,S) r-S* r.S+ r/S, r0S- r1\" \05      r2\" \0\15      r3SKS. jr4SKS/ jr5\" \45      r6S0 r7S1 r8S2 r9S3 r:S4 r;S5 r<S6 r=S7 r>S8 r?S9 r@S: rAS; rBS< rCS= rDS> rES? rFS@ rGSKSA jrHSKSB jrISJSC jrJSJSD jrKSE rLSF rM\NSG 5       rO\NSH 5       rPSIrQg)LSessionBase#   z%
Base class for all Session classes.

testcookieworkedNc                 h    Xl         SU l        SU l        [        [        R
                  5      U l        g )NF)_session_keyaccessedmodifiedr
   r   SESSION_SERIALIZER
serializerselfsession_keys     r   __init__SessionBase.__init__-   s(    ''(C(CDr   c                     XR                   ;   $ N_sessionr'   keys     r   __contains__SessionBase.__contains__3       mm##r   c                      U R                   U   $ r,   r-   r/   s     r   __getitem__SessionBase.__getitem__6   s    }}S!!r   c                 .    X R                   U'   SU l        g NTr.   r#   r'   r0   values      r   __setitem__SessionBase.__setitem__9   s    "cr   c                 R   #    X R                  5       I S h  vN U'   SU l        g  N7fr8   )_aget_sessionr#   r:   s      r   asetSessionBase.aset=   s%     ,1!!#	#S) 
$s   '%'c                 ,    U R                   U	 SU l        g r8   r9   r/   s     r   __delitem__SessionBase.__delitem__A   s    MM#r   c                 4    SU R                   R                  -   $ )Nzdjango.contrib.sessions.)	__class__r   r'   s    r   key_saltSessionBase.key_saltE   s    )DNN,G,GGGr   c                 8    U R                   R                  X5      $ r,   )r.   getr'   r0   defaults      r   rK   SessionBase.getI   s    }}  ..r   c                 \   #    U R                  5       I S h  vN R                  X5      $  N7fr,   )r?   rK   rL   s      r   agetSessionBase.agetL   s%     ((**//==*s   ,*,c                     U R                   =(       d    XR                  ;   U l         X R                  L a  SOU4nU R                  R                  " U/UQ76 $ Nr   )r#   r.   _SessionBase__not_givenpopr'   r0   rM   argss       r   rU   SessionBase.popO   sG    =)= 0 00rwj}}  ,t,,r   c                    #    U R                   =(       d    XR                  5       I S h  vN ;   U l         X R                  L a  SOU4nU R                  5       I S h  vN R                  " U/UQ76 $  NG N7frS   )r#   r?   rT   rU   rV   s       r   apopSessionBase.apopT   sc     L7I7I7K1K)L 0 00rwj((**//;d;; 2L*s!   'A5A11A5A3A53A5c                 J    XR                   ;   a  U R                   U   $ X U'   U$ r,   r-   r:   s      r   
setdefaultSessionBase.setdefaultY   s'    --==%%ILr   c                    #    U R                  5       I S h  vN nX;   a  X1   $ U R                  X5      I S h  vN   U$  N( N7fr,   )r?   r@   )r'   r0   r;   sessions       r   asetdefaultSessionBase.asetdefault`   sD     **,,><))C'''L - (s   A?!AAAAc                 4    U R                   X R                  '   g r,   )TEST_COOKIE_VALUETEST_COOKIE_NAMErG   s    r   set_test_cookieSessionBase.set_test_cookieh   s    &*&<&<""#r   c                 l   #    U R                  U R                  U R                  5      I S h  vN   g  N7fr,   )r@   re   rd   rG   s    r   aset_test_cookieSessionBase.aset_test_cookiek   s%     ii--t/E/EFFFs   *424c                 R    U R                  U R                  5      U R                  :H  $ r,   )rK   re   rd   rG   s    r   test_cookie_workedSessionBase.test_cookie_workedn   s"    xx--.$2H2HHHr   c                 n   #    U R                  U R                  5      I S h  vN U R                  :H  $  N7fr,   )rP   re   rd   rG   s    r   atest_cookie_workedSessionBase.atest_cookie_workedq   s+     ii 5 5664;Q;QQQ6s   535c                     X R                   	 g r,   )re   rG   s    r   delete_test_cookieSessionBase.delete_test_cookiet   s    &&'r   c                 V   #    U R                  5       I S h  vN U R                  	 g  N7fr,   )r?   re   rG   s    r   adelete_test_cookieSessionBase.adelete_test_cookiew   s"     %%'')>)>?'s   )')c                 X    [         R                  " UU R                  U R                  SS9$ )zGReturn the given session dictionary serialized and encoded as a string.T)saltr%   compress)r   dumpsrH   r%   )r'   session_dicts     r   encodeSessionBase.encodez   s'    }}	
 	
r   c                      [         R                  " XR                  U R                  S9$ ! [         R                   a+    [
        R                  " S5      nUR                  S5         0 $ [         a     0 $ f = f)N)rx   r%   z!django.security.SuspiciousSessionzSession data corrupted)	r   loadsrH   r%   BadSignaturelogging	getLoggerwarning	Exception)r'   session_dataloggers      r   decodeSessionBase.decode   su    
	====T__  ## 	5&&'JKFNN34
 		  	 			s   (+ ;A6)	A65A6c                 H    U R                   R                  U5        SU l        g r8   )r.   updater#   r'   dict_s     r   r   SessionBase.update   s    U#r   c                 l   #    U R                  5       I S h  vN R                  U5        SU l        g  N7fr8   )r?   r   r#   r   s     r   aupdateSessionBase.aupdate   s+     !!#	#++E2 
$s   424c                     XR                   ;   $ r,   r-   r/   s     r   has_keySessionBase.has_key   r3   r   c                 B   #    XR                  5       I S h  vN ;   $  N7fr,   )r?   r/   s     r   ahas_keySessionBase.ahas_key   s     //11221s   c                 6    U R                   R                  5       $ r,   )r.   keysrG   s    r   r   SessionBase.keys   s    }}!!##r   c                 Z   #    U R                  5       I S h  vN R                  5       $  N7fr,   )r?   r   rG   s    r   akeysSessionBase.akeys   s#     ((**0022*   +)+c                 6    U R                   R                  5       $ r,   )r.   valuesrG   s    r   r   SessionBase.values   s    }}##%%r   c                 Z   #    U R                  5       I S h  vN R                  5       $  N7fr,   )r?   r   rG   s    r   avaluesSessionBase.avalues   s#     ((**2244*r   c                 6    U R                   R                  5       $ r,   )r.   itemsrG   s    r   r   SessionBase.items   s    }}""$$r   c                 Z   #    U R                  5       I S h  vN R                  5       $  N7fr,   )r?   r   rG   s    r   aitemsSessionBase.aitems   s#     ((**1133*r   c                 .    0 U l         SU l        SU l        g r8   )_session_cacher"   r#   rG   s    r   clearSessionBase.clear   s     !r   c                 v     U R                   (       + =(       a    U R                  (       + $ ! [         a     gf = f)zBReturn True when there is no session_key and the session is empty.T)r!   r   AttributeErrorrG   s    r   is_emptySessionBase.is_empty   s6    	(((D1D1D-DD 		s   (+ 
88c                 X     [        S[        5      nU R                  U5      (       d  U$ M*  )z)Return session key that isn't being used.    )r	   VALID_KEY_CHARSexistsr&   s     r   _get_new_session_key SessionBase._get_new_session_key   s+    +B@K;;{++"" r   c                 t   #     [        S[        5      nU R                  U5      I S h  vN (       d  U$ M2   N7f)Nr   )r	   r   aexistsr&   s     r   _aget_new_session_key!SessionBase._aget_new_session_key   s4     +B@Kk222"" 2s   &868c                 ^    U R                   c  U R                  5       U l         U R                   $ r,   )r!   r   rG   s    r   _get_or_create_session_key&SessionBase._get_or_create_session_key   s+    $ $ 9 9 ;D   r   c                 z   #    U R                   c  U R                  5       I S h  vN U l         U R                   $  N7fr,   )r!   r   rG   s    r   _aget_or_create_session_key'SessionBase._aget_or_create_session_key   s7     $&*&@&@&B BD    !Cs   !;9;c                 0    U=(       a    [        U5      S:  $ )z|
Key must be truthy and at least 8 characters long. 8 characters is an
arbitrary lower bound for some minimal key security.
   )lenr/   s     r   _validate_session_key!SessionBase._validate_session_key   s    
 $s3x1}$r   c                     U R                   $ r,   )_SessionBase__session_keyrG   s    r   _get_session_keySessionBase._get_session_key   s    !!!r   c                 L    U R                  U5      (       a  Xl        gSU l        g)zF
Validate session key on assignment. Invalid values will set to None.
N)r   r   r'   r;   s     r   _set_session_keySessionBase._set_session_key   s#     %%e,,!&!%Dr   c                     SU l          U R                  $ ! [         aK    U R                  b  U(       a  0 U l         U R                  $ U R	                  5       U l         U R                  $ f = f)z
Lazily load session from storage (unless "no_load" is True, when only
an empty dict is stored) and store it in the current instance.
T)r"   r   r   r(   loadr'   no_loads     r   _get_sessionSessionBase._get_session   sk    
 	2&&& 	2'7&(# """ '+iik#"""	2s    %A*A*)A*c                    #    SU l          U R                  $ ! [         aT    U R                  b  U(       a  0 U l         U R                  $ U R	                  5       I S h  vN  U l         U R                  $ f = f7fr8   )r"   r   r   r(   aloadr   s     r   r?   SessionBase._aget_session   sq     	9&&& 	9'7&(# """ -1JJL&8&8#"""	9s<   A8 A8%A5A8	A5A
A5'A84A55A8c                 "    [         R                  $ r,   )r   SESSION_COOKIE_AGErG   s    r   get_session_cookie_age"SessionBase.get_session_cookie_age	  s    ***r   c                     US   n US   nU(       d  U R	                  5       $ [        U[        [        45      (       d  U$ [        U[        5      (       a  [        R                  " U5      nX2-
  nUR                  S-  UR                  -   $ ! [          a    [        R                  " 5       n Nf = f! [          a    U R                  S5      n Nf = f)zGet the number of seconds until the session expires.

Optionally, this function accepts `modification` and `expiry` keyword
arguments specifying the modification and expiry of the session.
modificationexpiry_session_expiryQ )KeyErrorr   nowrK   r   
isinstancer   strfromisoformatdayssecondsr'   kwargsr   r   deltas        r   get_expiry_ageSessionBase.get_expiry_age  s    	*!.1L	1H%F ..00&8S/22Mfc""++F3F%zzE!EMM11#  	*#<<>L	*  	1XX/0F	1s"   B B1 B.-B.1CCc                   #     US   n US   nU(       d  U R	                  5       $ [        U[        [        45      (       d  U$ [        U[        5      (       a  [        R                  " U5      nX2-
  nUR                  S-  UR                  -   $ ! [          a    [        R                  " 5       n Nf = f! [          a    U R                  S5      I S h  vN  n Nf = f7f)Nr   r   r   r   )r   r   r   rP   r   r   r   r   r   r   r   r   s        r   aget_expiry_ageSessionBase.aget_expiry_age'  s     	*!.1L	8H%F ..00&8S/22Mfc""++F3F%zzE!EMM11  	*#<<>L	*  	899%6777F	8sQ   CB B3 A?CB0-C/B00C3CCCCCCc                 t    US   n US   n[	        U[
        5      (       a  U$ [	        U[        5      (       a  [
        R                  " U5      $ U=(       d    U R                  5       nU[        US9-   $ ! [          a    [        R                  " 5       n Nf = f! [          a    U R                  S5      n Nf = f)zGet session the expiry date (as a datetime object).

Optionally, this function accepts `modification` and `expiry` keyword
arguments specifying the modification and expiry of the session.
r   r   r   r   )
r   r   r   rK   r   r   r   r   r   r   r'   r   r   r   s       r   get_expiry_dateSessionBase.get_expiry_date:  s    	*!.1L	1H%F fh''M$$))&1184668i777  	*#<<>L	*
  	1XX/0F	1s"   A4 B 4BBB76B7c                   #     US   n US   n[	        U[
        5      (       a  U$ [	        U[        5      (       a  [
        R                  " U5      $ U=(       d    U R                  5       nU[        US9-   $ ! [          a    [        R                  " 5       n Nf = f! [          a    U R                  S5      I S h  vN  n Nf = f7f)Nr   r   r   r   )
r   r   r   rP   r   r   r   r   r   r   r   s       r   aget_expiry_dateSessionBase.aget_expiry_dateQ  s     	*!.1L	8H%F fh''M$$))&1184668i777  	*#<<>L	*  	899%6777F	8sQ   CA6 B A'C6BCBCC9B<:C?CCCc                     Uc   U S	 g[        U[        5      (       a  [        R                  " 5       U-   n[        U[
        5      (       a  UR                  5       nXS'   g! [          a     gf = f)a  
Set a custom expiration for the session. ``value`` can be an integer,
a Python ``datetime`` or ``timedelta`` object or ``None``.

If ``value`` is an integer, the session will expire after that many
seconds of inactivity. If set to ``0`` then the session will expire on
browser close.

If ``value`` is a ``datetime`` or ``timedelta`` object, the session
will expire at that specific future time.

If ``value`` is ``None``, the session uses the global session expiry
policy.
Nr   )r   r   r   r   r   r   	isoformatr   s     r   
set_expirySessionBase.set_expiryb  sr     =*+ eY''LLNU*EeX&&OO%E"'  s   A   
A-,A-c                 H  #    Uc   U R                  S5      I S h  vN   g [        U[        5      (       a  [        R
                  " 5       U-   n[        U[        5      (       a  UR                  5       nU R                  SU5      I S h  vN   g  Nr! [         a     g f = f N7f)Nr   )	rZ   r   r   r   r   r   r   r   r@   r   s     r   aset_expirySessionBase.aset_expiry~  s     =ii 1222 eY''LLNU*EeX&&OO%Eii)5111 3  	2sD   B"B BB A(B"B 	B"B 
BB"BB"c                 T    U R                  S5      =nc  [        R                  $ US:H  $ )z
Return ``True`` if the session is set to expire when the browser
closes, and ``False`` if there's an expiry date. Use
``get_expiry_date()`` or ``get_expiry_age()`` to find the actual expiry
date/age, if there is one.
r   r   )rK   r   SESSION_EXPIRE_AT_BROWSER_CLOSEr'   r   s     r   get_expire_at_browser_close'SessionBase.get_expire_at_browser_close  s/     hh011F:;;;{r   c                 p   #    U R                  S5      I S h  vN =nc  [        R                  $ US:H  $  N7f)Nr   r   )rP   r   r   r  s     r   aget_expire_at_browser_close(SessionBase.aget_expire_at_browser_close  s8      II&7888FA;;;{ 9s   646c                 R    U R                  5         U R                  5         SU l        g)zK
Remove the current session data from the database and regenerate the
key.
N)r   deleter!   rG   s    r   flushSessionBase.flush  s    
 	

 r   c                 n   #    U R                  5         U R                  5       I S h  vN   S U l        g  N7fr,   )r   adeleter!   rG   s    r   aflushSessionBase.aflush  s*     

lln  	s   $535c                     U R                   nU R                  nU R                  5         Xl        U(       a  U R	                  U5        ggzE
Create a new session key, while retaining the current session data.
N)r.   r(   creater   r  r'   datar0   s      r   	cycle_keySessionBase.cycle_key  s;     }}"KK r   c                    #    U R                  5       I Sh  vN nU R                  nU R                  5       I Sh  vN   Xl        U(       a  U R	                  U5      I Sh  vN   gg NP N. N
7fr  )r?   r(   acreater   r  r  s      r   
acycle_keySessionBase.acycle_key  s_      ''))lln",,s### 	 * $s1   A-A'#A-A)%A- A+!A-)A-+A-c                     [        S5      e)z6
Return True if the given session_key already exists.
z9subclasses of SessionBase must provide an exists() methodNotImplementedErrorr&   s     r   r   SessionBase.exists  s     "G
 	
r   c                 T   #    [        U R                  5      " U5      I S h  vN $  N7fr,   )r   r   r&   s     r   r   SessionBase.aexists       "4;;/<<<<   (&(c                     [        S5      e)z
Create a new session instance. Guaranteed to create a new object with
a unique key and will have saved the result once (with empty data)
before the method returns.
z8subclasses of SessionBase must provide a create() methodr  rG   s    r   r  SessionBase.create  s     "F
 	
r   c                 R   #    [        U R                  5      " 5       I S h  vN $  N7fr,   )r   r  rG   s    r   r  SessionBase.acreate  s     "4;;/1111   '%'c                     [        S5      e)z
Save the session data. If 'must_create' is True, create a new session
object (or raise CreateError). Otherwise, only update an existing
object and don't create one (raise UpdateError if needed).
z6subclasses of SessionBase must provide a save() methodr  r'   must_creates     r   saveSessionBase.save  s     "D
 	
r   c                 T   #    [        U R                  5      " U5      I S h  vN $  N7fr,   )r   r*  r(  s     r   asaveSessionBase.asave  s     "499-k::::r!  c                     [        S5      e)z`
Delete the session data under this key. If the key is None, use the
current session key value.
z8subclasses of SessionBase must provide a delete() methodr  r&   s     r   r  SessionBase.delete  s    
 "F
 	
r   c                 T   #    [        U R                  5      " U5      I S h  vN $  N7fr,   )r   r  r&   s     r   r  SessionBase.adelete  r   r!  c                     [        S5      e)z0
Load the session data and return a dictionary.
z6subclasses of SessionBase must provide a load() methodr  rG   s    r   r   SessionBase.load  s     "D
 	
r   c                 R   #    [        U R                  5      " 5       I S h  vN $  N7fr,   )r   r   rG   s    r   r   SessionBase.aload  s     "499-////r&  c                     [        S5      e)z
Remove expired sessions from the session store.

If this operation isn't possible on a given backend, it should raise
NotImplementedError. If it isn't necessary, because the backend has
a built-in expiration mechanism, it should be a no-op.
z.This backend does not support clear_expired().r  clss    r   clear_expiredSessionBase.clear_expired  s     ""RSSr   c                 R   #    [        U R                  5      " 5       I S h  vN $  N7fr,   )r   r:  r8  s    r   aclear_expiredSessionBase.aclear_expired	  s     "3#4#457777r&  )__session_keyr   r!   r"   r#   r%   r,   )F)Rr   r   r   r   r   re   rd   objectrT   r)   r1   r5   r<   r@   rC   propertyrH   rK   rP   rU   rZ   r]   ra   rf   ri   rl   ro   rr   ru   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r!   r   r?   r.   r   r   r   r   r   r   r   r  r  r	  r  r  r  r   r   r  r  r*  r-  r  r  r   r   classmethodr:  r=  r   r   r   r   r   r   #   s    $ (KE$" H H/>  + -
 '2 <
=GIR(@
$3$3&5%4##!
!
%"& +,K,.>?L#	# %H+262&8.8"(82	
!!
		$
=
2
;
=
0 T T 8 8r   r   )r   stringr   r   asgiref.syncr   django.confr   django.corer   django.utilsr   django.utils.cryptor	   django.utils.module_loadingr
   ascii_lowercasedigitsr   r   r   r   r   r   r   r   <module>rL     sZ      ( &    ! 1 5 ((6==8	) 		) 	h8 h8r   