
&`Tc           @   sM  d  Z  d d d f Z d j e  Z d Z d Z d Z d g Z d	 d
 l m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z m Z d	 d l 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	 d l m Z d	 d l m  Z  m! Z! d	 d l" Z" d	 d l# Z# d	 d l$ Z$ e$ j% d k  rMd	 d l& m& Z& m' Z' n d	 d l( m& Z& m' Z' e) Z* e   Z+ e d    Z, d Z- e d d  Z. e/ Z0 e1 Z2 d Z3 d Z4 d Z5 d Z6 d Z7 d Z8 d e9 f d     YZ: d e9 f d      YZ; d! e9 f d"     YZ< d#   Z= d$   Z> d%   Z? e/ d& d'  Z@ d(   ZA d)   ZB e1 e1 d*  ZC d+   ZD d,   ZE d-   ZF d.   ZG d/   ZH e/ d0  ZI d1   ZJ d2   ZK d3   ZL e/ d4  ZM e+ jN d5  ZO e+ jN d6  ZP e+ jN d7  ZQ e+ jN d8  ZR e+ jN d9  ZS e+ jN d:  ZT e+ jN d;  ZU e+ jN d<  ZV e+ jN d=  ZW e+ jN d>  ZX d S(?   s  
    flask.ext.login
    ---------------

    This module provides user session management for Flask. It lets you log
    your users in and out in a database-independent manner.

    :copyright: (c) 2011 by Matthew Frazier.
    :license: MIT/X11, see LICENSE for more details.
t   0t   2t   11t   .s   Matthew Fraziers   MIT/X11s   (c) 2011 by Matthew Fraziert   LoginManageri(	   t   _request_ctx_stackt   abortt   current_appt   flasht   redirectt   requestt   sessiont   url_fort   has_request_context(   t	   Namespace(   t
   LocalProxy(   t   safe_str_cmp(   t
   url_decodet
   url_encode(   t   datetimet	   timedelta(   t   wraps(   t   sha1t   md5Nt   3(   t   urlparset
   urlunparsec           C   s   t    S(   N(   t	   _get_user(    (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   <lambda>.   s    t   remember_tokent   daysim  u"   Please log in to access this page.t   messageu*   Please reauthenticate to access this page.t   get_idt   Authorizationc           B   s   e  Z d  Z d e d  Z e d  Z e d  Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   
    This object is used to hold the settings used for logging in. Instances of
    :class:`LoginManager` are *not* bound to specific apps, so you can create
    one in the main body of your code and then bind it to your
    app in a factory function.
    c         C   s   t  |  _ d  |  _ t |  _ t |  _ d  |  _ t	 |  _
 t |  _ d |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ t |  _ d  |  _ d  |  _ | d  k	 r |  j | |  n  d  S(   Nt   basic(   t   AnonymousUserMixint   anonymous_usert   Nonet
   login_viewt   LOGIN_MESSAGEt   login_messaget   LOGIN_MESSAGE_CATEGORYt   login_message_categoryt   refresh_viewt   REFRESH_MESSAGEt   needs_refresh_messaget   REFRESH_MESSAGE_CATEGORYt   needs_refresh_message_categoryt   session_protectiont   localize_callbackt   token_callbackt   user_callbackt   unauthorized_callbackt   needs_refresh_callbackt   ID_ATTRIBUTEt   id_attributet   header_callbackt   request_callbackt   init_app(   t   selft   appt   add_context_processor(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   __init__W   s$    																c         C   s$   t  j d t  |  j | |  d S(   sl   
        This method has been deprecated. Please use
        :meth:`LoginManager.init_app` instead.
        s5   Warning setup_app is deprecated. Please use init_app.N(   t   warningst   warnt   DeprecationWarningR:   (   R;   R<   R=   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt	   setup_app   s    	c         C   sZ   |  | _  | j |  j  | j j d | j j d t   |  _ | rV | j t  n  d S(   s  
        Configures an application. This registers an `after_request` call, and
        attaches this `LoginManager` to it as `app.login_manager`.

        :param app: The :class:`flask.Flask` object to configure.
        :type app: :class:`flask.Flask`
        :param add_context_processor: Whether to add a context processor to
            the app that adds a `current_user` variable to the template.
            Defaults to ``True``.
        :type add_context_processor: bool
        t   LOGIN_DISABLEDt   TESTINGN(	   t   login_managert   after_requestt   _update_remember_cookiet   configt   gett   Falset   _login_disabledt   context_processort   _user_context_processor(   R;   R<   R=   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR:      s    	c         C   s   t  j t j    |  j r& |  j   S|  j s< t d  n  |  j r |  j d k	 rv t
 |  j |  j  d |  j q t
 |  j d |  j n  t t |  j t j   S(   s"  
        This is called when the user is required to log in. If you register a
        callback with :meth:`LoginManager.unauthorized_handler`, then it will
        be called. Otherwise, it will take the following actions:

            - Flash :attr:`LoginManager.login_message` to the user.

            - Redirect the user to `login_view`. (The page they were attempting
              to access will be passed in the ``next`` query string variable,
              so you can redirect there if present instead of the homepage.)

        If :attr:`LoginManager.login_view` is not defined, then it will simply
        raise a HTTP 401 (Unauthorized) error instead.

        This should be returned from a view or before/after_request function,
        otherwise the redirect will have no effect.
        i  t   categoryN(   t   user_unauthorizedt   sendR   t   _get_current_objectR4   R&   R   R(   R1   R%   R   R*   R	   t	   login_urlR
   t   url(   R;   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   unauthorized   s    	
		c         C   s   | |  _  | S(   sA  
        This sets the callback for reloading a user from the session. The
        function you set should take a user ID (a ``unicode``) and return a
        user object, or ``None`` if the user does not exist.

        :param callback: The callback for retrieving a user object.
        :type callback: unicode
        (   R3   (   R;   t   callback(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   user_loader   s    		c         C   s   | |  _  | S(   s  
        This sets the callback for loading a user from a header value.
        The function you set should take an authentication token and
        return a user object, or `None` if the user does not exist.

        :param callback: The callback for retrieving a user object.
        (   R8   (   R;   RU   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   header_loader   s    	c         C   s   | |  _  | S(   s  
        This sets the callback for loading a user from a Flask request.
        The function you set should take Flask request object and
        return a user object, or `None` if the user does not exist.

        :param callback: The callback for retrieving a user object.
        (   R9   (   R;   RU   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   request_loader   s    	c         C   s   | |  _  | S(   s  
        This sets the callback for loading a user from an authentication
        token. The function you set should take an authentication token
        (a ``unicode``, as returned by a user's `get_auth_token` method) and
        return a user object, or ``None`` if the user does not exist.

        :param callback: The callback for retrieving a user object.
        :type callback: unicode
        (   R2   (   R;   RU   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   token_loader   s    
	c         C   s   | |  _  | S(   sb  
        This will set the callback for the `unauthorized` method, which among
        other things is used by `login_required`. It takes no arguments, and
        should return a response to be sent to the user instead of their
        normal view.

        :param callback: The callback for unauthorized users.
        :type callback: function
        (   R4   (   R;   RU   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   unauthorized_handler   s    
	c         C   s   | |  _  | S(   si  
        This will set the callback for the `needs_refresh` method, which among
        other things is used by `fresh_login_required`. It takes no arguments,
        and should return a response to be sent to the user instead of their
        normal view.

        :param callback: The callback for unauthorized users.
        :type callback: function
        (   R5   (   R;   RU   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   needs_refresh_handler  s    
	c         C   s   t  j t j    |  j r& |  j   S|  j s< t d  n  |  j d k	 rm t	 |  j |  j
  d |  j n t	 |  j
 d |  j t t |  j t j   S(   s}  
        This is called when the user is logged in, but they need to be
        reauthenticated because their session is stale. If you register a
        callback with `needs_refresh_handler`, then it will be called.
        Otherwise, it will take the following actions:

            - Flash :attr:`LoginManager.needs_refresh_message` to the user.

            - Redirect the user to :attr:`LoginManager.refresh_view`. (The page
              they were attempting to access will be passed in the ``next``
              query string variable, so you can redirect there if present
              instead of the homepage.)

        If :attr:`LoginManager.refresh_view` is not defined, then it will
        simply raise a HTTP 403 (Forbidden) error instead.

        This should be returned from a view or before/after_request function,
        otherwise the redirect will have no effect.
        i  RN   N(   t   user_needs_refreshRP   R   RQ   R5   R+   R   R1   R%   R   R-   R/   R	   RR   R
   RS   (   R;   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   needs_refresh  s    	
	
c         C   s   t  j } | d  k rs t j d  } | d  k rB |  j   | _ q| |  j |  } | d  k rg t   q| | | _ n	 | | _ d  S(   Nt   user_id(	   R   t   topR%   R   RI   R$   t   userR3   t   logout_user(   R;   R`   t   ctxR^   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   reload_user=  s    	
c         C   s
  t  j t j    t j } | j d |  j  rP |  j   } | rP |  j   Sn  d t	 k } | r | j d t
  } | j d t  } | t j k o t	 j d  d k } | r |  j t j |  S|  j r |  j t  S| t j k r |  j t j |  Sn  |  j   S(   s;   Loads user from session or remember_me cookie as applicablet   SESSION_PROTECTIONR^   t   REMEMBER_COOKIE_NAMEt   AUTH_HEADER_NAMEt   remembert   clear(   t   user_accessedRP   R   RQ   RH   RI   R0   t   _session_protectionRc   R   t   COOKIE_NAMERf   R
   t   cookiest   _load_from_cookieR9   t   _load_from_requestt   headerst   _load_from_header(   R;   RH   t   deletedt   is_missing_user_idt   cookie_namet   header_namet
   has_cookie(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt
   _load_userM  s&    		c         C   s   t  j   } t   } t j   } | j j d |  j  } d | k rR | | d <n  | pa | d k } | r | | j d d   k r | d k s | j r t	 | d <t
 j |  t	 S| d k r | j   d | d <t
 j |  t Sn  t	 S(   NRd   t   _idt   strongR"   t   _freshRh   Rg   (   R   RQ   t   _create_identifierR   RH   RI   R0   R%   t	   permanentRJ   t   session_protectedRP   Rh   t   True(   R;   t   sesst   identR<   t   modet   check_protection(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyRj   m  s$    	


c         C   s   |  j  rc |  j  |  } | d  k	 rV t | |  j    t d <t t d <| t j _ q |  j	   n9 t
 |  } | d  k	 r | t d <t t d <n  |  j	   t j j d  k	 r t j   } t j | d t   n  d  S(   NR^   Ry   R`   (   R2   R%   t   getattrR7   R   RJ   R   R_   R`   Rc   t   decode_cookieR   RQ   t   user_loaded_from_cookieRP   R   (   R;   t   cookieR`   R^   R<   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyRm     s    	


c         C   sp   d  } |  j r! |  j |  } n  | d  k	 rb |  j d |  t j   } t j | d t   n
 |  j   d  S(   NR`   (   R%   R8   Rc   R   RQ   t   user_loaded_from_headerRP   R   (   R;   t   headerR`   R<   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyRp     s    	c         C   sp   d  } |  j r! |  j |  } n  | d  k	 rb |  j d |  t j   } t j | d t   n
 |  j   d  S(   NR`   (   R%   R9   Rc   R   RQ   t   user_loaded_from_requestRP   R   (   R;   R
   R`   R<   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyRn     s    	c         C   si   d t  k re t  j d d   } | d k rF d t  k rF |  j |  qe | d k re |  j |  qe n  | S(   NRg   t   setR^   Rh   (   R   t   popR%   t   _set_cookiet   _clear_cookie(   R;   t   responset	   operation(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyRG     s    c   
      C   s   t  j } | j d t  } | j d t  } | j d  } | j d t  } | j d t  } |  j rx t j	   } n t
 t t d   } t j   | }	 | j | d | d |	 d	 | d
 | d | d  S(   NRe   t   REMEMBER_COOKIE_DURATIONt   REMEMBER_COOKIE_DOMAINt   REMEMBER_COOKIE_SECUREt   REMEMBER_COOKIE_HTTPONLYR^   t   valuet   expirest   domaint   securet   httponly(   R   RH   RI   Rk   t   COOKIE_DURATIONt   COOKIE_SECUREt   COOKIE_HTTPONLYR2   t   current_usert   get_auth_tokent   encode_cookiet   strR   R   t   utcnowt
   set_cookie(
   R;   R   RH   Rs   t   durationR   R   R   t   dataR   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR     s     		c         C   sA   t  j } | j d t  } | j d  } | j | d | d  S(   NRe   R   R   (   R   RH   RI   Rk   t   delete_cookie(   R;   R   RH   Rs   R   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR     s    	N(   t   __name__t
   __module__t   __doc__R%   R}   R>   RB   R:   RT   RV   RW   RX   RY   RZ   R[   R]   Rc   Rv   Rj   Rm   Rp   Rn   RG   R   R   (    (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR   P   s*   7		#							%	 						t	   UserMixinc           B   sc   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z e	 j
 d d k ra e j Z n  RS(	   sr   
    This provides default implementations for the methods that Flask-Login
    expects user objects to have.
    c         C   s   t  S(   N(   R}   (   R;   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt	   is_active  s    c         C   s   t  S(   N(   R}   (   R;   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   is_authenticated  s    c         C   s   t  S(   N(   RJ   (   R;   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   is_anonymous  s    c         C   s5   y t  |  j  SWn t k
 r0 t d   n Xd  S(   Ns%   No `id` attribute - override `get_id`(   t   unicodet   idt   AttributeErrort   NotImplementedError(   R;   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR      s    c         C   s)   t  | t  r% |  j   | j   k St S(   sP   
        Checks the equality of two `UserMixin` objects using `get_id`.
        (   t
   isinstanceR   R    t   NotImplemented(   R;   t   other(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   __eq__  s    c         C   s$   |  j  |  } | t k r t S| S(   sR   
        Checks the inequality of two `UserMixin` objects using `get_id`.
        (   R   R   (   R;   R   t   equal(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   __ne__  s    i    i   (   R   R   R   R   R   R   R    R   R   t   syst   version_infot   objectt   __hash__(    (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR     s   							R#   c           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sH   
    This is the default object for representing an anonymous user.
    c         C   s   t  S(   N(   RJ   (   R;   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR     s    c         C   s   t  S(   N(   RJ   (   R;   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR     s    c         C   s   t  S(   N(   R}   (   R;   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR     s    c         C   s   d  S(   N(    (   R;   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR      s    (   R   R   R   R   R   R   R    (    (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR#     s
   			c         C   s   d j  |  t |    S(   s   
    This will encode a ``unicode`` value into a cookie, and sign that cookie
    with the app's secret key.

    :param payload: The value to encode, as `unicode`.
    :type payload: unicode
    u   {0}|{1}(   t   formatt   _cookie_digest(   t   payload(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR     s    c         C   so   y= |  j  d d  \ } } t | d  r< | j d  } n  Wn t k
 rQ d SXt t |  |  rk | Sd S(   s   
    This decodes a cookie given by `encode_cookie`. If verification of the
    cookie fails, ``None`` will be implicitly returned.

    :param cookie: An encoded cookie.
    :type cookie: str
    u   |i   t   decodet   asciiN(   t   rsplitt   hasattrR   t
   ValueErrorR   R   (   R   R   t   digest(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR   (  s    c      
   C   sy   t  |   } t  |  } | j s4 | j | j k ru | j sP | j | j k ru t d d | j | j | j d f  S| S(   s  
    Reduces the scheme and host from a given URL so it can be passed to
    the given `login` URL more efficiently.

    :param login_url: The login URL being redirected to.
    :type login_url: str
    :param current_url: The URL to reduce.
    :type current_url: str
    t    (   R   t   schemet   netlocR   t   patht   paramst   query(   RR   t   current_urlt   lt   c(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   make_next_param;  s    
%t   nextc         C   s   |  j  d  r |  } n t |   } | d k r4 | St t |   } t | d  } t | |  | | <t | d t | d <t	 |  S(   s  
    Creates a URL for redirecting to a login page. If only `login_view` is
    provided, this will just return the URL for it. If `next_url` is provided,
    however, this will append a ``next=URL`` parameter to the query string
    so that the login view can redirect back to that URL.

    :param login_view: The name of the login view. (Alternately, the actual
                       URL to the login view.)
    :type login_view: str
    :param next_url: The URL to give the login view for redirection.
    :type next_url: str
    :param next_field: What field to store the next URL in. (It defaults to
                       ``next``.)
    :type next_field: str
    s   https://s   http://t   /i   t   sort(   s   https://s   http://R   N(
   t
   startswithR   R%   t   listR   R   R   R   R}   R   (   R&   t   next_urlt
   next_fieldt   baset   partst   md(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyRR   N  s    	c          O   s   | j  d  } t |  } g  |  D]* } t | t  r= | n | j d  ^ q" } d j |  } t j | | t  j	   } t
 | d  r | j d  } n  | S(   sL  
    This will create a secure token that you can use as an authentication
    token for your users. It uses heavy-duty HMAC encryption to prevent people
    from guessing the information. (To make it even more effective, if you
    will never need to regenerate the token, you can  pass some random data
    as one of the arguments.)

    :param \*args: The data to include in the token.
    :type args: args
    :param \*\*options: To manually specify a secret key, pass ``key=THE_KEY``.
        Otherwise, the ``current_app`` secret key will be used.
    :type \*\*options: kwargs
    t   keys   utf-8t    R   (   RI   t   _secret_keyR   t   bytest   encodet   joint   hmact   newR   t	   hexdigestR   R   (   t   argst   optionsR   t   sR   R   t   token_value(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   make_secure_tokenm  s    7c           C   s   t  j d t  S(   s>   
    This returns ``True`` if the current login is fresh.
    Ry   (   R   RI   RJ   (    (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   login_fresh  s    c         C   s   | r |  j    r t St |  t j j    } | t d <t t d <t   t d <| rd d t d <n  |  t	 j
 _ t j t j   d t   t S(   s  
    Logs a user in. You should pass the actual user object to this. If the
    user's `is_active` method returns ``False``, they will not be logged in
    unless `force` is ``True``.

    This will return ``True`` if the log in attempt succeeds, and ``False`` if
    it fails (i.e. because the user is inactive).

    :param user: The user object to log in.
    :type user: object
    :param remember: Whether to remember the user after their session expires.
        Defaults to ``False``.
    :type remember: bool
    :param force: If the user is inactive, setting this to ``True`` will log
        them in regardless. Defaults to ``False``.
    :type force: bool
    R^   Ry   Rw   R   Rg   R`   (   R   RJ   R   R   RE   R7   R   R}   Rz   R   R_   R`   t   user_logged_inRP   RQ   R   (   R`   Rg   t   forceR^   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt
   login_user  s    

c          C   s   d t  k r t  j d  n  d t  k r8 t  j d  n  t j j d t  }  |  t j k ri d t  d <n  t   } | d k	 r | j
   r t j t j   d | n  t j j   t S(   s   
    Logs a user out. (You do not need to pass the actual user.) This will
    also clean up the remember me cookie if it exists.
    R^   Ry   Re   Rh   Rg   R`   N(   R   R   R   RH   RI   Rk   R
   Rl   R   R%   R   t   user_logged_outRP   RQ   RE   Rc   R}   (   Rs   R`   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyRa     s    	c           C   s.   t  t d <t   t d <t j t j    d S(   sq   
    This sets the current session as fresh. Sessions become stale when they
    are reloaded from a cookie.
    Ry   Rw   N(   R}   R   Rz   t   user_login_confirmedRP   R   RQ   (    (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   confirm_login  s    
c            s   t       f d    } | S(   s  
    If you decorate a view with this, it will ensure that the current user is
    logged in and authenticated before calling the actual view. (If they are
    not, it calls the :attr:`LoginManager.unauthorized` callback.) For
    example::

        @app.route('/post')
        @login_required
        def post():
            pass

    If there are only certain times you need to require that your user is
    logged in, you can do so with::

        if not current_user.is_authenticated():
            return current_app.login_manager.unauthorized()

    ...which is essentially the code that this function adds to your views.

    It can be convenient to globally turn off authentication when unit
    testing. To enable this, if either of the application
    configuration variables `LOGIN_DISABLED` or `TESTING` is set to
    `True`, this decorator will be ignored.

    :param func: The view function to decorate.
    :type func: function
    c             s?   t  j j r   |  |   St j   s2 t  j j   S  |  |   S(   N(   R   RE   RK   R   R   RT   (   R   t   kwargs(   t   func(    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   decorated_view  s
    (   R   (   R   R   (    (   R   sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   login_required  s    c            s   t       f d    } | S(   s  
    If you decorate a view with this, it will ensure that the current user's
    login is fresh - i.e. there session was not restored from a 'remember me'
    cookie. Sensitive operations, like changing a password or e-mail, should
    be protected with this, to impede the efforts of cookie thieves.

    If the user is not authenticated, :meth:`LoginManager.unauthorized` is
    called as normal. If they are authenticated, but their session is not
    fresh, it will call :meth:`LoginManager.needs_refresh` instead. (In that
    case, you will need to provide a :attr:`LoginManager.refresh_view`.)

    Behaves identically to the :func:`login_required` decorator with respect
    to configutation variables.

    :param func: The view function to decorate.
    :type func: function
    c             sU   t  j j r   |  |   St j   s2 t  j j   St   sH t  j j   S  |  |   S(   N(   R   RE   RK   R   R   RT   R   R]   (   R   R   (   R   (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR     s    	(   R   (   R   R   (    (   R   sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   fresh_login_required  s    	c           C   s?   t    r, t t j d  r, t j j   n  t t j d d   S(   NR`   (	   R   R   R   R_   R   RE   Rv   R   R%   (    (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR     s    c         C   s.   t  |  } t j | |  j d  t  j   S(   Ns   utf-8(   R   R   R   R   R   R   (   R   R   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR     s    c          C   s:   t  j j d t  j  }  |  d  k	 r6 |  j d  }  n  |  S(   Ns   X-Forwarded-Fors   utf-8(   R
   Ro   RI   t   remote_addrR%   R   (   t   address(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   _get_remote_addr%  s    c          C   s   t  j j d  }  |  d  k	 r0 |  j d  }  n  d j t   |   } t t k ri t	 | d d d } n  t
   } | j | j d   | j   S(   Ns
   User-Agents   utf-8s   {0}|{1}t   errorst   replacet   utf8(   R
   Ro   RI   R%   R   R   R   R   R   R   R   t   updateR   (   t
   user_agentR   t   h(    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyRz   ,  s    	c           C   s   t  d t    S(   NR   (   t   dictR   (    (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyRM   8  s    c         C   sA   |  d  k r t j d }  n  t |  t  r= |  j d  }  n  |  S(   Nt
   SECRET_KEYt   latin1(   R%   R   RH   R   R   R   (   R   (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyR   <  s
    s	   logged-ins
   logged-outs   loaded-from-cookies   loaded-from-headers   loaded-from-requests   login-confirmedRT   s   needs-refresht   accesseds   session-protected(Y   R   t   __version_info__R   t   __version__t
   __author__t   __license__t   __copyright__t   __all__t   flaskR   R   R   R   R	   R
   R   R   R   t   flask.signalsR   t   werkzeug.localR   t   werkzeug.securityR   t   werkzeug.urlsR   R   R   R   t	   functoolsR   t   hashlibR   R   R   R?   R   t   versionR   R   t   urllib.parseR   R   t   _signalsR   Rk   R   R%   R   RJ   R   R'   R)   R,   R.   R6   Rf   R   R   R   R#   R   R   R   RR   R   R   R   Ra   R   R   R   R   R   R   Rz   RM   R   t   signalR   R   R   R   R   R   RO   R\   Ri   R|   (    (    (    sQ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask_login.pyt   <module>   s   	@	 +					"		
	&					