o
    ^"<fÛ  ã                   @   s@   d Z ddlmZ ddlmZ ddlmZ dZG dd„ deƒZdS )	z#
Cached, database-backed sessions.
é    )Úsettings)ÚSessionStore)Úcachesz!django.contrib.sessions.cached_dbc                       sj   e Zd ZdZeZd‡ fdd„	Zedd„ ƒZdd„ Z	‡ fd	d
„Z
d‡ fdd„	Zd‡ fdd„	Zdd„ Z‡  ZS )r   z5
    Implement cached, database backed sessions.
    Nc                    s   t tj | _tƒ  |¡ d S ©N)r   r   ÚSESSION_CACHE_ALIASÚ_cacheÚsuperÚ__init__©ÚselfÚsession_key©Ú	__class__© úa/var/www/html/kck/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/cached_db.pyr	      s   zSessionStore.__init__c                 C   s   | j |  ¡  S r   )Úcache_key_prefixÚ_get_or_create_session_key©r   r   r   r   Ú	cache_key   s   zSessionStore.cache_keyc                 C   sr   z	| j  | j¡}W n ty   d }Y nw |d u r7|  ¡ }|r5|  |j¡}| j  | j|| j|j	d¡ |S i }|S )N)Úexpiry)
r   Úgetr   Ú	ExceptionÚ_get_session_from_dbÚdecodeÚsession_dataÚsetÚget_expiry_ageÚexpire_date)r   ÚdataÚsr   r   r   Úload   s   ýÿzSessionStore.loadc                    s    |r
| j | | jv ptƒ  |¡S r   )r   r   r   Úexistsr
   r   r   r   r!   +   s    zSessionStore.existsFc                    s(   t ƒ  |¡ | j | j| j|  ¡ ¡ d S r   )r   Úsaver   r   r   Ú_sessionr   )r   Úmust_creater   r   r   r"   .   s   zSessionStore.savec                    s>   t ƒ  |¡ |d u r| jd u rd S | j}| j | j| ¡ d S r   )r   Údeleter   r   r   r
   r   r   r   r%   2   s   
zSessionStore.deletec                 C   s   |   ¡  |  | j¡ d| _dS )zc
        Remove the current session data from the database and regenerate the
        key.
        N)Úclearr%   r   Ú_session_keyr   r   r   r   Úflush:   s   
zSessionStore.flushr   )F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
KEY_PREFIXr   r	   Úpropertyr   r    r!   r"   r%   r(   Ú__classcell__r   r   r   r   r      s    
r   N)	r,   Údjango.confr   Ú#django.contrib.sessions.backends.dbr   ÚDBStoreÚdjango.core.cacher   r-   r   r   r   r   Ú<module>   s    