
    h!                     
   S SK r S SKrS SKJr  S SKJrJr  S SKJr  S SK	J
r
  S SKJrJr   " S S\R                  5      r " S	 S
\R                   5      r " S S5      r " S S5      r " S S5      r " S S\5      rS rS rg)    N)settings)BaseStorageMessage)signing)SimpleCookie)SafeData	mark_safec                   0   ^  \ rS rSrSrSrU 4S jrSrU =r$ )MessageEncoder   zA
Compactly serialize instances of the ``Message`` class as JSON.
__json_messagec                 ,  > [        U[        5      (       ap  [        UR                  [        5      (       a  SOSnU R                  X!R
                  UR                  /nUR                  b  UR                  UR                  5        U$ [        TU ]%  U5      $ )N   r   )

isinstancer   messager   message_keylevel
extra_tagsappendsuperdefault)selfobjis_safedatar   	__class__s       X/var/www/html/env/lib/python3.13/site-packages/django/contrib/messages/storage/cookie.pyr   MessageEncoder.default   so    c7##)#++x@@!aK''iiMG~~)s~~.Nws##     )	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classcell__r   s   @r   r   r      s     #K$ $r   r   c                   2   ^  \ rS rSrSrS rU 4S jrSrU =r$ )MessageDecoder   z=
Decode JSON that includes serialized ``Message`` instances.
c                    [        U[        5      (       ae  U(       a^  US   [        R                  :X  a&  US   (       a  [	        US   5      US'   [        USS  6 $ U Vs/ s H  o R                  U5      PM     sn$ [        U[        5      (       a4  UR                  5        VVs0 s H  u  p4X0R                  U5      _M     snn$ U$ s  snf s  snnf )Nr   r         )	r   listr   r   r	   r   process_messagesdictitems)r   r   itemkeyvalues        r   r/   MessageDecoder.process_messages"   s    c4  S1v333q6&s1v.CFAB((<?@CD))$/C@@c4  HK		T*#C..u55TT
 ATs   C#Cc                 H   > [         TU ]  " U40 UD6nU R                  U5      $ N)r   decoder/   )r   skwargsdecodedr   s       r   r8   MessageDecoder.decode-   s'    '.-f-$$W--r   r   )	r    r!   r"   r#   r$   r/   r8   r%   r&   r'   s   @r   r)   r)      s    	. .r   r)   c                       \ rS rSrS rSrg)MessagePartSerializer2   c           	      b    U Vs/ s H  n[         R                  " US[        S9PM     sn$ s  snf )N),:)
separatorscls)jsondumpsr   )r   r   os      r   rF   MessagePartSerializer.dumps3   s?     
  JJ%"
 
 	
 
s   $,r   Nr    r!   r"   r#   rF   r%   r   r   r   r>   r>   2   s    
r   r>   c                       \ rS rSrS rSrg)MessagePartGatherSerializer>   c                 N    SSR                  U5      -   S-   R                  S5      $ )z
The parameter is an already serialized list of Message objects. No need
to serialize it again, only join the list together and encode it.
[rA   ]latin-1)joinencode)r   r   s     r   rF   !MessagePartGatherSerializer.dumps?   s'    
 chhsm#c)11)<<r   r   NrI   r   r   r   rK   rK   >   s    =r   rK   c                       \ rS rSrS rSrg)MessageSerializerG   c                 R    [         R                  " UR                  S5      [        S9$ )NrP   )rD   )rE   loadsr8   r)   r   datas     r   rX   MessageSerializer.loadsH   s    zz$++i0nEEr   r   N)r    r!   r"   r#   rX   r%   r   r   r   rU   rU   G   s    Fr   rU   c                      ^  \ rS rSrSrSrSrSr\R                  " S5      r
SrU 4S jrS rS	 rSS
 jrSS jrSS jrS rSrU =r$ )CookieStorageL   z
Store messages in a cookie.
messagesi   __messagesnotfinished__zdjango.contrib.messagesc                 l   > [         TU ]  " U0 UD6  [        R                  " U R                  S9U l        g )N)salt)r   __init__r   get_cookie_signerkey_saltsigner)r   argsr:   r   s      r   rc   CookieStorage.__init__Z   s+    $)&)//T]]Cr   c                    U R                   R                  R                  U R                  5      nU R	                  U5      nU=(       a    US   U R
                  :H  (       + nU(       a  U(       d  UR                  5         XE4$ )z
Retrieve a list of messages from the messages cookie. If the
not_finished sentinel value is found at the end of the message list,
remove it and return a result indicating that not all messages were
retrieved by this storage.
)requestCOOKIESgetcookie_name_decodenot_finishedpop)r   rg   r:   rZ   r_   all_retrieveds         r   _getCookieStorage._get^   se     ||##''(8(89<<%%K(2,$:K:K*KLMLLN&&r   c           	      R   U(       ai  UR                  U R                  U[        R                  [        R                  =(       d    S[        R
                  =(       d    S[        R                  S9  gUR                  U R                  [        R                  [        R                  S9  g)zb
Either set the cookie with the encoded data if there is any data to
store, or delete the cookie.
N)domainsecurehttponlysamesite)rv   ry   )
set_cookiern   r   SESSION_COOKIE_DOMAINSESSION_COOKIE_SECURESESSION_COOKIE_HTTPONLYSESSION_COOKIE_SAMESITEdelete_cookie)r   encoded_dataresponses      r   _update_cookieCookieStorage._update_cookiem   s    
   5555=!99AT!99    ""  55!99 # r   c                 z  ^ ^
^^ / n[        5       R                  U5      nT R                  U5      nT R                  (       ah  [	        5       mUU 4S jmU 4S jm
T" U5      (       aD  U(       a  [        UU
U4S jS9n	USU	 nT
" XyS 5      nO[        UU
U4S jS9n	XS nT
" USU	 5      nT R                  X5        U$ )a$  
Store the messages to a cookie and return a list of any messages which
could not be stored.

If the encoded data is larger than ``max_cookie_size``, remove
messages until the data fits (these are the messages which are
returned), and add the not_finished sentinel value to indicate as much.
c                 j   > U =(       a*    [        TR                  U 5      S   5      TR                  :  $ )Nr   )lenvalue_encodemax_cookie_size)rZ   cookier   s    r   is_too_large_for_cookie5CookieStorage._store.<locals>.is_too_large_for_cookie   s.    XF$7$7$=a$@ ADDXDX XXr   c                 @   > TR                  U TR                  /-   SS9$ )NTencode_empty)_encode_partsnot_finished_json)some_serialized_msgr   s    r   compute_msg)CookieStorage._store.<locals>.compute_msg   s/    ))'4+A+A*BB!% *  r   c                     > T" T" U 5      5      $ r7   r   mr   r   s    r   <lambda>&CookieStorage._store.<locals>.<lambda>       %<[^%Lr   )fnNc                     > T" T" U 5      5      $ r7   r   r   s    r   r   r      r   r   )r>   rF   r   r   r   bisect_keep_rightbisect_keep_leftr   )r   r_   r   remove_oldestrg   r:   unstored_messagesserialized_messagesr   idxr   r   r   s   `         @@@r   _storeCookieStorage._store   s     35;;HE))*=> "^FY '|44 ++LC )1#%#./B4/H#IL*+LC )1%#./B4C/H#ILL3  r   c                 ^    U(       d  U(       a  U R                   R                  U[        SS9$ g)z
Return an encoded version of the serialized messages list which can be
stored as plain text.

Since the data will be retrieved from the client-side, the encoded data
also contains a hash to ensure that the data was not tampered with.
T)
serializercompressN)rf   sign_objectrK   )r   r_   r   s      r   r   CookieStorage._encode_parts   s2     |;;**%@4 +   $r   c                 R    [        5       R                  U5      nU R                  X2S9$ )z
Return an encoded version of the messages list which can be stored as
plain text.

Proxies MessagePartSerializer.dumps and _encoded_parts.
r   )r>   rF   r   )r   r_   r   r   s       r   _encodeCookieStorage._encode   s-     45;;HE!!"5!QQr   c                     U(       d  g U R                   R                  U[        S9$ ! [        R                  [
        R                  [        R                  4 a     Of = fSU l	        g)z
Safely decode an encoded text stream back into a list of messages.

If the encoded text stream contained an invalid hash or was in an
invalid format, return None.
N)r   T)
rf   unsign_objectrU   r   BadSignaturebinasciiErrorrE   JSONDecodeErrorusedrY   s     r   ro   CookieStorage._decode   s_     	;;,,T>O,PP$$hnnd6J6JK 		 	s   ( 3AA)rf   r   )T)F)r    r!   r"   r#   r$   rn   r   rp   rE   rF   r   re   rc   rs   r   r   r   r   ro   r%   r&   r'   s   @r   r]   r]   L   s[     K O,L

#<=(HD'*+!ZR r   r]   c                 |    Sn[        U 5      nX#:  a)  X#-   S-  nU" U SUS-    5      (       a  UnOUS-   nX#:  a  M)  U$ )z
Find the index of the first element from the start of the array that
verifies the given condition.
The function is applied from the start of the array to the pivot.
r   r-   Nr   r   ar   lohimids        r   r   r      sS     
B	QB
'w1na	#'lBqB ' Ir   c                 t    Sn[        U 5      nX#:  a%  X#-   S-  nU" XS 5      (       a  US-   nOUnX#:  a  M%  U$ )z
Find the index of the first element from the end of the array that verifies
the given condition.
The function is applied from the pivot to the end of array.
r   r-   Nr   r   r   s        r   r   r      sK     
B	QB
'w1nag;;qBB ' Ir   )r   rE   django.confr   $django.contrib.messages.storage.baser   r   django.corer   django.httpr   django.utils.safestringr   r	   JSONEncoderr   JSONDecoderr)   r>   rK   rU   r]   r   r   r   r   r   <module>r      sw        E  $ 7$T%% $$.T%% .*	
 	
= =F F
JK JZ"r   