ó
Ý*µPc           @   s”   y d  d l  m Z Wn e k
 r3 d  d l Z n Xd  d l m Z d  d l m Z d  d l m	 Z	 d e
 f d „  ƒ  YZ d e	 f d	 „  ƒ  YZ d S(
   iÿÿÿÿ(   t   cPickleN(   t   settings(   t   signing(   t   SessionBaset   PickleSerializerc           B   s    e  Z d  Z d „  Z d „  Z RS(   sY   
    Simple wrapper around pickle to be used in signing.dumps and
    signing.loads.
    c         C   s   t  j | t  j ƒ S(   N(   t   picklet   dumpst   HIGHEST_PROTOCOL(   t   selft   obj(    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyR      s    c         C   s   t  j | ƒ S(   N(   R   t   loads(   R   t   data(    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyR
      s    (   t   __name__t
   __module__t   __doc__R   R
   (    (    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyR      s   	t   SessionStorec           B   s_   e  Z d  „  Z d „  Z e d „ Z d d „ Z d d „ Z d „  Z	 d „  Z
 e d „  ƒ Z RS(	   c         C   sT   y) t  j |  j d t d t j d d ƒSWn$ t  j t f k
 rO |  j ƒ  n Xi  S(   sÁ   
        We load the data from the key itself instead of fetching from
        some external data store. Opposite of _get_session_key(),
        raises BadSignature if signature fails.
        t
   serializert   max_aget   salts/   django.contrib.sessions.backends.signed_cookies(	   R   R
   t   session_keyR   R   t   SESSION_COOKIE_AGEt   BadSignaturet
   ValueErrort   create(   R   (    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyt   load   s    	c         C   s   t  |  _ d S(   s¡   
        To create a new key, we simply make sure that the modified flag is set
        so that the cookie is set on the client for the current request.
        N(   t   Truet   modified(   R   (    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyR   *   s    c         C   s   |  j  ƒ  |  _ t |  _ d S(   s½   
        To save, we get the session key as a securely signed string and then
        set the modified flag so that the cookie is set on the client for the
        current request.
        N(   t   _get_session_keyt   _session_keyR   R   (   R   t   must_create(    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyt   save1   s    c         C   s   t  S(   sµ   
        This method makes sense when you're talking to a shared resource, but
        it doesn't matter when you're storing the information in the client's
        cookie.
        (   t   False(   R   R   (    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyt   exists:   s    c         C   s   d |  _  i  |  _ t |  _ d S(   sÂ   
        To delete, we clear the session key and the underlying data structure
        and set the modified flag so that the cookie is set on the client for
        the current request.
        t    N(   R   t   _session_cacheR   R   (   R   R   (    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyt   deleteB   s    		c         C   s   |  j  ƒ  d S(   sÈ   
        Keeps the same data but with a new key.  To do this, we just have to
        call ``save()`` and it will automatically save a cookie with a new key
        at the end of the request.
        N(   R   (   R   (    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyt	   cycle_keyL   s    c         C   s1   t  |  d i  ƒ } t j | d t d d d t ƒS(   sþ   
        Most session backends don't need to override this method, but we do,
        because instead of generating a random string, we want to actually
        generate a secure url-safe Base64-encoded string of data as our
        session key.
        R"   t   compressR   s/   django.contrib.sessions.backends.signed_cookiesR   (   t   getattrR   R   R   R   (   R   t   session_cache(    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyR   T   s    c         C   s   d  S(   N(    (   t   cls(    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyt   clear_expired`   s    N(   R   R   R   R   R   R   t   NoneR    R#   R$   R   t   classmethodR)   (    (    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyR      s   			
		(   t   django.utils.six.movesR    R   t   ImportErrort   django.confR   t   django.coreR   t%   django.contrib.sessions.backends.baseR   t   objectR   R   (    (    (    sH   ../Django//lib/python/django/contrib/sessions/backends/signed_cookies.pyt   <module>   s   