
 X                 @   s   d  d l  m Z d  d l m Z d  d l m Z m Z d  d l m Z m	 Z	 e j
   Z e	 Gd d   d e   Z Gd d   d e  Z d	 S)
    )unicode_literals)settings)	constantsutils)
force_textpython_2_unicode_compatiblec               @   ss   e  Z d  Z d Z d d d  Z d d   Z d d   Z d	 d
   Z d d   Z e	 e  Z
 e	 d d    Z d S)Messagez
    Represents 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   R/home/ubuntu/projects/ifolica/build/django/django/contrib/messages/storage/base.py__init__   s    	zMessage.__init__c             C   s4   t  |  j d d |  _ t  |  j d d |  _ d S)a  
        Prepares the message for serialization by forcing the ``message``
        and ``extra_tags`` to unicode in case they are lazy translations.

        Known "safe" types (None, int, etc.) are not converted (see Django's
        ``force_text`` implementation for details).
        strings_onlyTN)r   r   r   )r   r   r   r   _prepare   s    zMessage._preparec             C   s1   t  | t  o0 |  j | j k o0 |  j | j k S)N)
isinstancer   r
   r   )r   otherr   r   r   __eq__"   s    !zMessage.__eq__c             C   s   t  |  j  S)N)r   r   )r   r   r   r   __str__&   s    zMessage.__str__c             C   sX   t  |  j d d } | r: |  j r: d j | |  j g  S| rD | S|  j rT |  j Sd S)Nr   T  )r   r   	level_tagjoin)r   r   r   r   r   	_get_tags)   s    	zMessage._get_tagsc             C   s   t  t j |  j d  d d S)Nr   r   T)r   
LEVEL_TAGSgetr
   )r   r   r   r   r   4   s    zMessage.level_tag)__name__
__module____qualname____doc__r   r   r   r   r   propertytagsr   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 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   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                sA   | |  _  g  |  _ d |  _ d |  _ t t |   j | |   d  S)NF)request_queued_messagesused	added_newsuperr$   r   )r   r%   argskwargs)	__class__r   r   r   A   s
    				zBaseStorage.__init__c             C   s   t  |  j  t  |  j  S)N)len_loaded_messagesr&   )r   r   r   r   __len__H   s    zBaseStorage.__len__c             C   s>   d |  _  |  j r1 |  j j |  j  g  |  _ n  t |  j  S)NT)r'   r&   r.   extenditer)r   r   r   r   __iter__K   s
    		zBaseStorage.__iter__c             C   s   | |  j  k p | |  j k S)N)r.   r&   )r   itemr   r   r   __contains__R   s    zBaseStorage.__contains__c             C   s:   t  |  d  s3 |  j   \ } } | p* g  |  _ n  |  j S)zt
        Returns a list of loaded messages, retrieving them first if they have
        not been loaded yet.
        _loaded_data)hasattr_getr5   )r   messagesZall_retrievedr   r   r   r.   U   s    zBaseStorage._loaded_messagesc             O   s   t  d   d S)a  
        Retrieves a list of stored messages. Returns 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() methodN)NotImplementedError)r   r*   r+   r   r   r   r7   `   s    zBaseStorage._getc             O   s   t  d   d S)z
        Stores a list of messages, returning 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() methodN)r9   )r   r8   responser*   r+   r   r   r   _storeo   s    	zBaseStorage._storec             C   s   x | D] } | j    q Wd S)z:
        Prepares a list of messages for storage.
        N)r   )r   r8   r   r   r   r   _prepare_messagesz   s    zBaseStorage._prepare_messagesc             C   sY   |  j  |  j  |  j r, |  j |  j |  S|  j rU |  j |  j } |  j | |  Sd S)z
        Stores all unread messages.

        If the backend has yet to be iterated, previously stored messages will
        be stored again. Otherwise, only messages added after the last
        iteration will be stored.
        N)r<   r&   r'   r;   r(   r.   )r   r:   r8   r   r   r   update   s    		zBaseStorage.updater   c             C   s[   | s
 d St  |  } | |  j k  r) d Sd |  _ t | | d | } |  j j |  d S)z
        Queues 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``).
        NTr   )r	   r
   r(   r   r&   append)r   r
   r   r   r   r   r   add   s    	zBaseStorage.addc             C   s1   t  |  d  s* t t d t j  |  _ n  |  j S)z
        Returns the minimum recorded level.

        The default level is the ``MESSAGE_LEVEL`` setting. If this is
        not found, the ``INFO`` level is used.
        _levelZMESSAGE_LEVEL)r6   getattrr   r   INFOr@   )r   r   r   r   
_get_level   s    zBaseStorage._get_levelNc             C   s7   | d k r$ t  |  d  r$ |  ` n t |  |  _ d S)z
        Sets a custom minimum recorded level.

        If set to ``None``, the default level will be used (see the
        ``_get_level`` method).
        Nr@   )r6   r@   r	   )r   valuer   r   r   
_set_level   s    	zBaseStorage._set_level)r   r   r    r!   r   r/   r2   r4   r"   r.   r7   r;   r<   r=   r?   rC   rE   r
   r   r   )r,   r   r$   9   s   r$   N)
__future__r   Zdjango.confr   Zdjango.contrib.messagesr   r   Zdjango.utils.encodingr   r   Zget_level_tagsr   objectr   r$   r   r   r   r   <module>   s   .