
    hRW                        S SK r S SKrS SKJr  S SKJr   S SKrS SKJ	r
  S SKJr  S SKJr  S SKJrJrJr  \ R$                  S    S:H  r\(       d  \rO\rS	 r " S
 S\\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\
5      r	 " S S\	5      r " S S\	5      r " S S\	5      r  " S S\	5      r! " S  S!\	5      r" " S" S#\	5      r#g! \ a    S SKr Nf = f)$    N)datetime)uuid4)SessionInterface)SessionMixin)CallbackDict)SignerBadSignature
want_bytes   c                 F    U R                   S-  S-  S-  U R                  -   $ )N<      )daysseconds)tds    kC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\flask_session/sessions.pytotal_secondsr      s#    77R<"r!BJJ..    c                   "    \ rS rSrSrSS jrSrg)ServerSideSession   z)Baseclass for server-side based sessions.Nc                 l    S n[         R                  " XU5        X l        U(       a  X0l        SU l        g )Nc                     SU l         g )NT)modifiedselfs    r   	on_update-ServerSideSession.__init__.<locals>.on_update   s	     DMr   F)r   __init__sid	permanentr   )r   initialr    r!   r   s        r   r   ServerSideSession.__init__   s+    	!dY7&Nr   )r   r!   r    )NNN)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__ r   r   r   r      s
    3r   r   c                       \ rS rSrSrg)RedisSession(   r*   Nr$   r%   r&   r'   r)   r*   r   r   r,   r,   (       r   r,   c                       \ rS rSrSrg)MemcachedSession,   r*   Nr.   r*   r   r   r1   r1   ,   r/   r   r1   c                       \ rS rSrSrg)FileSystemSession0   r*   Nr.   r*   r   r   r4   r4   0   r/   r   r4   c                       \ rS rSrSrg)MongoDBSession4   r*   Nr.   r*   r   r   r7   r7   4   r/   r   r7   c                       \ rS rSrSrg)SqlAlchemySession8   r*   Nr.   r*   r   r   r:   r:   8   r/   r   r:   c                        \ rS rSrS rS rSrg)r   r   c                 (    [        [        5       5      $ N)strr   r   s    r   _generate_sidSessionInterface._generate_sid>   s    57|r   c                 P    UR                   (       d  g [        UR                   SSS9$ )Nzflask-sessionhmac)saltkey_derivation)
secret_keyr   )r   apps     r   _get_signerSessionInterface._get_signerA   s$    ~~cnn?%+- 	-r   r*   N)r$   r%   r&   r'   r@   rH   r)   r*   r   r   r   r   <   s    -r   r   c                       \ rS rSrSrS rSrg)NullSessionInterfaceH   zAUsed to open a :class:`flask.sessions.NullSession` instance.
    c                     g r>   r*   )r   rG   requests      r   open_session!NullSessionInterface.open_sessionL   s    r   r*   N)r$   r%   r&   r'   r(   rO   r)   r*   r   r   rK   rK   H   s    r   rK   c                   6    \ rS rSrSr\r\rSS jr	S r
S rSrg)	RedisSessionInterfaceP   a`  Uses the Redis key-value store as a session backend.

.. versionadded:: 0.2
    The `use_signer` parameter was added.

:param redis: A ``redis.Redis`` instance.
:param key_prefix: A prefix that is added to all Redis store keys.
:param use_signer: Whether to sign the session id cookie or not.
:param permanent: Whether to use permanent session or not.
c                 v    Uc  SSK Jn  U" 5       nXl         X l        X0l        X@l        [        U S5      U l        g )Nr   )Redisget_cookie_samesite)redisrU   
key_prefix
use_signerr!   hasattrhas_same_site_capability)r   rW   rX   rY   r!   rU   s         r   r   RedisSessionInterface.__init___   s5    =#GE
$$"(/6K(L%r   c                 6   UR                   R                  UR                  S   5      nU(       d)  U R                  5       nU R	                  X0R
                  S9$ U R                  (       a7  U R                  U5      nUc  g  UR                  U5      nUR                  5       n[        (       d'  [        U[        5      (       d  UR                  SS5      nU R                  R                  U R                  U-   5      nUb+   U R                   R#                  U5      nU R	                  XsS9$ U R	                  X0R
                  S9$ ! [         a,    U R                  5       nU R	                  X0R
                  S9s $ f = f!   U R	                  X0R
                  S9s $ = f)NSESSION_COOKIE_NAMEr    r!   utf-8strictr    )cookiesgetconfigr@   session_classr!   rY   rH   unsigndecoder	   PY2
isinstance	text_typerW   rX   
serializerloads)r   rG   rN   r    signersid_as_bytesvaldatas           r   rO   "RedisSessionInterface.open_sessioni   sm   oo!!#**-B"CD$$&C%%#%HH??%%c*F~M%}}S1"))+
 s:c955**Wh/CjjnnT__s23?M,,S1))$)88 !!c^^!DD   M((*))c^^)LLMM))c^^)LLs    !E ?)E; 3E87E8;Fc           	         U R                  U5      nU R                  U5      nU(       da  UR                  (       aO  U R                  R	                  U R
                  UR                  -   5        UR                  UR                  S   XES9  g 0 nU R                  U5      nU R                  U5      nU R                  (       a  U R                  U5      US'   U R                  X5      n	U R                  R                  [!        U5      5      n
U R                  R#                  U R
                  UR                  -   U
[%        UR&                  5      S9  U R(                  (       a4  U R+                  U5      R-                  [/        UR                  5      5      nOUR                  nUR0                  " UR                  S   U4XXEUS.UD6  g )Nr^   domainpathsamesite)namevaluetimeexpireshttponlyru   rv   secure)get_cookie_domainget_cookie_pathr   rW   deleterX   r    delete_cookiere   get_cookie_httponlyget_cookie_securer[   rV   get_expiration_timerl   dumpsdictsetexr   permanent_session_lifetimerY   rH   signr
   
set_cookie)r   rG   sessionresponseru   rv   conditional_cookie_kwargsr}   r~   r|   rp   
session_ids               r   save_session"RedisSessionInterface.save_session   s   '',##C(

!!$//GKK"?@&&szz2G'H.4 ' A %'!++C0'',((484L4LS4Q%j1**38oo##DM2

doo;3+C,J,JK 	 	M??))#.33Jw{{4KLJ JCJJ'<=z 	9$+#)V	9 8	9r   )r[   rX   r!   rW   rY   NFT)r$   r%   r&   r'   r(   picklerl   r,   rf   r   rO   r   r)   r*   r   r   rR   rR   P   s$    	 J MME6#9r   rR   c                   B    \ rS rSrSr\r\rS
S jr	S r
S rS rS rSrg	)MemcachedSessionInterface   ah  A Session interface that uses memcached as backend.

.. versionadded:: 0.2
    The `use_signer` parameter was added.

:param client: A ``memcache.Client`` instance.
:param key_prefix: A prefix that is added to all Memcached store keys.
:param use_signer: Whether to sign the session id cookie or not.
:param permanent: Whether to use permanent session or not.
c                     Uc  U R                  5       nUc  [        S5      eXl        X l        X0l        X@l        [        U S5      U l        g )Nzno memcache module foundrV   )_get_preferred_memcache_clientRuntimeErrorclientrX   rY   r!   rZ   r[   )r   r   rX   rY   r!   s        r   r   "MemcachedSessionInterface.__init__   sJ    >88:F~"#=>>$$"(/6K(L%r   c                     S/n SS K nUR                  U5      $ ! [         a     Of = f SS KnUR                  U5      $ ! [         a     g f = f)Nz127.0.0.1:11211r   )pylibmcClientImportErrormemcache)r   serversr   r   s       r   r   8MemcachedSessionInterface._get_preferred_memcache_client   sd    $%	+ >>'**  		
	, ??7++  		s    
''A   
AAc                 T    US:  a!  U[        [        R                  " 5       5      -  nU$ )z~
Memcached deals with long (> 30 days) timeouts in a special
way. Call this function to obtain a safe value for your timeout.
i ' )intrz   )r   timeouts     r   _get_memcache_timeout/MemcachedSessionInterface._get_memcache_timeout   s(    
 W s499;''Gr   c                 d   UR                   R                  UR                  S   5      nU(       d)  U R                  5       nU R	                  X0R
                  S9$ U R                  (       a7  U R                  U5      nUc  g  UR                  U5      nUR                  5       nU R                  U-   n[        (       a&  [        U[        5      (       a  UR                  S5      nU R                   R                  U5      nUbA   [        (       d  [#        U5      nU R$                  R'                  U5      nU R	                  XS9$ U R	                  X0R
                  S9$ ! [         a,    U R                  5       nU R	                  X0R
                  S9s $ f = f!   U R	                  X0R
                  S9s $ = f)Nr^   r_   r`   rb   )rc   rd   re   r@   rf   r!   rY   rH   rg   rh   r	   rX   ri   rj   unicodeencoder   r
   rl   rm   )	r   rG   rN   r    rn   ro   full_session_keyrp   rq   s	            r   rO   &MemcachedSessionInterface.open_session   s   oo!!#**-B"CD$$&C%%#%HH??%%c*F~M%}}S1"))+
  ??S03:.88/66w?kkoo./?Ms$S/C,,S1))$)88 !!c^^!DD!   M((*))c^^)LLMM))c^^)LLs    !E  ?F 3FFF/c           	      D   U R                  U5      nU R                  U5      nU R                  UR                  -   n[        (       a&  [        U[        5      (       a  UR                  S5      nU(       dJ  UR                  (       a8  U R                  R                  U5        UR                  UR                  S   XES9  g 0 nU R                  U5      nU R                  U5      n	U R                  (       a  U R!                  U5      US'   U R#                  X5      n
[        (       d&  U R$                  R'                  [)        U5      S5      nO$U R$                  R'                  [)        U5      5      nU R                  R+                  XkU R-                  [/        UR0                  5      5      5        U R2                  (       a4  U R5                  U5      R7                  [9        UR                  5      5      nOUR                  nUR:                  " UR                  S   U4XXEU	S.UD6  g )Nr`   r^   rt   rw   r   r{   )r   r   rX   r    ri   rj   r   r   r   r   r   r   re   r   r   r[   rV   r   rl   r   r   setr   r   r   rY   rH   r   r
   r   )r   rG   r   r   ru   rv   r   r   r}   r~   r|   rp   r   s                r   r   &MemcachedSessionInterface.save_session  s   '',##C(??W[[83:.88/66w?""#34&&szz2G'H.4 ' A$&!++C0'',((484L4LS4Q%j1**38s//''Wq9C//''W6C(t/I/I%c&D&DE0G 	H??))#.33Jw{{4KLJ JCJJ'<=z 	9$+#)V	9 8	9r   )r   r[   rX   r!   rY   Nr   )r$   r%   r&   r'   r(   r   rl   r1   rf   r   r   r   rO   r   r)   r*   r   r   r   r      s.    	 J$M	M, E< 9r   r   c                   4    \ rS rSrSr\r SS jrS rS r	Sr
g)	FileSystemSessionInterfacei$  aF  Uses the :class:`cachelib.file.FileSystemCache` as a session backend.

.. versionadded:: 0.2
    The `use_signer` parameter was added.

:param cache_dir: the directory where session files are stored.
:param threshold: the maximum number of items the session stores before it
                  starts deleting some.
:param mode: the file mode wanted for the session files, default 0600
:param key_prefix: A prefix that is added to FileSystemCache store keys.
:param use_signer: Whether to sign the session id cookie or not.
:param permanent: Whether to use permanent session or not.
c                 n    SSK Jn  U" XUS9U l        X@l        XPl        X`l        [        U S5      U l        g )Nr   )FileSystemCache)	thresholdmoderV   )cachelib.filer   cacherX   rY   r!   rZ   r[   )r   	cache_dirr   r   rX   rY   r!   r   s           r   r   #FileSystemSessionInterface.__init__5  s2    1$Y$O
$$"(/6K(L%r   c                 Z   UR                   R                  UR                  S   5      nU(       d)  U R                  5       nU R	                  X0R
                  S9$ U R                  (       a7  U R                  U5      nUc  g  UR                  U5      nUR                  5       nU R                  R                  U R                  U-   5      nUb  U R	                  XcS9$ U R	                  X0R
                  S9$ ! [         a,    U R                  5       nU R	                  X0R
                  S9s $ f = f)Nr^   r_   rb   )rc   rd   re   r@   rf   r!   rY   rH   rg   rh   r	   r   rX   )r   rG   rN   r    rn   ro   rq   s          r   rO   'FileSystemSessionInterface.open_session>  s   oo!!#**-B"CD$$&C%%#%HH??%%c*F~M%}}S1"))+
 zz~~doo34%%d%44!!c^^!DD   M((*))c^^)LLMs    !C4 43D*)D*c           	      \   U R                  U5      nU R                  U5      nU(       da  UR                  (       aO  U R                  R	                  U R
                  UR                  -   5        UR                  UR                  S   XES9  g 0 nU R                  U5      nU R                  U5      nU R                  (       a  U R                  U5      US'   U R                  X5      n	[        U5      n
U R                  R                  U R
                  UR                  -   U
[!        UR"                  5      5        U R$                  (       a4  U R'                  U5      R)                  [+        UR                  5      5      nOUR                  nUR,                  " UR                  S   U4XXEUS.UD6  g )Nr^   rt   rw   r{   )r   r   r   r   r   rX   r    r   re   r   r   r[   rV   r   r   r   r   r   rY   rH   r   r
   r   )r   rG   r   r   ru   rv   r   r}   r~   r|   rq   r   s               r   r   'FileSystemSessionInterface.save_sessionS  sh   '',##C(

!!$//GKK"?@&&szz2G'H.4 ' A$&!++C0'',((484L4LS4Q%j1**38G}

t4d$S%C%CD	F??))#.33Jw{{4KLJ JCJJ'<=z 	9$+#)V	9 8	9r   )r   r[   rX   r!   rY   Nr   )r$   r%   r&   r'   r(   r4   rf   r   rO   r   r)   r*   r   r   r   r   $  s$     &M .2ME*9r   r   c                   :    \ rS rSrSr\r\r  SS jr	S r
S rSrg)	MongoDBSessionInterfaceip  a  A Session interface that uses mongodb as backend.

.. versionadded:: 0.2
    The `use_signer` parameter was added.

:param client: A ``pymongo.MongoClient`` instance.
:param db: The database you want to use.
:param collection: The collection you want to use.
:param key_prefix: A prefix that is added to all MongoDB store keys.
:param use_signer: Whether to sign the session id cookie or not.
:param permanent: Whether to use permanent session or not.
c                     Uc  SSK Jn  U" 5       nXl        X   U   U l        X@l        XPl        X`l        [        U S5      U l        g )Nr   )MongoClientrV   )	pymongor   r   storerX   rY   r!   rZ   r[   )r   r   db
collectionrX   rY   r!   r   s           r   r    MongoDBSessionInterface.__init__  sC    >+ ]FZ
+
$$"(/6K(L%r   c                    UR                   R                  UR                  S   5      nU(       d)  U R                  5       nU R	                  X0R
                  S9$ U R                  (       a7  U R                  U5      nUc  g  UR                  U5      nUR                  5       nU R                  U-   nU R                  R                  SU05      nU(       aG  UR                  S5      [        R                  " 5       ::  a  U R                  R!                  SU05        S nUb9   US   nU R"                  R%                  ['        U5      5      n	U R	                  XS9$ U R	                  X0R
                  S9$ ! [         a,    U R                  5       nU R	                  X0R
                  S9s $ f = f!   U R	                  X0R
                  S9s $ = f)Nr^   r_   id
expirationrp   rb   )rc   rd   re   r@   rf   r!   rY   rH   rg   rh   r	   rX   r   find_oner   utcnowremoverl   rm   r
   )
r   rG   rN   r    rn   ro   store_iddocumentrp   rq   s
             r   rO   $MongoDBSessionInterface.open_session  s   oo!!#**-B"CD$$&C%%#%HH??%%c*F~M%}}S1"))+
 ??S(::&&h'78\2hoo6GGJJtX./HMuo,,Z_=))$)88 !!c^^!DD#   M((*))c^^)LLMM))c^^)LLs    !E0 7F) 03F&%F&)Gc           	      N   U R                  U5      nU R                  U5      nU R                  UR                  -   nU(       dL  UR                  (       a:  U R
                  R                  SU05        UR                  UR                  S   XES9  g 0 nU R                  U5      nU R                  U5      n	U R                  (       a  U R                  U5      US'   U R                  X5      n
U R                  R                  [!        U5      5      nU R
                  R#                  SU0UUU
S.S5        U R$                  (       a4  U R'                  U5      R)                  [+        UR                  5      5      nOUR                  nUR,                  " UR                  S   U4XXEU	S.UD6  g )Nr   r^   rt   rw   )r   rp   r   Tr{   )r   r   rX   r    r   r   r   r   re   r   r   r[   rV   r   rl   r   r   updaterY   rH   r   r
   r   )r   rG   r   r   ru   rv   r   r   r}   r~   r|   rp   r   s                r   r   $MongoDBSessionInterface.save_session  s}   '',##C(??W[[0

!!4"23&&szz2G'H.4 ' A$&!++C0'',((484L4LS4Q%j1**38oo##DM2

4*!)"%)0237	9 ??))#.33Jw{{4KLJ JCJJ'<=z 	9$+#)V	9 8	9r   )r   r[   rX   r!   r   rY   Nr   )r$   r%   r&   r'   r(   r   rl   r7   rf   r   rO   r   r)   r*   r   r   r   r   p  s*     J"MFK
ME>9r   r   c                   :    \ rS rSrSr\r\r  SS jr	S r
S rSrg)	SqlAlchemySessionInterfacei  a  Uses the Flask-SQLAlchemy from a flask app as a session backend.

.. versionadded:: 0.2

:param app: A Flask app instance.
:param db: A Flask-SQLAlchemy instance.
:param table: The table name you want to use.
:param key_prefix: A prefix that is added to all store keys.
:param use_signer: Whether to sign the session id cookie or not.
:param permanent: Whether to use permanent session or not.
c                    ^ ^ Uc  SSK Jn  U" U5      nUT l        UT l        UT l        UT l        [        T S5      T l         " U U4S jST R                  R                  5      nUT l	        g )Nr   )
SQLAlchemyrV   c                     > \ rS rSr Yr Y R
                  R                   Y R
                  R                  SS9r Y R
                  R                   Y R
                  R                  S5      SS9r
 Y R
                  R                   Y R
                  R                  5      r Y R
                  R                   Y R
                  R                  5      rS rS rSrg	)
4SqlAlchemySessionInterface.__init__.<locals>.Sessioni  T)primary_key   )uniquec                 (    Xl         X l        X0l        g r>   )r   rq   expiry)r   r   rq   r   s       r   r   =SqlAlchemySessionInterface.__init__.<locals>.Session.__init__  s    ", 	$r   c                      SU R                   -  $ )Nz<Session data %s>)rq   r   s    r   __repr__=SqlAlchemySessionInterface.__init__.<locals>.Session.__repr__  s    *TYY66r   )rq   r   r   N)r$   r%   r&   r'   __tablename__r   ColumnIntegerr   Stringr   LargeBinaryrq   DateTimer   r   r   r)   )r   tables   r   Sessionr     s    !MTBBs(;DIJ77>>$''"5"56DWW^^DGG$4$45F%
7r   r   )
flask_sqlalchemyr   r   rX   rY   r!   rZ   r[   Modelsql_session_model)	r   rG   r   r   rX   rY   r!   r   r   s	   `  `     r   r   #SqlAlchemySessionInterface.__init__  sc    :3CB$$"(/6K(L%	7 	7dggmm 	7" ")r   c                    UR                   R                  UR                  S   5      nU(       d)  U R                  5       nU R	                  X0R
                  S9$ U R                  (       a7  U R                  U5      nUc  g  UR                  U5      nUR                  5       nU R                  U-   nU R                  R                  R                  US9R                  5       nU(       an  UR                   ["        R$                  " 5       ::  aK  U R&                  R(                  R+                  U5        U R&                  R(                  R-                  5         S nU(       a@   UR.                  nU R0                  R3                  [5        U5      5      n	U R	                  XS9$ U R	                  X0R
                  S9$ ! [         a,    U R                  5       nU R	                  X0R
                  S9s $ f = f!   U R	                  X0R
                  S9s $ = f)Nr^   r_   r   rb   )rc   rd   re   r@   rf   r!   rY   rH   rg   rh   r	   rX   r   query	filter_byfirstr   r   r   r   r   r   commitrq   rl   rm   r
   )
r   rG   rN   r    rn   ro   r   saved_sessionrp   rq   s
             r   rO   'SqlAlchemySessionInterface.open_session  s   oo!!#**-B"CD$$&C%%#%HH??%%c*F~M%}}S1"))+
 ??S(..44>> ? !!& 	]11X__5FFGGOO""=1GGOO""$ MM#((,,Z_=))$)88 !!c^^!DD'   M((*))c^^)LLM"M))c^^)LLs    !F6 >G/ 63G,+G,/Hc           	         U R                  U5      nU R                  U5      nU R                  UR                  -   nU R                  R
                  R                  US9R                  5       nU(       d  UR                  (       am  U(       aI  U R                  R                  R                  U5        U R                  R                  R                  5         UR                  UR                  S   XES9  g 0 nU R                  U5      n	U R!                  U5      n
U R"                  (       a  U R%                  U5      US'   U R'                  X5      nU R(                  R+                  [-        U5      5      nU(       a1  Xl        Xl        U R                  R                  R                  5         O[U R	                  XlU5      nU R                  R                  R3                  U5        U R                  R                  R                  5         U R4                  (       a4  U R7                  U5      R9                  [;        UR                  5      5      nOUR                  nUR<                  " UR                  S   U4XXEU
S.UD6  g )Nr   r^   rt   rw   r{   )r   r   rX   r    r   r   r   r   r   r   r   r   r   r   re   r   r   r[   rV   r   rl   r   r   rq   r   addrY   rH   r   r
   r   )r   rG   r   r   ru   rv   r   r   r   r}   r~   r|   rp   new_sessionr   s                  r   r   'SqlAlchemySessionInterface.save_session  s   '',##C(??W[[0..44>> ? !!& 	 GGOO**=9GGOO**,&&szz2G'H.4 ' A$&!++C0'',((484L4LS4Q%j1**38oo##DM2!$#* GGOO""$00HKGGOO,GGOO""$??))#.33Jw{{4KLJ JCJJ'<=z 	9$+#)V	9 8	9r   )r   r[   rX   r!   r   rY   Nr   )r$   r%   r&   r'   r(   r   rl   r:   rf   r   rO   r   r)   r*   r   r   r   r     s*    
 J%M>C)<EB%9r   r   )$sysrz   r   uuidr   cPickler   r   flask.sessionsr   FlaskSessionInterfacer   werkzeug.datastructuresr   itsdangerousr   r	   r
   version_infori   r?   rk   r   r   r   r,   r1   r4   r7   r:   rK   rR   r   r   r   r   r*   r   r   <module>r     s!   
    E ' 0 9 9 
qQ
II/
l 
	$ 		( 		) 		& 		) 		-, 	-+ W9, W9tw9 0 w9tI9!1 I9XY9. Y9xt9!1 t9K  s   C( (
C54C5