我正在使用 Pyramid 1.4a1 并且我有这个订阅者谓词:
class RouteName(object):
'''
Subscriber predicate to check against route name.
'''
def __init__(self, value, config):
self.value = value
self.config = config
def text(self):
return 'route_name = %s' % self.value
phash = text
def __call__(self, event):
route_name = event.request.matched_route.name
return route_name == self.value
我像这样添加它:
config.add_subscriber_predicate('route_name', RouteName)
但是,每当我尝试使用它时,就像这样:
@subscriber(ContextFound, route_name='user.register')
def check_invitation(event):
# Check invitation token before running registration view code ...
我得到这个回溯:
Traceback (most recent call last):
File "/Workspace/Personal/project/.env/bin/pserve", line 8, in <module>
load_entry_point('pyramid==1.4a1', 'console_scripts', 'pserve')()
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 47, in main
return command.run()
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 290, in run
relative_to=base, global_conf=vars)
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 318, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/util.py", line 56, in fix_call
val = callable(*args, **kw)
File "/Workspace/Personal/project/project/__init__.py", line 49, in main
return config.make_wsgi_app()
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/pyramid/config/__init__.py", line 955, in make_wsgi_app
self.commit()
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/pyramid/config/__init__.py", line 629, in commit
self.action_state.execute_actions(introspector=self.introspector)
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/pyramid/config/__init__.py", line 1083, in execute_actions
tb)
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/pyramid/config/__init__.py", line 1075, in execute_actions
callable(*args, **kw)
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/pyramid/config/adapters.py", line 53, in register
order, preds, phash = predlist.make(self, **predicates)
File "/Workspace/Personal/project/.env/local/lib/python2.7/site-packages/pyramid/config/util.py", line 264, in make
pred = predicate_factory(val, config)
pyramid.exceptions.ConfigurationExecutionError: <type 'exceptions.TypeError'>: object.__new__() takes no parameters
in:
Line 80 of file /Workspace/Personal/project/.env/local/lib/python2.7/site-packages/pyramid/events.py:
config.add_subscriber(wrapped, iface, **self.predicates)
我也有一个以相同方式注册的自定义视图谓词,它工作得很好,所以我不知道我在这里做错了什么。