
    g>B                         d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ ej                   ej"                  z   Z G d	 d
e      Z G d de      Z G d d      Zy)    N)datetime	timedelta)sync_to_async)settings)signing)timezone)get_random_string)import_stringc                       e Zd ZdZy)CreateErrorz
    Used internally as a consistent exception type to catch from save (see the
    docstring for SessionBase.save() for details).
    N__name__
__module____qualname____doc__     }/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/contrib/sessions/backends/base.pyr   r      s    
 	r   r   c                       e Zd ZdZy)UpdateErrorzF
    Occurs if Django tries to update a session that was deleted.
    Nr   r   r   r   r   r      s     	r   r   c                   "   e Zd ZdZdZdZ e       ZdHdZd Z	d Z
d Zd	 Zd
 Zed        ZdHdZdHdZefdZefdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d  Z$d! Z%d" Z&d# Z'd$ Z(d% Z)d& Z*d' Z+d( Z,d) Z-d* Z.d+ Z/d, Z0 ee/      Z1 ee/e0      Z2dId-Z3dId.Z4 ee3      Z5d/ Z6d0 Z7d1 Z8d2 Z9d3 Z:d4 Z;d5 Z<d6 Z=d7 Z>d8 Z?d9 Z@d: ZAd; ZBd< ZCd= ZDd> ZEd? ZFdId@ZGdIdAZHdHdBZIdHdCZJdD ZKdE ZLeMdF        ZNeMdG        ZOy)JSessionBasez-
    Base class for all Session classes.
    
testcookieworkedNc                 j    || _         d| _        d| _        t        t        j
                        | _        y )NF)_session_keyaccessedmodifiedr
   r   SESSION_SERIALIZER
serializerselfsession_keys     r   __init__zSessionBase.__init__-   s*    ''(C(CDr   c                     || j                   v S N_sessionr"   keys     r   __contains__zSessionBase.__contains__3       dmm##r   c                      | j                   |   S r&   r'   r)   s     r   __getitem__zSessionBase.__getitem__6   s    }}S!!r   c                 0    || j                   |<   d| _        y NTr(   r   r"   r*   values      r   __setitem__zSessionBase.__setitem__9   s    "cr   c                 T   K   || j                          d {   |<   d| _        y 7 wr0   )_aget_sessionr   r2   s      r   asetzSessionBase.aset=   s(     ,1t!!#	#S) 
$s   (&(c                 ,    | j                   |= d| _        y r0   r1   r)   s     r   __delitem__zSessionBase.__delitem__A   s    MM#r   c                 4    d| j                   j                  z   S )Nzdjango.contrib.sessions.)	__class__r   r"   s    r   key_saltzSessionBase.key_saltE   s    )DNN,G,GGGr   c                 :    | j                   j                  ||      S r&   )r(   getr"   r*   defaults      r   r?   zSessionBase.getI   s    }}  g..r   c                 ^   K   | j                          d {   j                  ||      S 7 wr&   )r6   r?   r@   s      r   agetzSessionBase.agetL   s(     ((**//W==*s   -+-c                     | j                   xs || j                  v | _         || j                  u rdn|f} | j                  j                  |g| S Nr   )r   r(   _SessionBase__not_givenpopr"   r*   rA   argss       r   rG   zSessionBase.popO   sM    =)= 0 00rwj t}}  ,t,,r   c                    K   | j                   xs || j                          d {   v | _         || j                  u rdn|f} | j                          d {   j                  |g| S 7 F7 wrE   )r   r6   rF   rG   rH   s       r   apopzSessionBase.apopT   sk     Lt7I7I7K1K)L 0 00rwj/d((**//;d;; 2L*s!   #A0A,1A0A.A0.A0c                 J    || j                   v r| j                   |   S || |<   |S r&   r'   r2   s      r   
setdefaultzSessionBase.setdefaultY   s+    $--==%%DILr   c                    K   | j                          d {   }||v r||   S | j                  ||       d {    |S 7 )7 wr&   )r6   r7   )r"   r*   r3   sessions       r   asetdefaultzSessionBase.asetdefault`   sL     **,,'>3<))C'''L - (s   AA "AAAAc                 6    | j                   | | j                  <   y r&   )TEST_COOKIE_VALUETEST_COOKIE_NAMEr<   s    r   set_test_cookiezSessionBase.set_test_cookieh   s    &*&<&<T""#r   c                 l   K   | j                  | j                  | j                         d {    y 7 wr&   )r7   rS   rR   r<   s    r   aset_test_cookiezSessionBase.aset_test_cookiek   s&     ii--t/E/EFFFs   *424c                 R    | j                  | j                        | j                  k(  S r&   )r?   rS   rR   r<   s    r   test_cookie_workedzSessionBase.test_cookie_workedn   s"    xx--.$2H2HHHr   c                 n   K   | j                  | j                         d {   | j                  k(  S 7 wr&   )rC   rS   rR   r<   s    r   atest_cookie_workedzSessionBase.atest_cookie_workedq   s,     ii 5 5664;Q;QQQ6s   535c                     | | j                   = y r&   )rS   r<   s    r   delete_test_cookiezSessionBase.delete_test_cookiet   s    &&'r   c                 V   K   | j                          d {   | j                  = y 7 wr&   )r6   rS   r<   s    r   adelete_test_cookiezSessionBase.adelete_test_cookiew   s#     %%'')>)>?'s   )')c                 \    t        j                  || j                  | j                  d      S )zGReturn the given session dictionary serialized and encoded as a string.T)saltr    compress)r   dumpsr=   r    )r"   session_dicts     r   encodezSessionBase.encodez   s'    }}	
 	
r   c                     	 t        j                  || j                  | j                        S # t         j                  $ r* t        j                  d      }|j                  d       Y i S t        $ r Y i S w xY w)N)r`   r    z!django.security.SuspiciousSessionzSession data corrupted)	r   loadsr=   r    BadSignaturelogging	getLoggerwarning	Exception)r"   session_dataloggers      r   decodezSessionBase.decode   sw    
	==4==T__  ## 	5&&'JKFNN34
 		  	 			s   +. 9A6*A65A6c                 H    | j                   j                  |       d| _        y r0   )r(   updater   r"   dict_s     r   rp   zSessionBase.update   s    U#r   c                 l   K   | j                          d {   j                  |       d| _        y 7 wr0   )r6   rp   r   rq   s     r   aupdatezSessionBase.aupdate   s,     !!#	#++E2 
$s   424c                     || j                   v S r&   r'   r)   s     r   has_keyzSessionBase.has_key   r,   r   c                 B   K   || j                          d {   v S 7 wr&   )r6   r)   s     r   ahas_keyzSessionBase.ahas_key   s      T//11221s   c                 6    | j                   j                         S r&   )r(   keysr<   s    r   rz   zSessionBase.keys   s    }}!!##r   c                 Z   K   | j                          d {   j                         S 7 wr&   )r6   rz   r<   s    r   akeyszSessionBase.akeys   s$     ((**0022*   +)+c                 6    | j                   j                         S r&   )r(   valuesr<   s    r   r   zSessionBase.values   s    }}##%%r   c                 Z   K   | j                          d {   j                         S 7 wr&   )r6   r   r<   s    r   avalueszSessionBase.avalues   s$     ((**2244*r}   c                 6    | j                   j                         S r&   )r(   itemsr<   s    r   r   zSessionBase.items   s    }}""$$r   c                 Z   K   | j                          d {   j                         S 7 wr&   )r6   r   r<   s    r   aitemszSessionBase.aitems   s$     ((**1133*r}   c                 .    i | _         d| _        d| _        y r0   )_session_cacher   r   r<   s    r   clearzSessionBase.clear   s     !r   c                 Z    	 | j                    xr | j                   S # t        $ r Y yw xY w)zBReturn True when there is no session_key and the session is empty.T)r   r   AttributeErrorr<   s    r   is_emptyzSessionBase.is_empty   s6    	(((D1D1D-DD 		s    	**c                 L    	 t        dt              }| j                  |      s|S $)z)Return session key that isn't being used.    )r	   VALID_KEY_CHARSexistsr!   s     r   _get_new_session_keyz SessionBase._get_new_session_key   s(    +B@K;;{+"" r   c                 h   K   	 t        dt              }| j                  |       d {   s|S ,7 w)Nr   )r	   r   aexistsr!   s     r   _aget_new_session_keyz!SessionBase._aget_new_session_key   s5     +B@Kk222"" 2s   &202c                 \    | j                   | j                         | _         | j                   S r&   )r   r   r<   s    r   _get_or_create_session_keyz&SessionBase._get_or_create_session_key   s+    $ $ 9 9 ;D   r   c                 x   K   | j                   | j                          d {   | _         | j                   S 7 wr&   )r   r   r<   s    r   _aget_or_create_session_keyz'SessionBase._aget_or_create_session_key   s8     $&*&@&@&B BD    !Cs    :8:c                 &    |xr t        |      dk\  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_keyz!SessionBase._validate_session_key   s    
 $s3x1}$r   c                     | j                   S r&   )_SessionBase__session_keyr<   s    r   _get_session_keyzSessionBase._get_session_key   s    !!!r   c                 D    | j                  |      r|| _        yd| _        y)zV
        Validate session key on assignment. Invalid values will set to None.
        N)r   r   r"   r3   s     r   _set_session_keyzSessionBase._set_session_key   s"     %%e,!&D!%Dr   c                     d| _         	 | j                  S # t        $ r9 | j                  |ri | _        n| j	                         | _        Y | j                  S w xY w)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_sessionzSessionBase._get_session   s\    
 	2&&& 	2'7&(#&*iik#"""	2s    4AAc                    K   d| _         	 | j                  S # t        $ rB | j                  |ri | _        n| j	                          d {  7  | _        Y | j                  S w xY wwr0   )r   r   r   r#   aloadr   s     r   r6   zSessionBase._aget_session   sc     	9&&& 	9'7&(#,0JJL&8&8#"""	9s1   A% A%2A"	A

A"A%!A""A%c                 "    t         j                  S r&   )r   SESSION_COOKIE_AGEr<   s    r   get_session_cookie_agez"SessionBase.get_session_cookie_age	  s    ***r   c                    	 |d   }	 |d   }|s| j	                         S t        |t        t        f      s|S t        |t              rt        j                  |      }||z
  }|j                  dz  |j                  z   S # t         $ r t        j                         }Y w xY w# t         $ r | j                  d      }Y w xY w)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   nowr?   r   
isinstancer   strfromisoformatdayssecondsr"   kwargsr   r   deltas        r   get_expiry_agezSessionBase.get_expiry_age  s    	*!.1L	1H%F ..00&8S/2Mfc"++F3F%zzE!EMM11#  	*#<<>L	*  	1XX/0F	1s"   A= B  =BB B=<B=c                   K   	 |d   }	 |d   }|s| j	                         S t        |t        t        f      s|S t        |t              rt        j                  |      }||z
  }|j                  dz  |j                  z   S # t         $ r t        j                         }Y w xY w# t         $ r | j                  d       d {  7  }Y w xY ww)Nr   r   r   r   )r   r   r   rC   r   r   r   r   r   r   r   r   s        r   aget_expiry_agezSessionBase.aget_expiry_age'  s     	*!.1L	8H%F ..00&8S/2Mfc"++F3F%zzE!EMM11  	*#<<>L	*  	899%6777F	8sQ   CA? B" A0C?BCBC"C?C CCCCc                 T   	 |d   }	 |d   }t	        |t
              r|S t	        |t              rt        j                  |      S |xs | j                         }|t        |      z   S # t         $ r t        j                         }Y w xY w# t         $ r | j                  d      }Y w xY w)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   r?   r   r   r   r   r   r   r"   r   r   r   s       r   get_expiry_datez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"   A' B
 'BB
B'&B'c                 n  K   	 |d   }	 |d   }t	        |t
              r|S t	        |t              rt        j                  |      S |xs | j                         }|t        |      z   S # t         $ r t        j                         }Y w xY w# t         $ r | j                  d       d {  7  }Y w xY ww)Nr   r   r   r   )
r   r   r   rC   r   r   r   r   r   r   r   s       r   aget_expiry_datez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   B5A) B AB5)B	B5B		B5B2)B,*B2/B51B22B5c                     |	 | d= yt        |t              rt        j                         |z   }t        |t
              r|j                         }|| d<   y# t         $ r Y yw xY w)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_expiryzSessionBase.set_expiryb  sn     =*+ eY'LLNU*EeX&OO%E"'  s   A 	A! A!c                 .  K   |	 | j                  d       d {    y t        |t              rt	        j
                         |z   }t        |t              r|j                         }| j                  d|       d {    y 7 g# t        $ r Y y w xY w7 w)Nr   )	rK   r   r   r   r   r   r   r   r7   r   s     r   aset_expiryz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                 R    | j                  d      x}t        j                  S |dk(  S )a  
        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   )r?   r   SESSION_EXPIRE_AT_BROWSER_CLOSEr"   r   s     r   get_expire_at_browser_closez'SessionBase.get_expire_at_browser_close  s/     hh011F:;;;{r   c                 n   K   | j                  d       d {   x}t        j                  S |dk(  S 7 w)Nr   r   )rC   r   r   r   s     r   aget_expire_at_browser_closez(SessionBase.aget_expire_at_browser_close  s9      II&7888FA;;;{ 9s   535c                 R    | j                          | j                          d| _        y)zc
        Remove the current session data from the database and regenerate the
        key.
        N)r   deleter   r<   s    r   flushzSessionBase.flush  s    
 	

 r   c                 n   K   | j                          | j                          d {    d | _        y 7 wr&   )r   adeleter   r<   s    r   aflushzSessionBase.aflush  s+     

lln  	s   $535c                     | j                   }| j                  }| j                          || _        |r| j	                  |       yyzU
        Create a new session key, while retaining the current session data.
        N)r(   r#   creater   r   r"   datar*   s      r   	cycle_keyzSessionBase.cycle_key  s=     }}"KK r   c                    K   | j                          d{   }| j                  }| j                          d{    || _        |r| j	                  |       d{    yy7 L7 *7 
wr   )r6   r#   acreater   r   r   s      r   
acycle_keyzSessionBase.acycle_key  sd      ''))lln",,s### 	 * $s1   A)A##A)A%!A)A'A)%A)'A)c                     t        d      )zF
        Return True if the given session_key already exists.
        z9subclasses of SessionBase must provide an exists() methodNotImplementedErrorr!   s     r   r   zSessionBase.exists  s     "G
 	
r   c                 T   K    t        | j                        |       d {   S 7 wr&   )r   r   r!   s     r   r   zSessionBase.aexists  "     /]4;;/<<<<   (&(c                     t        d      )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   r<   s    r   r   zSessionBase.create  s     "F
 	
r   c                 R   K    t        | j                                d {   S 7 wr&   )r   r   r<   s    r   r   zSessionBase.acreate  s      /]4;;/1111   '%'c                     t        d      )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   savezSessionBase.save  s     "D
 	
r   c                 T   K    t        | j                        |       d {   S 7 wr&   )r   r   r   s     r   asavezSessionBase.asave  s"     -]499-k::::r   c                     t        d      )zx
        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   zSessionBase.delete  s    
 "F
 	
r   c                 T   K    t        | j                        |       d {   S 7 wr&   )r   r   r!   s     r   r   zSessionBase.adelete  r   r   c                     t        d      )z@
        Load the session data and return a dictionary.
        z6subclasses of SessionBase must provide a load() methodr   r<   s    r   r   zSessionBase.load  s     "D
 	
r   c                 R   K    t        | j                                d {   S 7 wr&   )r   r   r<   s    r   r   zSessionBase.aload  s      -]499-////r   c                     t        d      )a  
        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_expiredzSessionBase.clear_expired  s     ""RSSr   c                 R   K    t        | j                                d {   S 7 wr&   )r   r   r   s    r   aclear_expiredzSessionBase.aclear_expired	  s"     5]3#4#457777r   r&   )F)Pr   r   r   r   rS   rR   objectrF   r$   r+   r.   r4   r7   r9   propertyr=   r?   rC   rG   rK   rM   rP   rT   rV   rX   rZ   r\   r^   rd   rn   rp   rt   rv   rx   rz   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r#   r   r   r6   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   #   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   )rh   stringr   r   asgiref.syncr   django.confr   django.corer   django.utilsr   django.utils.cryptor	   django.utils.module_loadingr
   ascii_lowercasedigitsr   rk   r   r   r   r   r   r   <module>r     sZ      ( &    ! 1 5 ((6==8	) 		) 	h8 h8r   