Changeset 83
- Timestamp:
- 06/07/07 05:10:07
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
AuthKit/branches/0.4/authkit/authenticate/__init__.py
r79 r83 126 126 password = users.user(username)['password'] 127 127 return digest.digest_password(realm, username, password) 128 # After speaking to Clark Evans who wrote the origianl code, this is the correct thing: 128 # After speaking to Clark Evans who wrote the origianl code, this is the 129 # correct thing: 129 130 return None 130 131 … … 138 139 users = None 139 140 if len(authenticate_conf) < 1: 140 raise AuthKitConfigError('Expected at least one authenticate key, not %r'%authenticate_conf) 141 raise AuthKitConfigError('Expected at least one authenticate key, not' 142 ' %r'%authenticate_conf) 141 143 if authenticate_conf.keys() == ['function']: 142 144 function = authenticate_conf['function'] … … 185 187 template = None 186 188 if len(template_conf) != 1: 187 raise AuthKitConfigError('Expected one template entry, not %r'%(', '.join(template_conf.keys()))) 189 raise AuthKitConfigError('Expected one template entry, not %r' % 190 (', '.join(template_conf.keys()))) 188 191 if template_conf.keys()[0] not in ['string', 'file', 'obj']: 189 192 raise AuthKitConfigError("Template option can only be 'string', 'file' or 'obj'") … … 247 250 return self.app(environ, start_response) 248 251 252 class AddDictToEnviron(object): 253 """Simple middleware which adds the values of a dict to the environ.""" 254 def __init__(self, app, dct): 255 self.app = app 256 self.dct = dct 257 258 def __call__(self, environ, start_response): 259 environ.update(self.dct) 260 return self.app(environ, start_response) 261 249 262 class RequireEnvironKey(object): 250 def __init__(self, app, key, missing_error= 'Missing the key %(key)s from the environ. Have you setup the correct middleware?'):263 def __init__(self, app, key, missing_error=None): 251 264 self.app = app 252 265 self.key = key 253 self.missing_error = missing_error 266 self.missing_error = missing_error or \ 267 'Missing the key %(key)s from the environ. Have you setup the correct middleware?' 254 268 255 269 def __call__(self, environ, start_response): … … 343 357 raise AuthKitConfigError( 344 358 "Expected app_conf to be paste deploy app_conf dictionary " 345 "from not %r" %app_conf359 "from not %r" % app_conf 346 360 ) 347 361 … … 356 370 # Check to see if middleware is disabled 357 371 if asbool(all_conf.get('setup.enable', True)) == False: 358 warnings.warn( 359 "AuthKit middleware has been turned off by the config option authkit.setup.enable" 360 ) 372 warnings.warn("AuthKit middleware has been turned off by the config " 373 "option authkit.setup.enable") 361 374 return app 362 375 363 376 # Status Checking/Changing Middleware 364 intercept = [str(x).strip() for x in all_conf.get('setup.intercept','401').split(',')] 377 intercept = [str(x).strip() for x in \ 378 all_conf.get('setup.intercept','401').split(',')] 365 379 if not '401' in intercept: 366 380 warnings.warn( 367 "AuthKit is configured via the authkit.setup.intercept option not to intercept " 368 "401 responses so the authentication middleware will not be triggered even if " 369 "a 401 Unauthenticated response is returned." 370 ) 371 app = AddToEnviron(app, 'authkit.intercept', intercept) 381 "AuthKit is configured via the authkit.setup.intercept option not " 382 "to intercept 401 responses so the authentication middleware will " 383 "not be triggered even if a 401 Unauthenticated response is " 384 "returned.") 372 385 373 386 methods = [method.strip() for method in all_conf['setup.method'].split(',')] … … 375 388 for method in methods: 376 389 if method in ['setup','config']: 377 raise AuthKitConfigError("The name %s is reserved cannot be used as a method name"%method) 390 raise AuthKitConfigError("The name %s is reserved cannot be used " 391 "as a method name" % method) 378 392 if not available_methods.has_key(method): 379 393 raise AuthKitConfigError( … … 395 409 prefix=prefix_, 396 410 ) 397 398 app = AddToEnviron(app, 'authkit.config', strip_base(all_conf, 'config.')) 411 app = AddDictToEnviron(app, 412 {'authkit.config':strip_base(all_conf, 'config.'), 413 'authkit.intercept':intercept}) 399 414 return app 400 415
