
    Hwg                     j    d dl mZ d dlmZmZ  ej
                         Z G d d      Z G d d      Zy)    )settings)	constantsutilsc                   J    e Zd ZdZd	dZd Zd Zd Zed        Z	ed        Z
y)
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                 @    t        |      | _        || _        || _        y N)intlevelmessage
extra_tagsselfr   r   r   s       [/var/www/horilla/myenv/lib/python3.12/site-packages/django/contrib/messages/storage/base.py__init__zMessage.__init__   s    Z
$    c                     t        | j                        | _        | j                  t        | j                        | _        yd| _        y)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   s    r   _preparezMessage._prepare   s4    
 4<<(26//2M#doo.SWr   c                     t        |t              st        S | j                  |j                  k(  xr | j                  |j                  k(  S r	   )
isinstancer   NotImplementedr   r   )r   others     r   __eq__zMessage.__eq__   s7    %)!!zzU[[(JT\\U]]-JJr   c                 ,    t        | j                        S r	   )r   r   r   s    r   __str__zMessage.__str__    s    4<<  r   c                 ^    dj                  d | j                  | j                  fD              S )N c              3   &   K   | ]	  }|s|  y wr	    ).0tags     r   	<genexpr>zMessage.tags.<locals>.<genexpr>%   s     PCPs   )joinr   	level_tagr   s    r   tagszMessage.tags#   s$    xxP'HPPPr   c                 B    t         j                  | j                  d      S )N )
LEVEL_TAGSgetr   r   s    r   r&   zMessage.level_tag'   s    ~~djj"--r   r	   )__name__
__module____qualname____doc__r   r   r   r   propertyr'   r&   r!   r   r   r   r      sG    %
XK
! Q Q . .r   r   c                        e Zd ZdZ fdZd Zd Zd Zd Ze	d        Z
d Zd	 Zd
 Zd ZddZd ZddZ e	eee      Z x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                 \    || _         g | _        d| _        d| _        t	        |   |i | y )NF)request_queued_messagesused	added_newsuperr   )r   r4   argskwargs	__class__s       r   r   zBaseStorage.__init__4   s2     "	$)&)r   c                 X    t        | j                        t        | j                        z   S r	   )len_loaded_messagesr5   r   s    r   __len__zBaseStorage.__len__;   s#    4(()C0E0E,FFFr   c                     d| _         | j                  r,| j                  j                  | j                         g | _        t	        | j                        S )NT)r6   r5   r>   extenditerr   s    r   __iter__zBaseStorage.__iter__>   sE    	  !!(()>)>?$&D!D))**r   c                 >    || j                   v xs || j                  v S r	   )r>   r5   )r   items     r   __contains__zBaseStorage.__contains__E   s#    t,,,M8M8M0MMr   c                 P    d| j                   j                   d| j                  dS )N<z
: request=>)r;   r.   r4   r   s    r   __repr__zBaseStorage.__repr__H   s'    4>>../z$,,9IKKr   c                 n    t        | d      s| j                         \  }}|xs g | _        | j                  S )zs
        Return a list of loaded messages, retrieving them first if they have
        not been loaded yet.
        _loaded_data)hasattr_getrL   )r   messagesall_retrieveds      r   r>   zBaseStorage._loaded_messagesK   s6     t^,&*iik#Hm (BD   r   c                     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   r9   r:   s      r   rN   zBaseStorage._getV   s     "D
 	
r   c                     t        d      )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() methodrR   )r   rO   responser9   r:   s        r   _storezBaseStorage._storeg   s     "F
 	
r   c                 2    |D ]  }|j                           y)z9
        Prepare a list of messages for storage.
        N)r   )r   rO   r   s      r   _prepare_messageszBaseStorage._prepare_messagest   s       	G	r   c                     | j                  | j                         | j                  r| j                  | j                  |      S | j                  r+| j
                  | j                  z   }| j                  ||      S y)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)rX   r5   r6   rV   r7   r>   )r   rU   rO   s      r   updatezBaseStorage.update{   si     	t44599;;t44h??^^,,t/D/DDH;;x22 r   c                     |syt        |      }|| j                  k  ryd| _        t        |||      }| j                  j                  |       y)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   r7   r   r5   appendr   s       r   addzBaseStorage.add   sK     E
4::%Z@$$W-r   c                 z    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)rM   getattrr   r   INFOr_   r   s    r   
_get_levelzBaseStorage._get_level   s,     tX&!(OY^^LDK{{r   c                 F    |t        | d      r| `yt        |      | _        y)z
        Set a custom minimum recorded level.

        If set to ``None``, the default level will be used (see the
        ``_get_level`` method).
        Nr_   )rM   r_   r
   )r   values     r   
_set_levelzBaseStorage._set_level   s"     =WT84e*DKr   )r)   r	   )r,   r-   r.   r/   r   r?   rC   rF   rJ   r0   r>   rN   rV   rX   rZ   r]   rc   rf   r   __classcell__)r;   s   @r   r2   r2   ,   sk    *G+NL ! !
"
3.$	
% ZZ8Er   r2   N)	django.confr   django.contrib.messagesr   r   get_level_tagsr*   r   r2   r!   r   r   <module>rk      s2      4!U!!#
". ".JF9 F9r   