
    Evg                          d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZ d dlmZ d dlmZmZ  G d de
          ZdS )    N)settings)VALID_KEY_CHARSCreateErrorSessionBaseUpdateError)InvalidSessionKey)ImproperlyConfiguredSuspiciousOperationc                        e Zd ZdZd fd	Zed             ZddZd Zd Z	d Z
d	 Zd
 Zd ZddZddZd Zd ZddZddZed             Zed             Z xZS )SessionStorez/
    Implement a file based session store.
    Nc                     |                                  | _        t          j        | _        t                                          |           d S N)_get_storage_pathstorage_pathr   SESSION_COOKIE_NAMEfile_prefixsuper__init__)selfsession_key	__class__s     b/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/sessions/backends/file.pyr   zSessionStore.__init__   s@     2244#7%%%%%    c                     	 | j         S # t          $ rf t          t          dd           pt	          j                    }t          j                            |          st          d|z            || _         |cY S w xY w)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   zSessionStore._get_storage_path   s    	 $$ 	  	  	 "5t<<U@S@U@U  7==.. *68DE   !-C	 s   	 A-A98A9c                     ||                                  }t          |                              t                    st	          d          t
          j                            | j        | j	        |z             S )z@
        Get the file associated with this session key.
        Nz!Invalid characters in session key)
_get_or_create_session_keysetissubsetr   r   r!   r"   joinr   r   r   r   s     r   _key_to_filezSessionStore._key_to_file/   sl     99;;K
 ;((99 	I#$GHHHw||D-t/?+/MNNNr   c                     t          j        |                                           j        }t          j        rt          j        j        nd}t          j        	                    ||          S )zY
        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   modificationr-   s      r   _last_modificationzSessionStore._last_modification>   sU     wt002233<&.o?X""4 ..|.CCCr   c                     |                     d          p;|                                 t          j        |                                           z   S )zS
        Return the expiry time of the file storing the session's content.
        _session_expiry)seconds)getr6   r1   	timedeltaget_session_cookie_age)r   session_datas     r   _expiry_datezSessionStore._expiry_dateF   sR      122 
##%% )D)D)F)FGGGH	
r   c                    i }	 t          |                                 d          5 }|                                }d d d            n# 1 swxY w Y   |r	 |                     |          }n# t          t
          f$ rv}t          |t
                    rCt          j        d|j	        j
        z            }|                    t          |                     |                                  Y d }~nd }~ww xY w|                     |                     |                    }|dk    r*i }|                                  |                                  n# t"          t
          f$ r
 d | _        Y nw xY w|S )Nascii)encodingzdjango.security.%s)expiryr   )openr+   readdecodeEOFErrorr
   
isinstancelogging	getLoggerr   __name__warningstrcreateget_expiry_ager>   deleteOSError_session_key)r   r=   session_file	file_dataelogger
expiry_ages          r   loadzSessionStore.loadO   s   	%d''))G<<< 0(--//	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  ""#';;y#9#9LL "56 " " "!!%899 /!(!201;3GG" " s1vv...KKMMMMMMMM" "008I8I,8W8W0XX
??#%LKKMMMKKMMM,- 	% 	% 	% $D	%s_   #E AE AE AE A, +E ,C3=A,C.)E .C33AE E+*E+c                 .   K   |                                  S r   )rW   r   s    r   aloadzSessionStore.aloadk   s      yy{{r   c                     	 |                                  | _        	 |                     d           n# t          $ r Y >w xY wd| _        d S )NTmust_create)_get_new_session_keyrQ   saver   modifiedrY   s    r   rM   zSessionStore.createn   sc    	 $ 9 9 ; ;D		d	++++    DMFs   3 
A A c                 .   K   |                                  S r   )rM   rY   s    r   acreatezSessionStore.acreatex   s      {{}}r   Fc                    | j         |                                 S |                     |          }|                                 }	 t          j        t          t          dd          z  }|r|t          j        t          j        z  z  }t	          j	        ||          }t	          j
        |           n-# t          $ r |st          Y nt          $ r |rt          Y nw xY wt          j                            |          \  }}	 t#          j        ||dz             \  }}	d}
	 	 t	          j        ||                     |                                                     t	          j
        |           n# t	          j
        |           w xY wt+          j        |	|           d}
|
st	          j        |	           d S d S # |
st	          j        |	           w w xY w# t0          t2          f$ r Y d S w xY w)N)no_loadO_BINARYr   _out_)dirprefixFT)r   rM   _get_sessionr+   r!   O_WRONLYr   O_EXCLO_CREATrC   closeFileNotFoundErrorr   FileExistsErrorr   r"   splitr   mkstempwriteencodeshutilmoveunlinkrF   rP   )r   r]   r=   session_file_nameflagsfdrg   rh   output_file_fdoutput_file_namerenameds              r   r_   zSessionStore.save{   s4   #;;==  (((== --//	" K'"j!"<"<<E 0RZ//*E22BHRLLLL  	" 	" 	" "!!" " 	" 	" 	" "!!" "	"& gmm$566V	/7/? 00 0 0,N, G0-H^T[[-F-F-M-M-O-OPPPH^,,,,BH^,,,,
 ,.?@@@ 0I./////0 0w 0I.////0'" 	 	 	DD	sU   A*B2 2CCCG ":E1 F; 1FF; !G ;GG G,+G,c                 2   K   |                      |          S )Nr\   )r_   )r   r]   s     r   asavezSessionStore.asave   s      yy[y111r   c                 f    t           j                            |                     |                    S r   )r!   r"   existsr+   r*   s     r   r   zSessionStore.exists   s$    w~~d//<<===r   c                 0   K   |                      |          S r   )r   r*   s     r   aexistszSessionStore.aexists   s      {{;'''r   c                     || j         d S | j         }	 t          j        |                     |                     d S # t          $ r Y d S w xY wr   )r   r!   rv   r+   rP   r*   s     r   rO   zSessionStore.delete   si    '*K	Id''4455555 	 	 	DD	s   '= 
A
Ac                 2   K   |                      |          S )N)r   )rO   r*   s     r   adeletezSessionStore.adelete   s      {{{{333r   c                    |                                  }t          j        }t          j        |          D ]T}|                    |          s|                    |          } | |          }d |_        |                                 Ud S )Nc                      d S r    r   r   r   <lambda>z,SessionStore.clear_expired.<locals>.<lambda>   s    T r   )	r   r   r   r!   listdir
startswithremoveprefixrM   rW   )r$   r   r   rR   r   sessions         r   clear_expiredzSessionStore.clear_expired   s    ,,..2J|44 		 		L**;77 &33K@@Kc+&&G *\GNLLNNNN		 		r   c                 2   K   |                                   d S r   )r   )r$   s    r   aclear_expiredzSessionStore.aclear_expired   s      r   r   )F)rJ   
__module____qualname____doc__r   classmethodr   r+   r6   r>   rW   rZ   rM   rb   r_   r~   r   r   rO   r   r   r   __classcell__)r   s   @r   r   r      s|        & & & & & &
     [ $O O O OD D D
 
 
  8      = = = =~2 2 2 2> > >( ( (   4 4 4 4   [   [    r   r   )r1   rH   r!   rt   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      s      				                          A @ @ @ @ @ L L L L L L L LP P P P P; P P P P Pr   