changeset 12:2efb1b30da4a

fix typos; now works, more or less
author egj@socialplanning.org
date Tue, 05 Jan 2010 18:18:35 +0000
parents 6fc4f426b8d4
children b6d63e78d396
files bitsyauth/minimal.py
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyauth/minimal.py	Tue Jan 05 12:54:28 2010 -0500
+++ b/bitsyauth/minimal.py	Tue Jan 05 18:18:35 2010 +0000
@@ -2,7 +2,7 @@
 
 import os
 
-def pw(basedir, user):
+def getpw(basedir, user):
     file = os.path.join(basedir, user, '.password')
 
     try:
@@ -20,25 +20,27 @@
 except ImportError:
     from md5 import md5
 def hash(user, pw, realm):
-    return md5("%s:%s:%s" (user, realm, pw)).hexdigest()
+    return md5("%s:%s:%s" % (user, realm, pw)).hexdigest()
 
 class BitsyblogFilespaceAuth(object):
     def __init__(self, realm, basedir):
         self.realm = realm
         self.basedir = basedir
     def __call__(self, user, pw):
-        stored = pw(self.basedir, user)
+        stored = getpw(self.basedir, user)
         if stored is None:
             return False
         return hash(user, pw, self.realm) == stored
 
-def filter_factory(app, global_conf, realm, basedir):
+def filter_factory(global_conf, realm=None, basedir=None):
     #from paste.util.import_string import eval_import
     #authfunc = eval_import(authfunc)
 
     authfunc = BitsyblogFilespaceAuth(realm, basedir)
 
-    return BasicAuthMiddleware(app, realm, authfunc)
+    def filter(app):        
+        return BasicAuthMiddleware(app, realm, authfunc)
+    return filter
 
 class BasicAuthMiddleware(object):
     def __init__(self, app, realm, auth_checker):
@@ -49,12 +51,12 @@
     def __call__(self, environ, start_response):
         req = Request(environ)
 
-        header = req.headers.get('AUTHORIZATION')
+        header = req.authorization
         if not header:
             return self.app(environ, start_response)
 
         (method, auth) = header.split(' ', 1)
-        if method != 'basic':
+        if method.lower() != 'basic':
             return self.app(environ, start_response)
 
         auth = auth.strip().decode('base64')