
    Evg>B                         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 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dS )    N)datetime	timedelta)sync_to_async)settings)signing)timezone)get_random_string)import_stringc                       e Zd ZdZdS )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__     b/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/sessions/backends/base.pyr   r      s         
 	Dr   r   c                       e Zd ZdZdS )UpdateErrorzF
    Occurs if Django tries to update a session that was deleted.
    Nr   r   r   r   r   r      s          	Dr   r   c                   N   e Zd ZdZdZdZ e            ZdIdZd Z	d Z
d Zd	 Zd
 Zed             ZdIdZdIdZef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%d" Z&d# Z'd$ Z(d% Z)d& Z*d' Z+d( Z,d) Z-d* Z.d+ Z/d, Z0 ee/          Z1 ee/e0          Z2dJd.Z3dJd/Z4 ee3          Z5d0 Z6d1 Z7d2 Z8d3 Z9d4 Z:d5 Z;d6 Z<d7 Z=d8 Z>d9 Z?d: Z@d; ZAd< ZBd= ZCd> ZDd? ZEd@ ZFdJdAZGdJdBZHdIdCZIdIdDZJdE ZKdF ZLeMdG             ZNeMdH             ZOdS )KSessionBasez-
    Base class for all Session classes.
    
testcookieworkedNc                 l    || _         d| _        d| _        t          t          j                  | _        d S )NF)_session_keyaccessedmodifiedr
   r   SESSION_SERIALIZER
serializerselfsession_keys     r   __init__zSessionBase.__init__-   s.    ''(CDDr   c                     || j         v S N_sessionr"   keys     r   __contains__zSessionBase.__contains__3       dm##r   c                     | j         |         S r&   r'   r)   s     r   __getitem__zSessionBase.__getitem__6   s    }S!!r   c                 (    || j         |<   d| _        d S NTr(   r   r"   r*   values      r   __setitem__zSessionBase.__setitem__9   s    "cr   c                 R   K   ||                                   d {V |<   d| _        d S r0   )_aget_sessionr   r2   s      r   asetzSessionBase.aset=   s9      ,1t!!##	#	#	#	#	#	#S)r   c                 $    | j         |= d| _        d S r0   r1   r)   s     r   __delitem__zSessionBase.__delitem__A   s    M#r   c                      d| j         j        z   S )Nzdjango.contrib.sessions.)	__class__r   r"   s    r   key_saltzSessionBase.key_saltE   s    )DN,GGGr   c                 8    | j                             ||          S r&   )r(   getr"   r*   defaults      r   r?   zSessionBase.getI   s    }  g...r   c                 b   K   |                                   d {V                     ||          S r&   )r6   r?   r@   s      r   agetzSessionBase.agetL   s:      ((********//W===r   c                 n    | j         p|| j        v | _         || j        u rdn|f} | j        j        |g|R  S Nr   )r   r(   _SessionBase__not_givenpopr"   r*   rA   argss       r   rG   zSessionBase.popO   sL    =)= 000rrwj t} ,t,,,,r   c                    K   | j         p||                                  d {V v | _         || j        u rdn|f} |                                  d {V j        |g|R  S rE   )r   r6   rF   rG   rH   s       r   apopzSessionBase.apopT   s      Lt7I7I7K7K1K1K1K1K1K1K)L 000rrwj/d((********/;d;;;;r   c                 <    || j         v r| j         |         S || |<   |S r&   r'   r2   s      r   
setdefaultzSessionBase.setdefaultY   s*    $-=%%DILr   c                    K   |                                   d {V }||v r||         S |                     ||           d {V  |S r&   )r6   r7   )r"   r*   r3   sessions       r   asetdefaultzSessionBase.asetdefault`   sg      **,,,,,,,,'>>3<))C'''''''''Lr   c                 $    | j         | | j        <   d S r&   )TEST_COOKIE_VALUETEST_COOKIE_NAMEr<   s    r   set_test_cookiezSessionBase.set_test_cookieh   s    &*&<T"###r   c                 V   K   |                      | j        | j                   d {V  d S r&   )r7   rS   rR   r<   s    r   aset_test_cookiezSessionBase.aset_test_cookiek   s8      ii-t/EFFFFFFFFFFFr   c                 H    |                      | j                  | j        k    S r&   )r?   rS   rR   r<   s    r   test_cookie_workedzSessionBase.test_cookie_workedn   s    xx-..$2HHHr   c                 X   K   |                      | j                   d {V | j        k    S r&   )rC   rS   rR   r<   s    r   atest_cookie_workedzSessionBase.atest_cookie_workedq   s5      ii 5666666664;QQQr   c                     | | j         = d S r&   )rS   r<   s    r   delete_test_cookiezSessionBase.delete_test_cookiet   s    &'''r   c                 J   K   |                                   d {V | j        = d S r&   )r6   rS   r<   s    r   adelete_test_cookiezSessionBase.adelete_test_cookiew   s5      %%'''''''')>???r   c                 F    t          j        || j        | j        d          S )zGReturn the given session dictionary serialized and encoded as a string.T)saltr    compress)r   dumpsr=   r    )r"   session_dicts     r   encodezSessionBase.encodez   s+    }	
 
 
 	
r   c                     	 t          j        || j        | j                  S # t           j        $ r, t          j        d          }|                    d           Y nt          $ r Y nw xY wi S )N)r`   r    z!django.security.SuspiciousSessionzSession data corrupted)	r   loadsr=   r    BadSignaturelogging	getLoggerwarning	Exception)r"   session_dataloggers      r   decodezSessionBase.decode   s    
	=4=T_    # 	5 	5 	5&'JKKFNN344444 	 	 	 D	 	s    # 8A)	A)(A)c                 H    | j                             |           d| _        d S r0   )r(   updater   r"   dict_s     r   rp   zSessionBase.update   s#    U###r   c                 r   K   |                                   d {V                     |           d| _        d S r0   )r6   rp   r   rq   s     r   aupdatezSessionBase.aupdate   sC      !!##	#	#	#	#	#	#++E222r   c                     || j         v S r&   r'   r)   s     r   has_keyzSessionBase.has_key   r,   r   c                 >   K   ||                                   d {V v S r&   )r6   r)   s     r   ahas_keyzSessionBase.ahas_key   s/      T//1111111122r   c                 4    | j                                         S r&   )r(   keysr<   s    r   rz   zSessionBase.keys   s    }!!###r   c                 ^   K   |                                   d {V                                 S r&   )r6   rz   r<   s    r   akeyszSessionBase.akeys   s6      ((********00222r   c                 4    | j                                         S r&   )r(   valuesr<   s    r   r~   zSessionBase.values   s    }##%%%r   c                 ^   K   |                                   d {V                                 S r&   )r6   r~   r<   s    r   avalueszSessionBase.avalues   s6      ((********22444r   c                 4    | j                                         S r&   )r(   itemsr<   s    r   r   zSessionBase.items   s    }""$$$r   c                 ^   K   |                                   d {V                                 S r&   )r6   r   r<   s    r   aitemszSessionBase.aitems   s6      ((********11333r   c                 0    i | _         d| _        d| _        d S r0   )_session_cacher   r   r<   s    r   clearzSessionBase.clear   s     !r   c                 F    	 | j          o| j         S # t          $ r Y dS w xY w)zBReturn True when there is no session_key and the session is empty.T)r   r   AttributeErrorr<   s    r   is_emptyzSessionBase.is_empty   s@    	((D1D-DD 	 	 	44	s    
  c                 ^    	 t          dt                    }|                     |          s|S -)z)Return session key that isn't being used.T    )r	   VALID_KEY_CHARSexistsr!   s     r   _get_new_session_keyz SessionBase._get_new_session_key   s5    	#+B@@K;;{++ #""	#r   c                 n   K   	 t          dt                    }|                     |           d {V s|S 3)NTr   )r	   r   aexistsr!   s     r   _aget_new_session_keyz!SessionBase._aget_new_session_key   sK      	#+B@@Kk22222222 #""	#r   c                 P    | j         |                                 | _         | j         S r&   )r   r   r<   s    r   _get_or_create_session_keyz&SessionBase._get_or_create_session_key   s(    $ $ 9 9 ; ;D  r   c                 `   K   | j         |                                  d {V | _         | j         S r&   )r   r   r<   s    r   _aget_or_create_session_keyz'SessionBase._aget_or_create_session_key   s>      $&*&@&@&B&B B B B B B BD  r   c                 ,    |o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    
 $s3xx1}$r   c                     | j         S r&   )_SessionBase__session_keyr<   s    r   _get_session_keyzSessionBase._get_session_key   s    !!r   c                 P    |                      |          r	|| _        dS d| _        dS )zV
        Validate session key on assignment. Invalid values will set to None.
        N)r   r   r"   r3   s     r   _set_session_keyzSessionBase._set_session_key   s6     %%e,, 	&!&D!%Dr   Fc                     d| _         	 | j        S # t          $ r- | j        |ri | _        n|                                 | _        Y nw xY w| j        S )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   r   r   r#   loadr"   no_loads     r   _get_sessionzSessionBase._get_session   sj    
 	2&& 	2 	2 	2'7'&(##&*iikk#		2
 ""s    4AAc                    K   d| _         	 | j        S # t          $ r3 | j        |ri | _        n|                                  d {V | _        Y nw xY w| j        S r0   )r   r   r   r#   aloadr   s     r   r6   zSessionBase._aget_session   s~      	9&& 	9 	9 	9'7'&(##,0JJLL&8&8&8&8&8&8#		9
 ""s    :AAc                     t           j        S r&   )r   SESSION_COOKIE_AGEr<   s    r   get_session_cookie_agez"SessionBase.get_session_cookie_age	  s    **r   c                    	 |d         }n## t           $ r t          j                    }Y nw xY w	 |d         }n%# t           $ r |                     d          }Y nw xY w|s|                                 S t          |t          t          f          s|S t          |t                    rt          j        |          }||z
  }|j	        dz  |j
        z   S )zGet 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_expiryQ )KeyErrorr   nowr?   r   
isinstancer   strfromisoformatdayssecondsr"   kwargsr   r   deltas        r   get_expiry_agezSessionBase.get_expiry_age  s    	*!.1LL 	* 	* 	*#<>>LLL	*
	1H%FF 	1 	1 	1XX/00FFF	1  	1..000&8S/22 	Mfc"" 	4+F33F%zE!EM11    ++8 AAc                   K   	 |d         }n## t           $ r t          j                    }Y nw xY w	 |d         }n+# t           $ r |                     d           d {V }Y nw xY w|s|                                 S t          |t          t          f          s|S t          |t                    rt          j        |          }||z
  }|j	        dz  |j
        z   S )Nr   r   r   r   )r   r   r   rC   r   r   r   r   r   r   r   r   s        r   aget_expiry_agezSessionBase.aget_expiry_age'  s     	*!.1LL 	* 	* 	*#<>>LLL	*	8H%FF 	8 	8 	899%677777777FFF	8  	1..000&8S/22 	Mfc"" 	4+F33F%zE!EM11    --: %A"!A"c                    	 |d         }n## t           $ r t          j                    }Y nw xY w	 |d         }n%# t           $ r |                     d          }Y nw xY wt	          |t
                    r|S t	          |t                    rt          j        |          S |p|                                 }|t          |          z   S )zGet 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    	*!.1LL 	* 	* 	*#<>>LLL	*	1H%FF 	1 	1 	1XX/00FFF	1 fh'' 	2M$$ 	2)&111846688i77777r   c                   K   	 |d         }n## t           $ r t          j                    }Y nw xY w	 |d         }n+# t           $ r |                     d           d {V }Y nw xY wt	          |t
                    r|S t	          |t                    rt          j        |          S |p|                                 }|t          |          z   S )Nr   r   r   r   )
r   r   r   rC   r   r   r   r   r   r   r   s       r   aget_expiry_datezSessionBase.aget_expiry_dateQ  s      	*!.1LL 	* 	* 	*#<>>LLL	*	8H%FF 	8 	8 	899%677777777FFF	8 fh'' 	2M$$ 	2)&111846688i77777r   c                     |	 | d= n# t           $ r Y nw xY wdS t          |t                    rt          j                    |z   }t          |t
                    r|                                }|| d<   dS )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_expiryb  s     =*++   FeY'' 	+LNNU*EeX&& 	&OO%%E"'s    
c                 L  K   |/	 |                      d           d {V  n# t          $ r Y nw xY wd S t          |t                    rt	          j                    |z   }t          |t                    r|                                }|                     d|           d {V  d S )Nr   )	rK   r   r   r   r   r   r   r   r7   r   s     r   aset_expiryzSessionBase.aset_expiry~  s      =ii 12222222222   FeY'' 	+LNNU*EeX&& 	&OO%%Eii)511111111111s   " 
//c                 T    |                      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   Nr   )r?   r   SESSION_EXPIRE_AT_BROWSER_CLOSEr"   r   s     r   get_expire_at_browser_closez'SessionBase.get_expire_at_browser_close  s/     hh0111F:;;{r   c                 d   K   |                      d           d {V x}t          j        S |dk    S )Nr   r   )rC   r   r   r   s     r   aget_expire_at_browser_closez(SessionBase.aget_expire_at_browser_close  sC       II&7888888888FA;;{r   c                 d    |                                   |                                  d| _        dS )zc
        Remove the current session data from the database and regenerate the
        key.
        N)r   deleter   r<   s    r   flushzSessionBase.flush  s,    
 	

 r   c                 t   K   |                                   |                                  d {V  d | _        d S r&   )r   adeleter   r<   s    r   aflushzSessionBase.aflush  sA      

llnn r   c                     | j         }| j        }|                                  || _        |r|                     |           dS dS zU
        Create a new session key, while retaining the current session data.
        N)r(   r#   creater   r   r"   datar*   s      r   	cycle_keyzSessionBase.cycle_key  sR     }" 	KK	 	r   c                    K   |                                   d{V }| j        }|                                  d{V  || _        |r|                     |           d{V  dS dS r   )r6   r#   acreater   r   r   s      r   
acycle_keyzSessionBase.acycle_key  s       ''))))))))llnn" 	$,,s###########	$ 	$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   r   zSessionBase.exists  s     "G
 
 	
r   c                 L   K    t          | j                  |           d {V S r&   )r   r   r!   s     r   r   zSessionBase.aexists  2      /]4;//<<<<<<<<<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   r<   s    r   r   zSessionBase.create  s     "F
 
 	
r   c                 J   K    t          | j                               d {V S r&   )r   r   r<   s    r   r   zSessionBase.acreate  s0      /]4;//111111111r   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.save  s     "D
 
 	
r   c                 L   K    t          | j                  |           d {V S r&   )r   r   r   s     r   asavezSessionBase.asave  s2      -]49--k:::::::::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.delete  s    
 "F
 
 	
r   c                 L   K    t          | j                  |           d {V S r&   )r   r   r!   s     r   r   zSessionBase.adelete  r   r   c                      t          d          )z@
        Load the session data and return a dictionary.
        z6subclasses of SessionBase must provide a load() methodr   r<   s    r   r   zSessionBase.load  s     "D
 
 	
r   c                 J   K    t          | j                               d {V S r&   )r   r   r<   s    r   r   zSessionBase.aload  s0      -]49--/////////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_expired  s     ""RSSSr   c                 J   K    t          | j                               d {V S r&   )r   r   r   s    r   aclear_expiredzSessionBase.aclear_expired	  s1      5]3#455777777777r   r&   )F)Pr   r   r   r   rS   rR   objectrF   r$   r+   r.   r4   r7   r9   propertyr=   r?   rC   rG   rK   rM   rP   rT   rV   rX   rZ   r\   r^   rd   rn   rp   rt   rv   rx   rz   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r#   r   r   r6   r(   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   #   s         $ &((KE E E E$ $ $" " "       H H XH/ / / /> > > >  + - - - -
 '2 < < < <
    = = =G G GI I IR R R( ( (@ @ @
 
 
      $ $ $3 3 3$ $ $3 3 3& & &5 5 5% % %4 4 4    # # ## # #! ! !
! ! !
% % %" " "& & & (+,,K8,.>??L# # # #	# 	# 	# 	# x%%H+ + +2 2 262 2 2&8 8 8.8 8 8"( ( (82 2 2	 	 	  
! ! !! ! !
	 	 		$ 	$ 	$
 
 
= = =
 
 
2 2 2
 
 
 
; ; ; ;
 
 
 
= = = =
 
 
0 0 0 T T [T 8 8 [8 8 8r   r   )rh   stringr   r   asgiref.syncr   django.confr   django.corer   django.utilsr   django.utils.cryptor	   django.utils.module_loadingr
   ascii_lowercasedigitsr   rk   r   r   r   r   r   r   <module>r     s<     ( ( ( ( ( ( ( ( & & & & & &                   ! ! ! ! ! ! 1 1 1 1 1 1 5 5 5 5 5 5 (6=8	 	 	 	 	) 	 	 		 	 	 	 	) 	 	 	h8 h8 h8 h8 h8 h8 h8 h8 h8 h8r   