當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。