本文整理汇总了Python中pyramid.events.NewRequest方法的典型用法代码示例。如果您正苦于以下问题:Python events.NewRequest方法的具体用法?Python events.NewRequest怎么用?Python events.NewRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.events
的用法示例。
在下文中一共展示了events.NewRequest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: allow_cors
# 需要导入模块: from pyramid import events [as 别名]
# 或者: from pyramid.events import NewRequest [as 别名]
def allow_cors(config, log):
def add_cors_headers_response_callback(event):
def cors_headers(_, response):
# log.trace("Adding CORS permission to request: {}".format(
# request.url
# ))
response.headers.update({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST,GET,DELETE,PUT,OPTIONS',
'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept, Authorization',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Max-Age': '1728000',
})
event.request.add_response_callback(cors_headers)
log.info("Configuring Pyramid for CORS permissions")
config.add_subscriber(add_cors_headers_response_callback, NewRequest)
示例2: allow_cors
# 需要导入模块: from pyramid import events [as 别名]
# 或者: from pyramid.events import NewRequest [as 别名]
def allow_cors(config):
def add_cors_headers_response_callback(event):
def cors_headers(_, response):
response.headers.update({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST,GET,DELETE,PUT,OPTIONS',
'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept, Authorization',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Max-Age': '1728000',
})
event.request.add_response_callback(cors_headers)
config.add_subscriber(add_cors_headers_response_callback, NewRequest)
示例3: allow_cors
# 需要导入模块: from pyramid import events [as 别名]
# 或者: from pyramid.events import NewRequest [as 别名]
def allow_cors(config):
def add_cors_headers_response_callback(event):
def cors_headers(_, response):
print("Adding headers")
response.headers.update({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST,GET,DELETE,PUT,OPTIONS',
'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept, Authorization',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Max-Age': '1728000',
})
event.request.add_response_callback(cors_headers)
config.add_subscriber(add_cors_headers_response_callback, NewRequest)
示例4: main
# 需要导入模块: from pyramid import events [as 别名]
# 或者: from pyramid.events import NewRequest [as 别名]
def main(global_config, **settings):
settings = dict(settings)
# Scoping sessions for Pyramid ensure session are commit/rollback
# after the template has been rendered
create_engine(settings, scoped=True)
session_factory = UnencryptedCookieSessionFactoryConfig(
settings['pyvac.cookie_key']
)
authn_policy = RouteSwithchAuthPolicy(secret=settings['pyvac.cookie_key'],
callback=groupfinder)
authz_policy = ACLPolicy()
config = Configurator(settings=settings,
root_factory=RootFactory,
locale_negotiator=locale_negotiator,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
session_factory=session_factory)
config.add_subscriber('pyvac.helpers.i18n.add_renderer_globals',
IBeforeRender)
config.add_subscriber('pyvac.helpers.i18n.add_localizer', NewRequest)
config.end()
return config.make_wsgi_app()