本文整理汇总了Python中pyramid.config.Configurator.add_subscriber方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_subscriber方法的具体用法?Python Configurator.add_subscriber怎么用?Python Configurator.add_subscriber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_subscriber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.add_renderer('.html', mako_factory)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('new', '/')
config.add_route('quiz', '/user/{username}/account/{account_type}')
config.add_route('posting', '/posting')
config.add_route('notloggedin', '/notloggedin')
config.add_route('loginerror', '/loginerror')
config.add_route('saranghae100', '/saranghae100')
# MongoDB Setting
db_url = urlparse(settings['mongo_uri'])
conn = pymongo.Connection(host=db_url.hostname, port=db_url.port)
config.registry.settings['db_conn'] = conn
def add_mongo_db(event):
settings = event.request.registry.settings
db = settings['db_conn'][db_url.path[1:]]
if db_url.username and db_url.password:
db.authenticate(db_url.username, db_url.password)
event.request.db = db
config.add_subscriber(add_mongo_db, NewRequest)
config.scan()
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
authentication_policy = AuthTktAuthenticationPolicy('lrrrftht', callback=groupfinder)
authorization_policy = ACLAuthorizationPolicy()
config = Configurator(authentication_policy=authentication_policy, authorization_policy=authorization_policy, settings=settings, root_factory='datinggame.models.RootFactory')
#set up the database and have it append to each request
db_uri = settings['db_uri']
conn = pymongo.Connection(db_uri)
config.registry.settings['db_conn'] = conn
config.add_subscriber(add_mongo_db, NewRequest)
config.add_static_view('static', 'datinggame:static', cache_max_age=3600)
#add the routes here -- they will be specified with a decorator in the views file
config.add_route('root', '')
config.add_route('logout', '/logout')
config.add_route('login', '/login')
config.add_route('start', '/start')
config.add_route('signup', '/signup')
config.add_route('edit','/edit')
config.add_route('editpicture','/editpicture')
config.add_route('profilepic','/profilepic/{pic_id}')
config.add_route('messagethread', '/messages/{username}')
config.add_route('favicon', "/favicon.ico")
config.add_route('user', '/{username}')
config.scan()
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings['sqlalchemy.url'] = settings['cn.dialect'] + quote_plus(settings['sqlalchemy.url'])
engine = engine_from_config(settings, 'sqlalchemy.')
dbConfig['url'] = settings['sqlalchemy.url']
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)
Base.metadata.reflect(views=True, extend_existing=False)
config = Configurator(settings=settings)
# Add renderer for datetime objects
json_renderer = JSON()
json_renderer.add_adapter(datetime, datetime_adapter)
json_renderer.add_adapter(Decimal, decimal_adapter)
json_renderer.add_adapter(bytes, bytes_adapter)
config.add_renderer('json', json_renderer)
# Set up authentication and authorization
includeme(config)
# config.set_root_factory(SecurityRoot)
# config.set_request_factory(request_factory)
config.add_subscriber(add_cors_headers_response_callback, NewRequest)
# Set the default permission level to 'read'
config.set_default_permission('read')
config.include('pyramid_tm')
add_routes(config)
config.scan()
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
session_factory = session_factory_from_settings(settings)
config = Configurator(settings=settings,
session_factory=session_factory)
config.include('pyramid_mailer')
config.add_translation_dirs(
'colander:locale/',
'deform:locale/',
'c3sintent:locale/')
config.add_static_view('static',
'c3sintent:static', cache_max_age=3600)
config.add_subscriber('c3sintent.subscribers.add_base_template',
'pyramid.events.BeforeRender')
config.add_subscriber('c3sintent.subscribers.add_locale_to_cookie',
'pyramid.events.NewRequest')
# home /
# membership application form
config.add_route('intent', '/')
config.scan()
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
from nokkhumapi.security import TokenAuthenticationPolicy
authn_policy = TokenAuthenticationPolicy()
authz_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings, root_factory='nokkhumapi.acl.RootFactory',
authentication_policy=authn_policy, authorization_policy=authz_policy)
from .routing import add_routes
add_routes(config)
config.scan('nokkhumapi.views')
from .models import initial
initial(config.registry.settings)
modify_json_renderer(config)
from .security import SecretManager, RequestWithUserAttribute
config.set_request_factory(RequestWithUserAttribute)
secret_manager = SecretManager(settings.get('nokkhum.auth.secret'))
config.registry.settings['secret_manager'] = secret_manager
config.add_subscriber(add_response_callback, NewRequest)
return config.make_wsgi_app()
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings)
config.include("cornice")
config.include('semantica_rt_py.renderer')
config.add_subscriber(init_redis_sucker, ApplicationCreated)
config.scan("semantica_rt_py.views")
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
session_config = session_factory_from_settings(settings)
config = Configurator(settings=settings, session_factory=session_config, root_factory='.models.RootFactory')
config.set_authentication_policy(authetntication_policy)
config.set_authorization_policy(authorization_policy)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_renderer('.html', mako_factory)
config.add_route('home', '/')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('about', '/about')
config.add_route('contact', '/contact')
config.add_route('income', '/income')
config.add_route('income_category', '/income-category')
config.add_route('expense', '/expense')
config.add_route('expense_category', '/expense-category')
config.add_route('balance', '/balance')
config.add_subscriber('.subscribers.csrf_validation', NewRequest)
config.scan()
return config.make_wsgi_app()
示例8: yeastgenome_frontend
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def yeastgenome_frontend(backend_url, heritage_url, log_directory, **configs):
chosen_frontend = YeastgenomeFrontend(backend_url, heritage_url, log_directory)
settings = dict(configs)
settings.setdefault('jinja2.i18n.domain', 'myproject')
configurator = Configurator(settings=settings)
configurator.add_translation_dirs('locale/')
configurator.include('pyramid_jinja2')
# set global template var asset_root to read from cloudfront or local, depending on .ini value, default to False
production_assets = configs.get('production_assets', False)
if production_assets == 'True':
file_path = os.path.dirname(os.path.realpath(__file__)) + '/../../../../production_asset_url.json'
asset_root = json.load(open(file_path, 'r'))['url']
else:
asset_root = '/static'
# put query string in global template variable
def add_template_global(event):
event['asset_root'] = asset_root
configurator.add_subscriber(add_template_global, 'pyramid.events.BeforeRender')
# cache everything for 1 month on browser
configurator.add_static_view('static', 'src:sgd/frontend/yeastgenome/static', cache_max_age=2629740)
configurator.add_static_view('img-domain', 'src:sgd/frontend/yeastgenome/img-domain', cache_max_age=2629740)
configurator.add_renderer('jsonp', JSONP(param_name='callback'))
return chosen_frontend, configurator
示例9: BaseEventTest
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
class BaseEventTest(BaseWebTest):
subscribed = tuple()
def setUp(self):
super(BaseEventTest, self).setUp()
self.events = []
self.body = {'data': {'name': 'de Paris'}}
def tearDown(self):
self.events = []
super(BaseEventTest, self).tearDown()
def listener(self, event):
self.events.append(event)
def make_app(self, settings=None):
settings = self.get_app_settings(settings)
self.config = Configurator(settings=settings)
for event_cls in self.subscribed:
self.config.add_subscriber(self.listener, event_cls)
self.config.commit()
app = testapp(config=self.config)
app = webtest.TestApp(app)
app.RequestClass = get_request_class(self.api_prefix)
return app
示例10: create_api
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def create_api(global_config, **settings):
settings = get_settings(global_config, **settings)
config = Configurator(settings=settings)
config.set_authentication_policy(remote_authn)
config.set_authorization_policy(acl_authz)
config.set_root_factory("h.api.resources.create_root")
config.add_renderer("json", JSON(indent=4))
config.add_subscriber("h.api.subscribers.set_user_from_oauth", "pyramid.events.ContextFound")
config.add_tween("h.api.tweens.auth_token")
config.include("h.features")
config.include("h.auth")
config.include("h.api.db")
config.include("h.api.views")
if config.registry.feature("queue"):
config.include("h.queue")
config.include("h.api.queue")
app = config.make_wsgi_app()
app = permit_cors(
app,
allow_headers=("Authorization", "X-Annotator-Auth-Token"),
allow_methods=("HEAD", "GET", "POST", "PUT", "DELETE"),
)
return app
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
initialize_sql(settings)
session_factory = session_factory_from_settings(settings)
set_cache_regions_from_settings(settings)
authentication_policy = AuthTktAuthenticationPolicy('somesecret')
authorization_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
session_factory=session_factory,
authentication_policy=authentication_policy,
authorization_policy=authorization_policy
)
config.add_subscriber(add_renderer_globals, BeforeRender)
config.add_subscriber(csrf_validation, NewRequest)
config.add_mako_renderer(".html")
config.add_static_view("static", "patchman:static", cache_max_age=3600)
config.add_static_view("store",settings["storage"], cache_max_age=3600)
MyRoutes(config)
config.scan()
return config.make_wsgi_app()
示例12: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
"""
This function returns a Pyramid WSGI application.
"""
# Modified from the pyramid cookbook
# Generate persistence objects
db_uri = 'localhost'
db_port = 27017
db_name = "traffic1"
conn = pymongo.Connection(db_uri, db_port)
db = conn[db_name]
# Store persistence objects for use during requests
settings['db_conn'] = conn
settings['db'] = db
config = Configurator(root_factory=Root, settings=settings)
config.add_static_view('static', 'trafmongo:static')
# This subscriber will make it easier to access the database objects
config.add_subscriber(add_mongo_db, NewRequest)
# Find views
config.scan('trafmongo')
return config.make_wsgi_app()
示例13: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
"""
config = Configurator(settings=settings, root_factory=Root)
config.include('pyramid_chameleon')
config.add_view('aci_test.views.my_view',
context='aci_test:resources.Root',
renderer='aci_test:templates/mytemplate.pt')
config.add_static_view('static', 'aci_test:static')
# MongoDB
def add_mongo_db(event):
settings = event.request.registry.settings
url = settings['mongodb.url']
db_name = settings['mongodb.db_name']
db = settings['mongodb_conn'][db_name]
event.request.db = db
db_uri = settings['mongodb.url']
MongoDB = pymongo.Connection
if 'pyramid_debugtoolbar' in set(settings.values()):
class MongoDB(pymongo.Connection):
def __html__(self):
return 'MongoDB: <b>{}></b>'.format(self)
conn = MongoDB(db_uri)
config.registry.settings['mongodb_conn'] = conn
config.add_subscriber(add_mongo_db, NewRequest)
config.scan('aci_test')
return config.make_wsgi_app()
示例14: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings["g"] = g = Globals(**settings)
config = Configurator(settings=settings
, root_factory=WebsiteRootContext
, session_factory = session_factory_from_settings(settings)
, authentication_policy= Security()
, authorization_policy= ACLAuthorizationPolicy()
, default_permission='view'
)
request.extend_request_traversal(config)
config.add_directive('add_mako_renderer', pyramid_mako.add_mako_renderer)
config.add_mako_renderer(".html")
config.add_mako_renderer(".xml")
config.add_renderer('json', jsonRenderer)
def _(request, string):
return string
config.add_request_method(_, '_')
config.add_subscriber(add_renderer_variables, 'pyramid.events.BeforeRender')
config.include("ufostart.handlers")
config.include("ufostart.admin")
config.scan()
return config.make_wsgi_app()
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_subscriber [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
logger = logging.getLogger('__init__')
logger.setLevel(logging.DEBUG)
logger.info('Application initialization...')
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
session_factory = session_factory_from_settings(settings)
config = Configurator(
settings=settings,
session_factory=session_factory
)
config.add_subscriber(
'similarimages.subscribers.add_base_template',
'pyramid.events.BeforeRender'
)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('upload', '/upload')
config.add_route('choose', '/choose')
config.add_route('result', '/result')
config.scan()
logger.info('Application initialization finished.')
return config.make_wsgi_app()