我正在尝试implement my own authentication method for AuthKit,并试图弄清楚一些内置方法是如何工作的。特别是,我正在尝试弄清楚如何正确地更新environ的REMOTE_USER。
这就是在authkit.authenticate.basic中处理它的方式,但它非常令人困惑。我找不到任何定义了REMOTE_USER和AUTH_TYPE的地方。这里发生了什么奇怪的事情吗?如果有,是什么?
def __call__(self, environ, start_response):
environ['authkit.users'] = self.users
result = self.authenticate(environ)
if isinstance(result, str):
AUTH_TYPE.update(environ, 'basic')
REMOTE_USER.update(environ, result)
return self.application(environ, start_response)实际上有很多像这样的大写字母,我找不到它的定义。例如,AUTHORIZATION从何而来:
def authenticate(self, environ):
authorization = AUTHORIZATION(environ)
if not authorization:
return self.build_authentication()
(authmeth, auth) = authorization.split(' ',1)
if 'basic' != authmeth.lower():
return self.build_authentication()
auth = auth.strip().decode('base64')
username, password = auth.split(':',1)
if self.authfunc(environ, username, password):
return username
return self.build_authentication()我觉得我可能遗漏了Python的一些特殊语法处理,但可能还有一些非常奇怪的事情,对于像我这样刚接触environ的人来说并不是很明显。
发布于 2010-03-18 10:09:16
看看那个来源,我发现它有一个(邪恶的)
from paste.httpheaders import *这是另一种方式-神秘的名字可能突然出现在代码中(这就是为什么这个习惯用法是一个非常非常糟糕的做法)。我不能确定这些标识符是如何突然莫名其妙地出现的,但这是有可能的。
https://stackoverflow.com/questions/2467013
复制相似问题