Ë
    ùi¯eà-  ã                   óÒ   — d dl Z d dlZd dlmZ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 ej                  ej                  z   Z G d„ d	e«      Z G d
„ de«      Z G d„ d«      Zy)é    N)ÚdatetimeÚ	timedelta)Úsettings)Úsigning)Útimezone)Úget_random_string)Úimport_stringc                   ó   — e Zd ZdZy)ÚCreateErrorz‡
    Used internally as a consistent exception type to catch from save (see the
    docstring for SessionBase.save() for details).
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úNE:\TRUCKING_PROJECT\Lib\site-packages\django/contrib/sessions/backends/base.pyr   r      s   „ ñð
 	r   r   c                   ó   — e Zd ZdZy)ÚUpdateErrorzF
    Occurs if Django tries to update a session that was deleted.
    Nr   r   r   r   r   r      s   „ ñð 	r   r   c                   ój  — e Zd ZdZdZdZ e«       Zd-d„Zd„ Z	d„ Z
d„ Zd	„ Zed
„ «       Zd-d„Zefd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z d„ Z!d„ Z" ee!«      Z# ee!e"«      Z$d.d„Z% ee%«      Z&d „ Z'd!„ Z(d"„ Z)d#„ Z*d$„ Z+d%„ Z,d&„ Z-d'„ Z.d(„ Z/d.d)„Z0d-d*„Z1d+„ Z2e3d,„ «       Z4y)/ÚSessionBasez-
    Base class for all Session classes.
    Ú
testcookieÚworkedNc                 ój   — || _         d| _        d| _        t        t        j
                  «      | _        y )NF)Ú_session_keyÚaccessedÚmodifiedr	   r   ÚSESSION_SERIALIZERÚ
serializer©ÚselfÚsession_keys     r   Ú__init__zSessionBase.__init__+   s*   € Ø'ˆÔØˆŒØˆŒÜ'¬×(CÑ(CÓDˆ�r   c                 ó   — || j                   v S ©N©Ú_session©r!   Úkeys     r   Ú__contains__zSessionBase.__contains__1   ó   € Ø�d—m‘mÐ#Ð#r   c                 ó    — | j                   |   S r%   r&   r(   s     r   Ú__getitem__zSessionBase.__getitem__4   s   € Ø�}‰}˜SÑ!Ð!r   c                 ó0   — || j                   |<   d| _        y ©NT©r'   r   ©r!   r)   Úvalues      r   Ú__setitem__zSessionBase.__setitem__7   s   € Ø"ˆ�‰�cÑØˆ�r   c                 ó,   — | j                   |= d| _        y r/   r0   r(   s     r   Ú__delitem__zSessionBase.__delitem__;   s   € Ø�M‰M˜#ÐØˆ�r   c                 ó4   — d| j                   j                  z   S )Nzdjango.contrib.sessions.)Ú	__class__r   ©r!   s    r   Úkey_saltzSessionBase.key_salt?   s   € à)¨D¯N©N×,GÑ,GÑGÐGr   c                 ó:   — | j                   j                  ||«      S r%   )r'   Úget)r!   r)   Údefaults      r   r;   zSessionBase.getC   s   € Ø�}‰}× Ñ   gÓ.Ð.r   c                 ó¤   — | j                   xs || j                  v | _         || j                  u rdn|f} | j                  j                  |g|¢­Ž S )Nr   )r   r'   Ú_SessionBase__not_givenÚpop)r!   r)   r<   Úargss       r   r?   zSessionBase.popF   sM   € ØŸ™Ò=¨°·±Ð)=ˆŒØ × 0Ñ 0Ñ0‰r°w°jˆØ ˆt�}‰}× Ñ  Ð, tÒ,Ð,r   c                 ól   — || j                   v r| j                   |   S d| _        || j                   |<   |S r/   r0   r1   s      r   Ú
setdefaultzSessionBase.setdefaultK   s7   € Ø�$—-‘-ÑØ—=‘= Ñ%Ð%à ˆDŒMØ!&ˆD�M‰M˜#ÑØˆLr   c                 ó6   — | j                   | | j                  <   y r%   )ÚTEST_COOKIE_VALUEÚTEST_COOKIE_NAMEr8   s    r   Úset_test_cookiezSessionBase.set_test_cookieS   s   € Ø&*×&<Ñ&<ˆˆT×"Ñ"Ò#r   c                 óR   — | j                  | j                  «      | j                  k(  S r%   )r;   rE   rD   r8   s    r   Útest_cookie_workedzSessionBase.test_cookie_workedV   s"   € Ø�x‰x˜×-Ñ-Ó.°$×2HÑ2HÑHÐHr   c                 ó   — | | j                   = y r%   )rE   r8   s    r   Údelete_test_cookiezSessionBase.delete_test_cookieY   s   € Ø�×&Ñ&Ñ'r   c                 ó\   — t        j                  || j                  | j                  d¬«      S )zGReturn the given session dictionary serialized and encoded as a string.T)Úsaltr   Úcompress)r   Údumpsr9   r   )r!   Úsession_dicts     r   ÚencodezSessionBase.encode\   s'   € ä�}‰}ØØ—‘Ø—‘Øô	
ð 	
r   c                 óò   — 	 t        j                  || j                  | j                  ¬«      S # t         j                  $ r* t        j                  d«      }|j                  d«       Y i S t        $ r Y i S w xY w)N)rL   r   z!django.security.SuspiciousSessionzSession data corrupted)	r   Úloadsr9   r   ÚBadSignatureÚloggingÚ	getLoggerÚwarningÚ	Exception)r!   Úsession_dataÚloggers      r   ÚdecodezSessionBase.decodee   sw   € ð
	Ü—=‘=Ø 4§=¡=¸T¿_¹_ôð øô ×#Ñ#ò 	5Ü×&Ñ&Ð'JÓKˆFØ�N‰NÐ3Õ4ð
 ˆ	ô	 ò 	ð Øˆ	ð		ús   ‚+. ®9A6Á*A6Á5A6c                 óH   — | j                   j                  |«       d| _        y r/   )r'   Úupdater   )r!   Údict_s     r   r\   zSessionBase.updates   s   € Ø�‰×Ñ˜UÔ#Øˆ�r   c                 ó   — || j                   v S r%   r&   r(   s     r   Úhas_keyzSessionBase.has_keyw   r+   r   c                 ó6   — | j                   j                  «       S r%   )r'   Úkeysr8   s    r   ra   zSessionBase.keysz   s   € Ø�}‰}×!Ñ!Ó#Ð#r   c                 ó6   — | j                   j                  «       S r%   )r'   Úvaluesr8   s    r   rc   zSessionBase.values}   s   € Ø�}‰}×#Ñ#Ó%Ð%r   c                 ó6   — | j                   j                  «       S r%   )r'   Úitemsr8   s    r   re   zSessionBase.items€   s   € Ø�}‰}×"Ñ"Ó$Ð$r   c                 ó.   — i | _         d| _        d| _        y r/   )Ú_session_cacher   r   r8   s    r   ÚclearzSessionBase.clearƒ   s   € ð !ˆÔØˆŒØˆ�r   c                 óZ   — 	 | j                    xr | j                   S # t        $ r Y yw xY w)zBReturn True when there is no session_key and the session is empty.T)r   rg   ÚAttributeErrorr8   s    r   Úis_emptyzSessionBase.is_empty‹   s6   € ð	Ø×(Ñ(Ð(ÒD°×1DÑ1DÐ-DÐDøÜò 	Ùð	ús   ‚ ž	*©*c                 óL   — 	 t        dt        «      }| j                  |«      s|S Œ$)z)Return session key that isn't being used.é    )r   ÚVALID_KEY_CHARSÚexistsr    s     r   Ú_get_new_session_keyz SessionBase._get_new_session_key’   s(   € àÜ+¨B´Ó@ˆKØ—;‘;˜{Ô+Ø"Ð"ð r   c                 ó\   — | j                   €| j                  «       | _         | j                   S r%   )r   rp   r8   s    r   Ú_get_or_create_session_keyz&SessionBase._get_or_create_session_key™   s+   € Ø×ÑÐ$Ø $× 9Ñ 9Ó ;ˆDÔØ× Ñ Ð r   c                 ó&   — |xr t        |«      dk\  S )z”
        Key must be truthy and at least 8 characters long. 8 characters is an
        arbitrary lower bound for some minimal key security.
        é   )Úlenr(   s     r   Ú_validate_session_keyz!SessionBase._validate_session_keyž   s   € ð
 Ò$”s˜3“x 1‘}Ð$r   c                 ó   — | j                   S r%   )Ú_SessionBase__session_keyr8   s    r   Ú_get_session_keyzSessionBase._get_session_key¥   s   € Ø×!Ñ!Ð!r   c                 óD   — | j                  |«      r|| _        yd| _        y)zV
        Validate session key on assignment. Invalid values will set to None.
        N)rv   rx   ©r!   r2   s     r   Ú_set_session_keyzSessionBase._set_session_key¨   s"   € ð ×%Ñ% eÔ,Ø!&ˆDÕà!%ˆDÕr   c                 ó´   — d| _         	 | j                  S # t        $ r9 | j                  �|ri | _        n| j	                  «       | _        Y | j                  S w xY w)zž
        Lazily load session from storage (unless "no_load" is True, when only
        an empty dict is stored) and store it in the current instance.
        T)r   rg   rj   r"   Úload)r!   Úno_loads     r   Ú_get_sessionzSessionBase._get_session´   s\   € ð
 ˆŒð	2Ø×&Ñ&Ð&øÜò 	2Ø×ÑÐ'©7Ø&(�Õ#à&*§i¡i£k�Ô#øØ×"Ñ"Ð"ð	2ús   ‰ •4AÁAc                 ó"   — t         j                  S r%   )r   ÚSESSION_COOKIE_AGEr8   s    r   Úget_session_cookie_agez"SessionBase.get_session_cookie_ageÅ   s   € Ü×*Ñ*Ð*r   c                 ó€  — 	 |d   }	 |d   }|s| j	                  «       S t        |t        t        f«      s|S t        |t        «      rt        j                  |«      }||z
  }|j                  dz  |j                  z   S # t         $ r t        j                  «       }Y Œ•w xY w# t         $ r | j                  d«      }Y Œ¯w xY w)zÕGet the number of seconds until the session expires.

        Optionally, this function accepts `modification` and `expiry` keyword
        arguments specifying the modification and expiry of the session.
        ÚmodificationÚexpiryÚ_session_expiryi€Q )ÚKeyErrorr   Únowr;   rƒ   Ú
isinstancer   ÚstrÚfromisoformatÚdaysÚseconds)r!   Úkwargsr…   r†   Údeltas        r   Úget_expiry_agezSessionBase.get_expiry_ageÈ   s¾   € ð	*Ø! .Ñ1ˆLð	1Ø˜HÑ%ˆFñ Ø×.Ñ.Ó0Ð0Ü˜&¤8¬S /Ô2ØˆMÜ�fœcÔ"Ü×+Ñ+¨FÓ3ˆFØ˜Ñ%ˆØ�z‰z˜EÑ! E§M¡MÑ1Ð1øô# ò 	*Ü#Ÿ<™<›>ŠLð	*ûô ò 	1Ø—X‘XÐ/Ó0ŠFð	1ús"   ‚A= ˆB  Á=BÂBÂ B=Â<B=c                 óT  — 	 |d   }	 |d   }t	        |t
        «      r|S t	        |t        «      rt        j                  |«      S |xs | j                  «       }|t        |¬«      z   S # t         $ r t        j                  «       }Y Œw xY w# t         $ r | j                  d«      }Y Œ™w xY w)zÔGet session the expiry date (as a datetime object).

        Optionally, this function accepts `modification` and `expiry` keyword
        arguments specifying the modification and expiry of the session.
        r…   r†   r‡   )rŽ   )
rˆ   r   r‰   r;   rŠ   r   r‹   rŒ   rƒ   r   )r!   r�   r…   r†   s       r   Úget_expiry_datezSessionBase.get_expiry_dateã   sª   € ð	*Ø! .Ñ1ˆLð	1Ø˜HÑ%ˆFô �fœhÔ'ØˆMÜ˜¤Ô$Ü×)Ñ)¨&Ó1Ð1ØÒ8˜4×6Ñ6Ó8ˆØœi°Ô7Ñ7Ð7øô ò 	*Ü#Ÿ<™<›>ŠLð	*ûô
 ò 	1Ø—X‘XÐ/Ó0ŠFð	1ús"   ‚A' ˆB
 Á'BÂBÂ
B'Â&B'c                 óÈ   — |€	 | d= yt        |t        «      rt        j                  «       |z   }t        |t
        «      r|j                  «       }|| d<   y# t         $ r Y yw xY w)a*  
        Set a custom expiration for the session. ``value`` can be an integer,
        a Python ``datetime`` or ``timedelta`` object or ``None``.

        If ``value`` is an integer, the session will expire after that many
        seconds of inactivity. If set to ``0`` then the session will expire on
        browser close.

        If ``value`` is a ``datetime`` or ``timedelta`` object, the session
        will expire at that specific future time.

        If ``value`` is ``None``, the session uses the global session expiry
        policy.
        Nr‡   )rˆ   rŠ   r   r   r‰   r   Ú	isoformatr{   s     r   Ú
set_expiryzSessionBase.set_expiryú   sn   € ð ˆ=ðØÐ*Ð+ð Ü�eœYÔ'Ü—L‘L“N UÑ*ˆEÜ�eœXÔ&Ø—O‘OÓ%ˆEØ"'ˆÐÒøô ò ØØðús   „A Á	A!Á A!c                 óR   — | j                  d«      x}€t        j                  S |dk(  S )a  
        Return ``True`` if the session is set to expire when the browser
        closes, and ``False`` if there's an expiry date. Use
        ``get_expiry_date()`` or ``get_expiry_age()`` to find the actual expiry
        date/age, if there is one.
        r‡   r   )r;   r   ÚSESSION_EXPIRE_AT_BROWSER_CLOSE)r!   r†   s     r   Úget_expire_at_browser_closez'SessionBase.get_expire_at_browser_close  s/   € ð —h‘hÐ0Ó1Ð1ˆFÐ:Ü×;Ñ;Ð;Ø˜‰{Ðr   c                 óR   — | j                  «        | j                  «        d| _        y)zc
        Remove the current session data from the database and regenerate the
        key.
        N)rh   Údeleter   r8   s    r   ÚflushzSessionBase.flush!  s   € ð
 	�
‰
ŒØ�‰ŒØ ˆÕr   c                 óŠ   — | j                   }| j                  }| j                  «        || _        |r| j	                  |«       yy)zU
        Create a new session key, while retaining the current session data.
        N)r'   r"   Úcreaterg   r›   )r!   Údatar)   s      r   Ú	cycle_keyzSessionBase.cycle_key*  s=   € ð �}‰}ˆØ×ÑˆØ�‰ŒØ"ˆÔÙØ�K‰K˜Õð r   c                 ó   — t        d«      ‚)zF
        Return True if the given session_key already exists.
        z9subclasses of SessionBase must provide an exists() method©ÚNotImplementedErrorr    s     r   ro   zSessionBase.exists7  s   € ô "ØGó
ð 	
r   c                 ó   — t        d«      ‚)zÅ
        Create a new session instance. Guaranteed to create a new object with
        a unique key and will have saved the result once (with empty data)
        before the method returns.
        z8subclasses of SessionBase must provide a create() methodr¢   r8   s    r   rž   zSessionBase.create?  s   € ô "ØFó
ð 	
r   c                 ó   — t        d«      ‚)zä
        Save the session data. If 'must_create' is True, create a new session
        object (or raise CreateError). Otherwise, only update an existing
        object and don't create one (raise UpdateError if needed).
        z6subclasses of SessionBase must provide a save() methodr¢   )r!   Úmust_creates     r   ÚsavezSessionBase.saveI  s   € ô "ØDó
ð 	
r   c                 ó   — t        d«      ‚)zx
        Delete the session data under this key. If the key is None, use the
        current session key value.
        z8subclasses of SessionBase must provide a delete() methodr¢   r    s     r   r›   zSessionBase.deleteS  s   € ô
 "ØFó
ð 	
r   c                 ó   — t        d«      ‚)z@
        Load the session data and return a dictionary.
        z6subclasses of SessionBase must provide a load() methodr¢   r8   s    r   r~   zSessionBase.load\  s   € ô "ØDó
ð 	
r   c                 ó   — t        d«      ‚)a  
        Remove expired sessions from the session store.

        If this operation isn't possible on a given backend, it should raise
        NotImplementedError. If it isn't necessary, because the backend has
        a built-in expiration mechanism, it should be a no-op.
        z.This backend does not support clear_expired().r¢   )Úclss    r   Úclear_expiredzSessionBase.clear_expiredd  s   € ô "Ð"RÓSÐSr   r%   )F)5r   r   r   r   rE   rD   Úobjectr>   r#   r*   r-   r3   r5   Úpropertyr9   r;   r?   rB   rF   rH   rJ   rP   rZ   r\   r_   ra   rc   re   rh   rk   rp   rr   rv   ry   r|   r"   r   r€   r'   rƒ   r‘   r“   r–   r™   rœ   r    ro   rž   r§   r›   r~   Úclassmethodr¬   r   r   r   r   r   !   s4  „ ñð $ÐØ Ðá“(€KóEò$ò"òòð ñHó ðHó/ð  +ó -ò
ò=òIò(ò
òòò$ò$ò&ò%òòò#ò!ò
%ò"ò&ñ Ð+Ó,€KÙÐ,Ð.>Ó?€Ló#ñ ˜Ó%€Hò+ò2ò68ò.(ò8	ò!ò	ò
ò
ó
ó
ò
ð ñTó ñTr   r   )rT   Ústringr   r   Údjango.confr   Údjango.corer   Údjango.utilsr   Údjango.utils.cryptor   Údjango.utils.module_loadingr	   Úascii_lowercaseÚdigitsrn   rW   r   r   r   r   r   r   ú<module>r¸      sY   ðÛ Û ß (å  Ý Ý !Ý 1Ý 5ð ×(Ñ(¨6¯=©=Ñ8€ô	�)ô 	ô	�)ô 	÷LTò LTr   