o
    ÕèFhÂ  ã                   @   sR   d dl mZ d dlmZmZ d dlmZ eejƒZG dd„ dƒZ	G dd„ dƒZ
dS )	é    )Úsettings)Ú	constantsÚutils)ÚSimpleLazyObjectc                   @   sR   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Ze	dd„ ƒZ
e	dd„ ƒZdS )ÚMessagez±
    Represent an actual message that can be stored in any of the supported
    storage classes (typically session- or cookie-based) and rendered in a view
    or template.
    Nc                 C   s   t |ƒ| _|| _|| _d S ©N)ÚintÚlevelÚmessageÚ
extra_tags©Úselfr	   r
   r   © r   ú]/var/www/html/loop/nvenv/lib/python3.10/site-packages/django/contrib/messages/storage/base.pyÚ__init__   s   

zMessage.__init__c                 C   s0   t | jƒ| _| jdurt | jƒ| _dS d| _dS )z˜
        Prepare the message for serialization by forcing the ``message``
        and ``extra_tags`` to str in case they are lazy translations.
        N)Ústrr
   r   ©r   r   r   r   Ú_prepare   s   $zMessage._preparec                 C   s&   t |tƒstS | j|jko| j|jkS r   )Ú
isinstancer   ÚNotImplementedr	   r
   )r   Úotherr   r   r   Ú__eq__   s   
zMessage.__eq__c                 C   s
   t | jƒS r   )r   r
   r   r   r   r   Ú__str__!   s   
zMessage.__str__c                 C   s0   | j r	d| j ›�nd}d| j› d| j›|› d�S )Nz, extra_tags=Ú zMessage(level=z
, message=ú))r   r	   r
   )r   r   r   r   r   Ú__repr__$   s   zMessage.__repr__c                 C   s   d  dd„ | j| jfD ƒ¡S )Nú c                 s   s   � | ]}|r|V  qd S r   r   )Ú.0Útagr   r   r   Ú	<genexpr>*   s   € zMessage.tags.<locals>.<genexpr>)Újoinr   Ú	level_tagr   r   r   r   Útags(   s   zMessage.tagsc                 C   s   t  | jd¡S )Nr   )Ú
LEVEL_TAGSÚgetr	   r   r   r   r   r!   ,   s   zMessage.level_tagr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   Úpropertyr"   r!   r   r   r   r   r      s    

r   c                       s”   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Ze	dd„ ƒZ
dd„ Zdd„ Zdd„ Zdd„ Zddd„Zdd„ Zddd„Ze	eeeƒZ‡  ZS ) ÚBaseStoragezÖ
    This is the base backend for temporary message storage.

    This is not a complete class; to be a usable storage backend, it must be
    subclassed and the two methods ``_get`` and ``_store`` overridden.
    c                    s.   || _ g | _d| _d| _tƒ j|i |¤Ž d S )NF)ÚrequestÚ_queued_messagesÚusedÚ	added_newÚsuperr   )r   r+   ÚargsÚkwargs©Ú	__class__r   r   r   9   s
   zBaseStorage.__init__c                 C   s   t | jƒt | jƒ S r   )ÚlenÚ_loaded_messagesr,   r   r   r   r   Ú__len__@   ó   zBaseStorage.__len__c                 C   s*   d| _ | jr| j | j¡ g | _t| jƒS )NT)r-   r,   r5   ÚextendÚiterr   r   r   r   Ú__iter__C   s
   
zBaseStorage.__iter__c                 C   s   || j v p	|| jv S r   )r5   r,   )r   Úitemr   r   r   Ú__contains__J   r7   zBaseStorage.__contains__c                 C   s   d| j j› d| j›d�S )Nú<z
: request=ú>)r3   r'   r+   r   r   r   r   r   M   s   zBaseStorage.__repr__c                 C   s&   t | dƒs|  ¡ \}}|pg | _| jS )zs
        Return a list of loaded messages, retrieving them first if they have
        not been loaded yet.
        Ú_loaded_data)ÚhasattrÚ_getr?   )r   ÚmessagesÚall_retrievedr   r   r   r5   P   s   

zBaseStorage._loaded_messagesc                 O   ó   t dƒ‚)a  
        Retrieve a list of stored messages. Return a tuple of the messages
        and a flag indicating whether or not all the messages originally
        intended to be stored in this storage were, in fact, stored and
        retrieved; e.g., ``(messages, all_retrieved)``.

        **This method must be implemented by a subclass.**

        If it is possible to tell if the backend was not used (as opposed to
        just containing no messages) then ``None`` should be returned in
        place of ``messages``.
        z6subclasses of BaseStorage must provide a _get() method©ÚNotImplementedError)r   r0   r1   r   r   r   rA   [   s   ÿzBaseStorage._getc                 O   rD   )zï
        Store a list of messages and return a list of any messages which could
        not be stored.

        One type of object must be able to be stored, ``Message``.

        **This method must be implemented by a subclass.**
        z8subclasses of BaseStorage must provide a _store() methodrE   )r   rB   Úresponser0   r1   r   r   r   Ú_storel   s   	ÿzBaseStorage._storec                 C   s   |D ]}|  ¡  qdS )z9
        Prepare a list of messages for storage.
        N)r   )r   rB   r
   r   r   r   Ú_prepare_messagesy   s   
ÿzBaseStorage._prepare_messagesc                 C   sB   |   | j¡ | jr|  | j|¡S | jr| j| j }|  ||¡S dS )zË
        Store all unread messages.

        If the backend has yet to be iterated, store previously stored messages
        again. Otherwise, only store messages added after the last iteration.
        N)rI   r,   r-   rH   r.   r5   )r   rG   rB   r   r   r   Úupdate€   s   þzBaseStorage.updater   c                 C   sB   |sdS t |ƒ}|| jk rdS d| _t|||d�}| j |¡ dS )zº
        Queue a message to be stored.

        The message is only queued if it contained something and its level is
        not less than the recording level (``self.level``).
        NT)r   )r   r	   r.   r   r,   Úappendr   r   r   r   ÚaddŽ   s   
zBaseStorage.addc                 C   s    t | dƒsttdtjƒ| _| jS )z«
        Return the minimum recorded level.

        The default level is the ``MESSAGE_LEVEL`` setting. If this is
        not found, the ``INFO`` level is used.
        Ú_levelÚMESSAGE_LEVEL)r@   Úgetattrr   r   ÚINFOrM   r   r   r   r   Ú
_get_level    s   
zBaseStorage._get_levelNc                 C   s(   |du rt | dƒr| `dS t|ƒ| _dS )z›
        Set a custom minimum recorded level.

        If set to ``None``, the default level will be used (see the
        ``_get_level`` method).
        NrM   )r@   rM   r   )r   Úvaluer   r   r   Ú
_set_level«   s   zBaseStorage._set_level)r   r   )r%   r&   r'   r(   r   r6   r:   r<   r   r)   r5   rA   rH   rI   rJ   rL   rQ   rS   r	   Ú__classcell__r   r   r2   r   r*   1   s"    



r*   N)Údjango.confr   Údjango.contrib.messagesr   r   Údjango.utils.functionalr   Úget_level_tagsr#   r   r*   r   r   r   r   Ú<module>   s    
)