
    (ph-                         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  \R                  \R                  -   r " S S	\5      r " S
 S\5      r " S S5      rg)    N)datetime	timedelta)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       X/var/www/html/venv/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S/S jr	S r
S rS	 rS
 r\S 5       rS/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#\" \"5      r$\" \"\#5      r%S0S  jr&\" \&5      r'S! r(S" r)S# r*S$ r+S% r,S& r-S' r.S( r/S) r0S0S* jr1S/S+ jr2S, r3\4S- 5       r5S.r6g)1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__1       mm##r   c                      U R                   U   $ r+   r,   r.   s     r   __getitem__SessionBase.__getitem__4   s    }}S!!r   c                 .    X R                   U'   SU l        g NTr-   r"   r&   r/   values      r   __setitem__SessionBase.__setitem__7   s    "cr   c                 ,    U R                   U	 SU l        g r7   r8   r.   s     r   __delitem__SessionBase.__delitem__;   s    MM#r   c                 4    SU R                   R                  -   $ )Nzdjango.contrib.sessions.)	__class__r   r&   s    r   key_saltSessionBase.key_salt?   s    )DNN,G,GGGr   c                 8    U R                   R                  X5      $ r+   )r-   get)r&   r/   defaults      r   rF   SessionBase.getC   s    }}  ..r   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&   r/   rG   argss       r   rK   SessionBase.popF   sG    =)= 0 00rwj}}  ,t,,r   c                 l    XR                   ;   a  U R                   U   $ SU l        X R                   U'   U$ r7   r8   r9   s      r   
setdefaultSessionBase.setdefaultK   s3    --==%% DM!&MM#Lr   c                 4    U R                   X R                  '   g r+   )TEST_COOKIE_VALUETEST_COOKIE_NAMErB   s    r   set_test_cookieSessionBase.set_test_cookieS   s    &*&<&<""#r   c                 R    U R                  U R                  5      U R                  :H  $ r+   )rF   rS   rR   rB   s    r   test_cookie_workedSessionBase.test_cookie_workedV   s"    xx--.$2H2HHHr   c                     X R                   	 g r+   )rS   rB   s    r   delete_test_cookieSessionBase.delete_test_cookieY   s    &&'r   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   dumpsrC   r$   )r&   session_dicts     r   encodeSessionBase.encode\   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)r]   r$   z!django.security.SuspiciousSessionzSession data corrupted)	r   loadsrC   r$   BadSignaturelogging	getLoggerwarning	Exception)r&   session_dataloggers      r   decodeSessionBase.decodee   su    
	====T__  ## 	5&&'JKFNN34
 		  	 			s   (+ ;A6)	A65A6c                 H    U R                   R                  U5        SU l        g r7   )r-   updater"   )r&   dict_s     r   ro   SessionBase.updates   s    U#r   c                     XR                   ;   $ r+   r,   r.   s     r   has_keySessionBase.has_keyw   r2   r   c                 6    U R                   R                  5       $ r+   )r-   keysrB   s    r   rv   SessionBase.keysz   s    }}!!##r   c                 6    U R                   R                  5       $ r+   )r-   valuesrB   s    r   ry   SessionBase.values}   s    }}##%%r   c                 6    U R                   R                  5       $ r+   )r-   itemsrB   s    r   r|   SessionBase.items   s    }}""$$r   c                 .    0 U l         SU l        SU l        g r7   )_session_cacher!   r"   rB   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   AttributeErrorrB   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                 ^    U R                   c  U R                  5       U l         U R                   $ r+   )r    r   rB   s    r   _get_or_create_session_key&SessionBase._get_or_create_session_key   s+    $ $ 9 9 ;D   r   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_keyrB   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                 "    [         R                  $ r+   )r   SESSION_COOKIE_AGErB   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_expiryiQ )KeyErrorr   nowrF   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                 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   rF   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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_expiry   sr     =*+ eY''LLNU*EeX&&OO%E"'  s   A   
A-,A-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   )rF   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                 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    rB   s    r   flushSessionBase.flush!  s    
 	

 r   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&   datar/   s      r   	cycle_keySessionBase.cycle_key*  s;     }}"KK r   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.exists7  s     "G
 	
r   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   rB   s    r   r   SessionBase.create?  s     "F
 	
r   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.saveI  s     "D
 	
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.deleteS  s    
 "F
 	
r   c                     [        S5      e)z0
Load the session data and return a dictionary.
z6subclasses of SessionBase must provide a load() methodr   rB   s    r   r   SessionBase.load\  s     "D
 	
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_expiredd  s     ""RSSr   )__session_keyr   r    r!   r"   r$   r+   )F)7r   r   r   r   r   rS   rR   objectrJ   r(   r0   r4   r;   r>   propertyrC   rF   rK   rO   rT   rW   rZ   ra   rl   ro   rs   rv   ry   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   !   s4    $ (KE$" H H/  + -
=I(
$$&%#!
%"& +,K,.>?L# %H+268.(8	!	




 T Tr   r   )rf   stringr   r   django.confr   django.corer   django.utilsr   django.utils.cryptor   django.utils.module_loadingr	   ascii_lowercasedigitsr   ri   r   r   r   r   r   r   <module>r      sY      (    ! 1 5 ((6==8	) 		) 	LT LTr   