def authenticated(method):
 @functools.wraps(method)
 def wrapper(self, *args, **kwargs):
  if (not self.current_user):
   if (self.request.method in ('GET', 'HEAD')):
    url = self.get_login_url()
    if ('?' not in url):
     if urlparse.urlsplit(url).scheme:
      next_url = self.request.full_url()
     else:
      next_url = self.request.uri
     url += ('?' + urlencode(dict(next=next_url)))
    self.redirect(url)
    return
   raise HTTPError(403)
  return method(self, *args, **kwargs)
 return wrapper

def authenticated ( method ) : @ functools . wraps ( method ) def wrapper ( self , * args , ** kwargs ) : if ( not self . current_user ) : if ( self . request . method in ( 'GET' , 'HEAD' ) ) : url = self . get_login_url ( ) if ( '?' not in url ) : if urlparse . urlsplit ( url ) . scheme : next_url = self . request . full_url ( ) else : next_url = self . request . uri url += ( '?' + urlencode ( dict ( next = next_url ) ) ) self . redirect ( url ) return raise HTTPError ( 403 ) return method ( self , * args , ** kwargs ) return wrapper
wrap request handler methods with this decorator to require that the user be logged in .