本文整理汇总了Python中pyramid.configuration.Configurator.add_subscriber方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_subscriber方法的具体用法?Python Configurator.add_subscriber怎么用?Python Configurator.add_subscriber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.configuration.Configurator
的用法示例。
在下文中一共展示了Configurator.add_subscriber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator()
config.begin()
db_uri = settings['db_uri']
server_url = settings['server_url']
conn = Connection(db_uri)
config.registry.settings['db_conn'] = conn
config.registry.settings['server_url'] = server_url
config.registry.settings['db_name'] = settings['db_name']
config.add_subscriber(add_mongo_db, NewRequest)
config.include('pyramid_zcml')
config.load_zcml('configure.zcml')
config.end()
#add renderer
#Fixme: try to insert this on zcml file
config.add_renderer('jsonp', JSONP(param_name='callback'))
return config.make_wsgi_app()
示例2: registerSubscriber
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_subscriber [as 别名]
def registerSubscriber(subscriber, iface=Interface):
""" Register a ZCA subscriber component.
The ``subscriber`` argument specifies the implementation of the
subscriber component (often a function).
The ``iface`` argument is the interface type for which the
subscriber will be registered (:class:`zope.interface.Interface`
by default). If ``iface`` is not a tuple or list, it will be
converted to a one-tuple before being passed to the underlying ZCA
:meth:`pyramid.registry.registerHandler` method.
See `The ZCA book <http://www.muthukadan.net/docs/zca.html>`_ for
more information about ZCA subscribers.
.. warning:: This API is deprecated as of :app:`Pyramid` 1.0.
Instead use the
:meth:`pyramid.configuration.Configurator.add_subscriber`
method in your unit and integration tests.
"""
registry = get_current_registry()
config = Configurator(registry)
return config.add_subscriber(subscriber, iface=iface)