ó
i4Vdc           @   sÊ   d  d l  Z  d  d l m Z d  d l m Z m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z m Z d  d l m Z m Z d e  j f d	 „  ƒ  YZ d
 e  j f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   settings(   t   BaseStoraget   Message(   t   SimpleCookie(   t   six(   t   constant_time_comparet   salted_hmac(   t   SafeDatat	   mark_safet   MessageEncoderc           B   s   e  Z d  Z d Z d „  Z RS(   sJ   
    Compactly serializes instances of the ``Message`` class as JSON.
    t   __json_messagec         C   s~   t  | t ƒ rh t  | j t ƒ r' d n d } |  j | | j | j g } | j rd | j | j ƒ n  | St t	 |  ƒ j
 | ƒ S(   Ni   i    (   t
   isinstanceR   t   messageR   t   message_keyt   levelt
   extra_tagst   appendt   superR	   t   default(   t   selft   objt   is_safedataR   (    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyR      s    	(   t   __name__t
   __module__t   __doc__R   R   (    (    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyR	      s   t   MessageDecoderc           B   s    e  Z d  Z d „  Z d „  Z RS(   sF   
    Decodes JSON that includes serialized ``Message`` instances.
    c            sÇ   t  | t ƒ r— | r— | d t j k rw t | ƒ d k rH t | d Œ  S| d ri t | d ƒ | d <n  t | d Œ  Sg  | D] } ˆ  j | ƒ ^ q~ St  | t ƒ rÃ ‡  f d †  t	 j
 | ƒ Dƒ S| S(   Ni    i   i   i   c            s(   i  |  ] \ } } ˆ  j  | ƒ | “ q S(    (   t   process_messages(   t   .0t   keyt   value(   R   (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pys
   <dictcomp>,   s   	(   R   t   listR	   R   t   lenR   R   R   t   dictR   t	   iteritems(   R   R   t   item(    (   R   st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyR   !   s    
 c         K   s(   t  t |  ƒ j | |  } |  j | ƒ S(   N(   R   R   t   decodeR   (   R   t   st   kwargst   decoded(    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyR#   0   s    (   R   R   R   R   R#   (    (    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyR      s   	t   CookieStoragec           B   s\   e  Z d  Z d Z d Z d Z d „  Z d „  Z e d „ Z	 d „  Z
 e d „ Z d	 „  Z RS(
   s&   
    Stores messages in a cookie.
    t   messagesi   t   __messagesnotfinished__c         O   se   |  j  j j |  j ƒ } |  j | ƒ } | o= | d |  j k } | r[ | r[ | j ƒ  n  | | f S(   s  
        Retrieves 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.
        iÿÿÿÿ(   t   requestt   COOKIESt   gett   cookie_namet   _decodet   not_finishedt   pop(   R   t   argsR%   t   dataR(   t   all_retrieved(    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyt   _get@   s    c      	   C   s`   | rC | j  |  j | d t j d t j p- d d t j p< d ƒn | j |  j d t j ƒd S(   s|   
        Either sets the cookie with the encoded data if there is any data to
        store, or deletes the cookie.
        t   domaint   securet   httponlyN(   t
   set_cookieR-   R    t   SESSION_COOKIE_DOMAINt   SESSION_COOKIE_SECUREt   Nonet   SESSION_COOKIE_HTTPONLYt   delete_cookie(   R   t   encoded_datat   response(    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyt   _update_cookieO   s    	c   	         sÃ   g  } |  j  | ƒ } |  j r¯ t ƒ  ‰  ‡  f d †  } xv | r« | | ƒ |  j k r« | rs | j | j d ƒ ƒ n | j d | j ƒ  ƒ |  j  | |  j g d | ƒ} q9 Wn  |  j | | ƒ | S(   sV  
        Stores the messages to a cookie, returning a list of any messages which
        could not be stored.

        If the encoded data is larger than ``max_cookie_size``, removes
        messages until the data fits (these are the messages which are
        returned), and add the not_finished sentinel value to indicate as much.
        c            s   t  ˆ  j |  ƒ d ƒ S(   Ni   (   R   t   value_encode(   t   val(   t   cookie(    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyt   stored_lengthm   s    i    t   encode_empty(   t   _encodet   max_cookie_sizeR   R   R0   t   insertR/   R@   (	   R   R(   R?   t   remove_oldestR1   R%   t   unstored_messagesR>   RD   (    (   RC   st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyt   _store]   s    			c         C   s   d } t  | | ƒ j ƒ  S(   s    
        Creates an HMAC/SHA1 hash based on the value and the project setting's
        SECRET_KEY, modified to make it unique for the present purpose.
        s   django.contrib.messages(   R   t	   hexdigest(   R   R   t   key_salt(    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyt   _hashz   s    c         C   sE   | s | rA t  d d ƒ } | j | ƒ } d |  j | ƒ | f Sd S(   s	  
        Returns 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
   separatorst   ,t   :s   %s$%sN(   RP   RQ   (   R	   t   encodeRN   (   R   R(   RE   t   encoderR   (    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyRF   ‚   s    c         C   s   | s
 d S| j d d ƒ } t | ƒ d k rƒ | \ } } t | |  j | ƒ ƒ rƒ y t j | d t ƒSWq€ t k
 r| q€ Xqƒ n  t	 |  _
 d S(   sÎ   
        Safely decodes 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, ``None`` is returned.
        t   $i   i   t   clsN(   R;   t   splitR   R   RN   t   jsont   loadsR   t
   ValueErrort   Truet   used(   R   R2   t   bitst   hashR   (    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyR.      s    
	(   R   R   R   R-   RG   R/   R4   R@   RZ   RK   RN   t   FalseRF   R.   (    (    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyR'   5   s   			(   RW   t   django.confR    t$   django.contrib.messages.storage.baseR   R   t   django.httpR   t   django.utilsR   t   django.utils.cryptoR   R   t   django.utils.safestringR   R   t   JSONEncoderR	   t   JSONDecoderR   R'   (    (    (    st   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/messages/storage/cookie.pyt   <module>   s   