
    h                          S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJrJ	r	J
r
Jr  S SKJr  S SKJrJr   " S S\
5      rg)    N)settings)VALID_KEY_CHARSCreateErrorSessionBaseUpdateError)InvalidSessionKey)ImproperlyConfiguredSuspiciousOperationc                      ^  \ rS rSrSrSU 4S jjr\S 5       rSS jrS r	S r
S rS	 rS
 rS rSS jrSS jrS rS rSS jrSS jr\S 5       r\S 5       rSrU =r$ )SessionStore   z'
Implement a file based session store.
c                 x   > U R                  5       U l        [        R                  U l        [
        TU ]  U5        g N)_get_storage_pathstorage_pathr   SESSION_COOKIE_NAMEfile_prefixsuper__init__)selfsession_key	__class__s     W/var/www/html/env/lib/python3.13/site-packages/django/contrib/sessions/backends/file.pyr   SessionStore.__init__   s/     224#77%    c                 
    U R                   $ ! [         aj    [        [        SS 5      =(       d    [        R
                  " 5       n[        R                  R                  U5      (       d  [        SU-  5      eXl         Us $ f = f)NSESSION_FILE_PATHzThe session storage path %r doesn't exist. Please set your SESSION_FILE_PATH setting to an existing directory in which Django can store session data.)
_storage_pathAttributeErrorgetattrr   tempfile
gettempdirospathisdirr	   )clsr   s     r   r   SessionStore._get_storage_path   s    	 $$$ 	 "5t<U@S@S@U  77==..*68DE  !-	 s    A1BBc                     Uc  U R                  5       n[        U5      R                  [        5      (       d  [	        S5      e[
        R                  R                  U R                  U R                  U-   5      $ )z0
Get the file associated with this session key.
z!Invalid characters in session key)
_get_or_create_session_keysetissubsetr   r   r#   r$   joinr   r   r   r   s     r   _key_to_fileSessionStore._key_to_file/   sb     99;K
 ;((99#$GHHww||D--t/?/?+/MNNr   c                     [         R                  " U R                  5       5      R                  n[        R
                  (       a  [        R                  R                  OSn[        R                  R                  XS9$ )zI
Return the modification time of the file storing the session's content.
N)tz)
r#   statr.   st_mtimer   USE_TZdatetimetimezoneutcfromtimestamp)r   modificationr1   s      r   _last_modificationSessionStore._last_modification>   sT     wwt0023<<&.ooX""4  ..|.CCr   c                     UR                  S5      =(       d3    U R                  5       [        R                  " U R	                  5       S9-   $ )zC
Return the expiry time of the file storing the session's content.
_session_expiry)seconds)getr:   r5   	timedeltaget_session_cookie_age)r   session_datas     r   _expiry_dateSessionStore._expiry_dateF   sF      12 
##%  )D)D)FGH	
r   c                    0 n [        U R                  5       SS9 nUR                  5       nS S S 5        W(       aX   U R                  U5      nU R                  U R                  U5      S9nUS::  a"  0 nU R!                  5         U R                  5         U$ ! , (       d  f       No= f! [        [
        4 av  n[        U[
        5      (       aG  [        R                  " SUR                  R                  -  5      nUR                  [        U5      5        U R                  5          S nANS nAff = f! ["        [
        4 a    S U l         U$ f = f)Nascii)encodingzdjango.security.%s)expiryr   )openr.   readdecodeEOFErrorr
   
isinstancelogging	getLoggerr   __name__warningstrcreateget_expiry_agerC   deleteOSError_session_key)r   rB   session_file	file_dataelogger
expiry_ages          r   loadSessionStore.loadO   s#   	%d'')G<(--/	 = "#';;y#9L "008I8I,8W0X
?#%LKKMKKM / =< !"56 "!!%899!(!2!201;;3G3GG" s1v.KKMM" ,- 	% $D	%sR   D0 BD0 B' AD0 
B$ D0 'D-7A,D(#D0 (D--D0 0E
Ec                 *   #    U R                  5       $ 7fr   )r]   r   s    r   aloadSessionStore.aloadk   s     yy{   c                      U R                  5       U l         U R                  SS9  SU l        g ! [         a     M;  f = f)NTmust_create)_get_new_session_keyrW   saver   modifiedr`   s    r   rS   SessionStore.createn   sI     $ 9 9 ;D		d	+ !DM  s   / 
==c                 *   #    U R                  5       $ 7fr   )rS   r`   s    r   acreateSessionStore.acreatex   s     {{}rc   c                    U R                   c  U R                  5       $ U R                  US9nU R                  5       n [        R
                  [        [        SS5      -  nU(       a$  U[        R                  [        R                  -  -  n[        R                  " X45      n[        R                  " U5        [        R                  R!                  U5      u  pg ["        R$                  " XgS-   S9u  pSn
  [        R&                  " XR)                  U5      R)                  5       5        [        R                  " U5        [*        R,                  " X5        Sn
U
(       d  [        R.                  " U	5        g g ! [         a    U(       d  [        e N[         a    U(       a  [        e Nf = f! [        R                  " U5        f = f! U
(       d  [        R.                  " U	5        f f = f! [0        [2        4 a     g f = f)N)no_loadO_BINARYr   _out_)dirprefixFT)r   rS   _get_sessionr.   r#   O_WRONLYr    O_EXCLO_CREATrI   closeFileNotFoundErrorr   FileExistsErrorr   r$   splitr!   mkstempwriteencodeshutilmoveunlinkrL   rV   )r   rf   rB   session_file_nameflagsfdrr   rs   output_file_fdoutput_file_namerenameds              r   rh   SessionStore.save{   s   #;;=  (((= --/	" KK'"j!"<<ERZZ//*2BHHRL. ggmm$56	/7/?/? 00,N G0-HH^[[-F-M-M-OPHH^,
 ,@II./ S ! 	"!!  	"!! 	"< HH^, II./ '" 		sT   A9E6 G) 63F+ ).G G) 6F(F('F(+GG  G&&G) )G<;G<c                 (   #    U R                  US9$ 7f)Nre   )rh   )r   rf   s     r   asaveSessionStore.asave   s     yy[y11   c                 ^    [         R                  R                  U R                  U5      5      $ r   )r#   r$   existsr.   r-   s     r   r   SessionStore.exists   s     ww~~d//<==r   c                 ,   #    U R                  U5      $ 7fr   )r   r-   s     r   aexistsSessionStore.aexists   s     {{;''   c                     Uc  U R                   c  g U R                   n [        R                  " U R                  U5      5        g ! [         a     g f = fr   )r   r#   r   r.   rV   r-   s     r   rU   SessionStore.delete   sP    '**K	IId''45 		s   %A 
AAc                 (   #    U R                  US9$ 7f)N)r   )rU   r-   s     r   adeleteSessionStore.adelete   s     {{{{33r   c                    U R                  5       n[        R                  n[        R                  " U5       HL  nUR                  U5      (       d  M  UR                  U5      nU " U5      nS Ul        UR                  5         MN     g )Nc                      g r    r   r   r   <lambda>,SessionStore.clear_expired.<locals>.<lambda>   s    Tr   )	r   r   r   r#   listdir
startswithremoveprefixrS   r]   )r&   r   r   rX   r   sessions         r   clear_expiredSessionStore.clear_expired   sn    ,,.22JJ|4L**;77&33K@K+&G *GNLLN 5r   c                 ,   #    U R                  5         g 7fr   )r   )r&   s    r   aclear_expiredSessionStore.aclear_expired   s     r   )rW   r   ri   r   r   )F)rP   
__module____qualname____firstlineno____doc__r   classmethodr   r.   r:   rC   r]   ra   rS   rl   rh   r   r   r   rU   r   r   r   __static_attributes____classcell__)r   s   @r   r   r      s    &
    $OD
8=~2>(4    r   r   )r5   rN   r#   r   r!   django.confr   %django.contrib.sessions.backends.baser   r   r   r   "django.contrib.sessions.exceptionsr   django.core.exceptionsr	   r
   r   r   r   r   <module>r      s8      	      A LP; Pr   