o
    ÕŸŽi›  ã                   @   sp   d dl 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 d dlmZ G d	d
„ d
eƒZdS )é    N)Úimport_module)Úsettings)ÚUpdateError)ÚSessionInterrupted)Úpatch_vary_headers)ÚMiddlewareMixin)Ú	http_datec                       s,   e Zd Z‡ fdd„Zdd„ Zdd„ Z‡  ZS )ÚSessionMiddlewarec                    s"   t ƒ  |¡ ttjƒ}|j| _d S ©N)ÚsuperÚ__init__r   r   ZSESSION_ENGINEÚSessionStore)ÚselfZget_responseZengine©Ú	__class__© úlC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\django/contrib/sessions/middleware.pyr      s   
zSessionMiddleware.__init__c                 C   s   |j  tj¡}|  |¡|_d S r
   )ÚCOOKIESÚgetr   ÚSESSION_COOKIE_NAMEr   Úsession)r   ÚrequestÚsession_keyr   r   r   Úprocess_request   s   z!SessionMiddleware.process_requestc           	      C   s$  z|j j}|j j}|j  ¡ }W n ty   | Y S w tj|jv r7|r7|jtjtj	tj
tjd� t|dƒ |S |r>t|dƒ |sCtjr�|s�|j  ¡ rOd}d}n|j  ¡ }t ¡ | }t|ƒ}|jdk r�z|j  ¡  W n tyu   tdƒ‚w |jtj|j j||tj
tj	tjp‡dtjp‹dtjd�	 |S )zå
        If request.session was modified, or if the configuration is to save the
        session every time, save the changes and set a session cookie or delete
        the session cookie if the session has been emptied.
        )ÚpathÚdomainÚsamesite)ÚCookieNiô  z‚The request's session was deleted before the request completed. The user may have logged out in a concurrent request, for example.)Úmax_ageÚexpiresr   r   ÚsecureÚhttponlyr   )r   ÚaccessedÚmodifiedZis_emptyÚAttributeErrorr   r   r   Zdelete_cookieZSESSION_COOKIE_PATHZSESSION_COOKIE_DOMAINZSESSION_COOKIE_SAMESITEr   ZSESSION_SAVE_EVERY_REQUESTZget_expire_at_browser_closeZget_expiry_ageÚtimer   Ústatus_codeÚsaver   r   Ú
set_cookier   ZSESSION_COOKIE_SECUREZSESSION_COOKIE_HTTPONLY)	r   r   Úresponser"   r#   Úemptyr   r   Zexpires_timer   r   r   Úprocess_response   sZ   ÿü
"à



ÿÿ÷z"SessionMiddleware.process_response)Ú__name__Ú
__module__Ú__qualname__r   r   r+   Ú__classcell__r   r   r   r   r	      s    r	   )r%   Ú	importlibr   Zdjango.confr   Z%django.contrib.sessions.backends.baser   Z"django.contrib.sessions.exceptionsr   Zdjango.utils.cacher   Zdjango.utils.deprecationr   Zdjango.utils.httpr   r	   r   r   r   r   Ú<module>   s    