
    Hwg                     r    d dl Z d dlmZmZm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  G d de      Zy)	    N)CreateErrorSessionBaseUpdateError)SuspiciousOperation)DatabaseErrorIntegrityErrorroutertransaction)timezone)cached_propertyc                        e Zd ZdZd fd	Zed        Zed        Zd Z	d Z
d Zd Zd	 Zdd
ZddZed        Z xZS )SessionStorez+
    Implement database session store.
    c                 $    t         |   |       y N)super__init__)selfsession_key	__class__s     Z/var/www/horilla/myenv/lib/python3.12/site-packages/django/contrib/sessions/backends/db.pyr   zSessionStore.__init__   s    %    c                     ddl m} |S )Nr   )Session)django.contrib.sessions.modelsr   )clsr   s     r   get_model_classzSessionStore.get_model_class   s     	;r   c                 "    | j                         S r   )r   r   s    r   modelzSessionStore.model   s    ##%%r   c                    	 | j                   j                  j                  | j                  t	        j
                               S # | j                   j                  t        f$ rg}t        |t              rFt        j                  d|j                  j                  z        }|j                  t        |             d | _        Y d }~y d }~ww xY w)N)r   expire_date__gtzdjango.security.%s)r   objectsgetr   r   nowDoesNotExistr   
isinstancelogging	getLoggerr   __name__warningstr_session_key)r   eloggers      r   _get_session_from_dbz!SessionStore._get_session_from_db   s    	%::%%)) ,,hlln *   

'')<= 	%!01 **+?!++BVBV+VWs1v& $D		%s   AA C$ACCc                 `    | j                         }|r| j                  |j                        S i S r   )r/   decodesession_data)r   ss     r   loadzSessionStore.load)   s*    %%'./t{{1>>*7R7r   c                 j    | j                   j                  j                  |      j                         S N)r   )r   r"   filterexistsr   r   s     r   r8   zSessionStore.exists-   s)    zz!!(([(AHHJJr   c                     	 | j                         | _        	 | j                  d       d| _        y # t        $ r Y <w xY w)NT)must_create)_get_new_session_keyr,   saver   modifiedr   s    r   createzSessionStore.create0   sK     $ 9 9 ;D 		d	+ !DM	  s   2 	>>c                     | j                  | j                         | j                  |      | j                               S )z
        Return a new instance of the session model object, which represents the
        current session state. Intended to be used for saving the session data
        to the database.
        )r   r2   expire_date)r   _get_or_create_session_keyencodeget_expiry_date)r   datas     r   create_model_instancez"SessionStore.create_model_instance=   s>     zz779T*,,.  
 	
r   c                    | j                   | j                         S | j                  |      }| j                  |      }t	        j
                  | j                  |      }	 t        j                  |      5  |j                  || |       ddd       y# 1 sw Y   yxY w# t        $ r
 |rt         t        $ r
 |st         w xY w)z
        Save the current session data to the database. If 'must_create' is
        True, raise a database error if the saving operation doesn't create a
        new entry (as opposed to possibly updating an existing entry).
        N)no_load)instance)using)force_insertforce_updaterJ   )r   r?   _get_sessionrF   r	   db_for_writer   r
   atomicr=   r   r   r   r   )r   r;   rE   objrJ   s        r   r=   zSessionStore.saveI   s     #;;=    5((.##DJJ=	##%0 !,{?RW      	!! 	!!	s*   "B# 8BB# B B#  B# #$Cc                     || j                   y | j                   }	 | j                  j                  j                  |      j	                          y # | j                  j
                  $ r Y y w xY wr6   )r   r   r"   r#   deleter%   r9   s     r   rR   zSessionStore.deleteb   sg    '**K	JJ""{";BBDzz&& 		s   4A A.-A.c                     | j                         j                  j                  t        j                               j                          y )N)expire_date__lt)r   r"   r7   r   r$   rR   )r   s    r   clear_expiredzSessionStore.clear_expiredl   s1    %%,,X\\^,LSSUr   r   )F)r)   
__module____qualname____doc__r   classmethodr   r   r   r/   r4   r8   r?   rF   r=   rR   rU   __classcell__)r   s   @r   r   r   
   so    &   & &	%8K

2 V Vr   r   )r'   %django.contrib.sessions.backends.baser   r   r   django.core.exceptionsr   	django.dbr   r   r	   r
   django.utilsr   django.utils.functionalr   r    r   r   <module>ra      s-     W W 6 H H ! 3dV; dVr   