ó
`¾Tc           @   sY  d  Z  d d l Z d d l Z d d l m Z m Z d d l m Z d d l m Z m	 Z	 d d l
 m Z d d l m Z m Z d d	 l m Z m Z d d
 l m Z m Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ e ƒ  Z d e e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d l m Z d S(   sÂ   
    flask.sessions
    ~~~~~~~~~~~~~~

    Implements cookie based sessions based on itsdangerous.

    :copyright: (c) 2012 by Armin Ronacher.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿN(   t	   b64encodet	   b64decode(   t   datetime(   t	   http_datet
   parse_date(   t   CallbackDicti   (   t   Markupt   json(   t	   iteritemst	   text_type(   t   URLSafeTimedSerializert   BadSignaturec         C   s   |  j  d d d |  j S(   Ni<   i   (   t   dayst   seconds(   t   td(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   total_seconds   s    t   SessionMixinc           B   sA   e  Z d  Z d „  Z d „  Z e e e ƒ Z [ [ e Z e	 Z
 RS(   sv   Expands a basic dictionary with an accessors that are expected
    by Flask extensions and users for the session.
    c         C   s   |  j  d t ƒ S(   Nt
   _permanent(   t   gett   False(   t   self(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   _get_permanent!   s    c         C   s   t  | ƒ |  d <d  S(   NR   (   t   bool(   R   t   value(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   _set_permanent$   s    (   t   __name__t
   __module__t   __doc__R   R   t   propertyt	   permanentR   t   newt   Truet   modified(    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyR      s   		t   TaggedJSONSerializerc           B   s    e  Z d  Z d „  Z d „  Z RS(   s“   A customized JSON serializer that supports a few extra types that
    we take for granted when serializing (tuples, markup objects, datetime).
    c            s(   ‡  f d †  ‰  t  j ˆ  | ƒ d d ƒS(   Nc            sn  t  |  t ƒ r3 i g  |  D] } ˆ  | ƒ ^ q d 6St  |  t j ƒ rS i |  j d 6St  |  t ƒ r| i t |  ƒ j d ƒ d 6St t	 |  d d  ƒ ƒ r« i t |  j ƒ  ƒ d 6St  |  t ƒ r× g  |  D] } ˆ  | ƒ ^ qÁ St  |  t ƒ r÷ i t |  ƒ d 6St  |  t ƒ r&t ‡  f d †  t |  ƒ Dƒ ƒ St  |  t ƒ rjy t |  ƒ SWqjt k
 rft d	 |  ƒ ‚ qjXn  |  S(
   Ns    ts    ut   asciis    bt   __html__s    ms    dc         3   s'   |  ] \ } } | ˆ  | ƒ f Vq d  S(   N(    (   t   .0t   kt   v(   t   _tag(    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pys	   <genexpr>K   s    už   A byte string with non-ASCII data was passed to the session system which can only store unicode strings.  Consider base64 encoding your string (String was %r)(   t
   isinstancet   tuplet   uuidt   UUIDt   hext   bytesR    t   decodet   callablet   getattrt   NoneR	   R#   t   listR   R   t   dictR   t   strt   UnicodeErrort   UnexpectedUnicodeError(   R   t   x(   R'   (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyR'   =   s*    $ t
   separatorst   ,t   :(   R9   R:   (   R   t   dumps(   R   R   (    (   R'   sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyR;   <   s    c         C   s   d „  } t  j | d | ƒS(   Nc         S   s£   t  |  ƒ d k r |  St t |  ƒ ƒ \ } } | d k rD t | ƒ S| d k r] t j | ƒ S| d k rs t | ƒ S| d k r‰ t | ƒ S| d k rŸ t | ƒ S|  S(   Ni   s    ts    us    bs    ms    d(	   t   lent   nextR   R)   R*   R+   R   R   R   (   t   objt   the_keyt	   the_value(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   object_hookX   s    



RA   (   R   t   loads(   R   R   RA   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyRB   W   s    	(   R   R   R   R;   RB   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyR!   7   s   	t   SecureCookieSessionc           B   s   e  Z d  Z d d „ Z RS(   s/   Baseclass for sessions based on signed cookies.c         C   s)   d „  } t  j |  | | ƒ t |  _ d  S(   Nc         S   s   t  |  _ d  S(   N(   R   R    (   R   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt	   on_updateq   s    (   R   t   __init__R   R    (   R   t   initialRD   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyRE   p   s    	N(   R   R   R   R1   RE   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyRC   m   s   t   NullSessionc           B   s8   e  Z d  Z d „  Z e Z Z Z Z Z Z	 Z
 [ RS(   s¤   Class used to generate nicer error messages if sessions are not
    available.  Will still allow read-only access to the empty session
    but fail on setting.
    c         O   s   t  d ƒ ‚ d  S(   Ns€   the session is unavailable because no secret key was set.  Set the secret_key on the application to something unique and secret.(   t   RuntimeError(   R   t   argst   kwargs(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   _fail}   s    (   R   R   R   RK   t   __setitem__t   __delitem__t   cleart   popt   popitemt   updatet
   setdefault(    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyRG   w   s   	t   SessionInterfacec           B   sk   e  Z d  Z e Z e Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d	 „  Z RS(
   s´  The basic interface you have to implement in order to replace the
    default session interface which uses werkzeug's securecookie
    implementation.  The only methods you have to implement are
    :meth:`open_session` and :meth:`save_session`, the others have
    useful defaults which you don't need to change.

    The session object returned by the :meth:`open_session` method has to
    provide a dictionary like interface plus the properties and methods
    from the :class:`SessionMixin`.  We recommend just subclassing a dict
    and adding that mixin::

        class Session(dict, SessionMixin):
            pass

    If :meth:`open_session` returns `None` Flask will call into
    :meth:`make_null_session` to create a session that acts as replacement
    if the session support cannot work because some requirement is not
    fulfilled.  The default :class:`NullSession` class that is created
    will complain that the secret key was not set.

    To replace the session interface on an application all you have to do
    is to assign :attr:`flask.Flask.session_interface`::

        app = Flask(__name__)
        app.session_interface = MySessionInterface()

    .. versionadded:: 0.8
    c         C   s
   |  j  ƒ  S(   sÉ  Creates a null session which acts as a replacement object if the
        real session support could not be loaded due to a configuration
        error.  This mainly aids the user experience because the job of the
        null session is to still support lookup without complaining but
        modifications are answered with a helpful error message of what
        failed.

        This creates an instance of :attr:`null_session_class` by default.
        (   t   null_session_class(   R   t   app(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   make_null_session±   s    
c         C   s   t  | |  j ƒ S(   sÊ   Checks if a given object is a null session.  Null sessions are
        not asked to be saved.

        This checks if the object is an instance of :attr:`null_session_class`
        by default.
        (   R(   RT   (   R   R>   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   is_null_session½   s    c         C   s«   | j  d d	 k	 r | j  d S| j  d d	 k	 r§ d | j  d j d d ƒ d } | d k rg d	 } n  | d	 k	 r£ |  j | ƒ } | d k r£ | j d ƒ } q£ n  | Sd	 S(
   s   Helpful helper method that returns the cookie domain that should
        be used for the session cookie if session cookies are used.
        t   SESSION_COOKIE_DOMAINt   SERVER_NAMEt   .R:   i   i    s
   .localhostt   /N(   t   configR1   t   rsplitt   get_cookie_patht   lstrip(   R   RU   t   rvt   path(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   get_cookie_domainÆ   s    !	c         C   s   | j  d p | j  d p d S(   sþ   Returns the path for which the cookie should be valid.  The
        default implementation uses the value from the SESSION_COOKIE_PATH``
        config var if it's set, and falls back to ``APPLICATION_ROOT`` or
        uses ``/`` if it's `None`.
        t   SESSION_COOKIE_PATHt   APPLICATION_ROOTR[   (   R\   (   R   RU   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyR^   à   s    c         C   s   | j  d S(   s¥   Returns True if the session cookie should be httponly.  This
        currently just returns the value of the ``SESSION_COOKIE_HTTPONLY``
        config var.
        t   SESSION_COOKIE_HTTPONLY(   R\   (   R   RU   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   get_cookie_httponlyé   s    c         C   s   | j  d S(   sŽ   Returns True if the cookie should be secure.  This currently
        just returns the value of the ``SESSION_COOKIE_SECURE`` setting.
        t   SESSION_COOKIE_SECURE(   R\   (   R   RU   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   get_cookie_secureð   s    c         C   s   | j  r t j ƒ  | j Sd S(   s  A helper method that returns an expiration date for the session
        or `None` if the session is linked to the browser session.  The
        default implementation returns now + the permanent session
        lifetime configured on the application.
        N(   R   R   t   utcnowt   permanent_session_lifetime(   R   RU   t   session(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   get_expiration_timeö   s    	c         C   s   t  ƒ  ‚ d S(   s#  This method has to be implemented and must either return `None`
        in case the loading failed because of a configuration error or an
        instance of a session object which implements a dictionary like
        interface + the methods and attributes on :class:`SessionMixin`.
        N(   t   NotImplementedError(   R   RU   t   request(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   open_sessionÿ   s    c         C   s   t  ƒ  ‚ d S(   sï   This is called for actual sessions returned by :meth:`open_session`
        at the end of the request.  This is still called during a request
        context so if you absolutely need access to the request you can do
        that.
        N(   Rm   (   R   RU   Rk   t   response(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   save_session  s    (   R   R   R   RG   RT   R   t   pickle_basedRV   RW   Rb   R^   Rf   Rh   Rl   Ro   Rq   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyRS   †   s   											t   SecureCookieSessionInterfacec           B   sP   e  Z d  Z d Z e e j ƒ Z d Z e	 Z
 e Z d „  Z d „  Z d „  Z RS(   su   The default session interface that stores sessions in signed cookies
    through the :mod:`itsdangerous` module.
    s   cookie-sessiont   hmacc         C   sM   | j  s d  St d |  j d |  j ƒ } t | j  d |  j d |  j d | ƒS(   Nt   key_derivationt   digest_methodt   saltt
   serializert   signer_kwargs(   t
   secret_keyR1   R3   Ru   Rv   R
   Rw   Rx   (   R   RU   Ry   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   get_signing_serializer"  s    			c         C   s˜   |  j  | ƒ } | d  k r d  S| j j | j ƒ } | sD |  j ƒ  St | j ƒ } y& | j | d | ƒ} |  j | ƒ SWn t	 k
 r“ |  j ƒ  SXd  S(   Nt   max_age(
   R{   R1   t   cookiesR   t   session_cookie_namet   session_classR   Rj   RB   R   (   R   RU   Rn   t   st   valR|   t   data(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyRo   -  s    
c   
      C   sÓ   |  j  | ƒ } |  j | ƒ } | sP | j rL | j | j d | d | ƒn  d  S|  j | ƒ } |  j | ƒ } |  j | | ƒ } |  j | ƒ j	 t
 | ƒ ƒ }	 | j | j |	 d | d | d | d | d | ƒd  S(   Nt   domainRa   t   expirest   httponlyt   secure(   Rb   R^   R    t   delete_cookieR~   Rf   Rh   Rl   R{   R;   R3   t
   set_cookie(
   R   RU   Rk   Rp   Rƒ   Ra   R…   R†   R„   R   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyRq   ;  s    	(   R   R   R   Rw   t   staticmethodt   hashlibt   sha1Rv   Ru   t   session_json_serializerRx   RC   R   R{   Ro   Rq   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyRs     s   		(   R6   (    R   R*   RŠ   t   base64R    R   R   t   werkzeug.httpR   R   t   werkzeug.datastructuresR   t    R   R   t   _compatR   R	   t   itsdangerousR
   R   R   t   objectR   R!   RŒ   RC   RG   RS   Rs   t   flask.debughelpersR6   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/sessions.pyt   <module>
   s$   	3	
Š<