Python 如何传输url参数以重新定位自定义谓词检查器

Python 如何传输url参数以重新定位自定义谓词检查器,python,authentication,permissions,turbogears2,repoze.who,Python,Authentication,Permissions,Turbogears2,Repoze.who,我想创建一个repose自定义谓词检查器,它能够访问url参数并验证某些内容。但我想使用allow_仅在控制器的所有范围内设置此权限检查器。比如: class MyController(BaseController): allow_only = All(not_anonymous(msg=l_(u'You must be logged on')), my_custom_predicate(msg=l_(u'something wrong')))

我想创建一个repose自定义谓词检查器,它能够访问url参数并验证某些内容。但我想使用allow_仅在控制器的所有范围内设置此权限检查器。比如:

class MyController(BaseController):

    allow_only = All(not_anonymous(msg=l_(u'You must be logged on')),
                     my_custom_predicate(msg=l_(u'something wrong')))

    def index(self, **kw):
        return dict()
然后,my_custom_谓词应该检查每个MyController方法中每个请求的url参数,并执行它所做的任何操作。
问题在于:如何允许我的_custom_谓词检查url参数,就像我上面写的那样使用它。

可能是您需要使用ControllerProtector

from repoze.what.plugins.pylonshq import ControllerProtector

allow_only = All(not_anonymous(msg=l_(u'You must be logged on')),
                     my_custom_predicate(msg=l_(u'something wrong')))

@ControllerProtector(allow_only)
class MyController(BaseController):

    def index(self, **kw):
        return dict()

参见文档中的

Ok,这与仅在控制器范围内使用allow_非常相似。但是我的自定义谓词如何知道传递给索引的**kw值呢?请使用全局请求对象。kw=请求环境['pylons.routes_dict']