Commits

Lynn Rees committed 604950d

[svn]

Comments (0)

Files changed (1)

trunk/wsgiauth/base.py

 import time
 from urllib import quote
 from datetime import datetime
-from util import request_uri
-from util import extract
+from util import extract, request_path, Response
     
 
-__all__ = ['BaseAuth', 'Scheme', 'HTTPAuth', 'AuthResponse']
+__all__ = ['BaseAuth', 'Scheme', 'HTTPAuth']
 
 # Default authorization response template
 TEMPLATE = '''<html>
 _tracker = dict()
 
 
-class AuthResponse(object):
-
-    def __init__(self, message=None, template=None):
-        # Authorization message
-        self.response = message or self._response        
-        # Authorization response template
-        self.template = template or TEMPLATE
-
-    def __call__(self, environ, start_response):
-        start_response('200 OK', [('Content-type', 'text/html')])
-        return self.response(environ)
-
-    def _response(self, environ): 
-        '''Returns an iterator containing a message body.'''
-        return [self.template % request_uri(environ, False)]
-
-
 class BaseAuth(object):
 
     '''Base class for authentication persisting.'''
         # Token value encoder
         self.compute = kw.get('compute', self._compute)
         # Authorization response
-        self.response = kw.get('response', AuthResponse)
+        self.response = kw.get('response', Response(template=TEMPLATE))
         # Token name
         self.name = kw.get('name', self.fieldname)
         # Token tracking store
 
     def _gettoken(self, environ):
         '''Generates authentication tokens.'''
-        user = environ['REMOTE_USER']
-        path = quote(environ['SCRIPT_NAME']) + quote(environ['PATH_INFO'])
+        user, path = environ['REMOTE_USER'], request_path(environ)
         agent = environ['HTTP_USER_AGENT']
         raddr, server = environ['REMOTE_ADDR'], environ['SERVER_NAME']
         # Onetime secret
     'wrong credentials (e.g., bad password), or your browser\r\n' \
     'does not understand how to supply the credentials required.' 
     
-
     def __init__(self, realm, authfunc, **kw):
         self.realm, self.authfunc = realm, authfunc
         # WSGI app that sends a 401 response
         self.scheme = scheme.authtype
 
     def __call__(self, environ, start_response):
-        user = environ.get('REMOTE_USER')
-        if user is None:
+        if environ.get('REMOTE_USER') is None:
             result = self.authenticate(environ)
             if not isinstance(result, str):
                 return result(environ, start_response)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.