当前位置: 首页>>代码示例>>Python>>正文


Python events.NewRequest方法代码示例

本文整理汇总了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) 
开发者ID:mikeckennedy,项目名称:restful-services-in-pyramid,代码行数:20,代码来源:__init__.py

示例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) 
开发者ID:mikeckennedy,项目名称:restful-services-in-pyramid,代码行数:16,代码来源:__init__.py

示例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) 
开发者ID:mikeckennedy,项目名称:restful-services-in-pyramid,代码行数:16,代码来源:__init__.py

示例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() 
开发者ID:sayoun,项目名称:pyvac,代码行数:31,代码来源:__init__.py


注:本文中的pyramid.events.NewRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。