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


Python Configurator.add_route_predicate方法代码示例

本文整理汇总了Python中pyramid.config.Configurator.add_route_predicate方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_route_predicate方法的具体用法?Python Configurator.add_route_predicate怎么用?Python Configurator.add_route_predicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.config.Configurator的用法示例。


在下文中一共展示了Configurator.add_route_predicate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route_predicate [as 别名]
def main(argv=sys.argv):
	if len(argv) != 2:
		usage(argv)
	config_uri = argv[1]
	setup_logging(config_uri)
	settings = get_appsettings(config_uri)
	engine = engine_from_config(settings, 'sqlalchemy.')
	DBSession.configure(bind=engine)
	cache.cache = cache.configure_cache(settings)

	config = Configurator(
		settings=settings,
		root_factory=RootFactory,
		locale_negotiator=locale_neg
	)
	config.add_route_predicate('vhost', VHostPredicate)
	config.add_view_predicate('vhost', VHostPredicate)

	mmgr = config.registry.getUtility(IModuleManager)
	mmgr.load('core')
	mmgr.load_enabled()

	rts = rt.configure(mmgr, config.registry)
	app = rts.app()
	rt.run(rts, app)
开发者ID:baloon11,项目名称:npui,代码行数:27,代码来源:rtd.py

示例2: setup_config

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route_predicate [as 别名]
def setup_config(settings):
    global inst_id

    settings['netprofile.debug'] = asbool(settings.get('netprofile.debug'))
    if 'netprofile.instance_id' in settings:
        inst_id = settings.get('netprofile.instance_id')
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    cache.cache = cache.configure_cache(settings)

    config = Configurator(settings=settings,
                          root_factory=RootFactory,
                          locale_negotiator=locale_neg)
    config.add_route_predicate('vhost', VHostPredicate)
    config.add_view_predicate('vhost', VHostPredicate)
    config.include('netprofile.common.crypto')
    return config
开发者ID:unikmhz,项目名称:npui,代码行数:19,代码来源:__init__.py

示例3: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route_predicate [as 别名]
def main(global_config, **settings):
    """This function returns a Pyramid WSGI application."""
    config = Configurator(settings=settings)
    config.include('pyramid_chameleon')

    config.add_directive(
        'add_cors_preflight_handler', add_cors_preflight_handler)
    config.add_route_predicate('cors_preflight', CorsPreflightPredicate)

    config.add_subscriber(add_cors_to_response, 'pyramid.events.NewResponse')

    config.add_route(
        'cors-options-preflight', '/{catch_all:.*}',
        cors_preflight=True,
    )
    config.add_view(
        cors_options_view,
        route_name='cors-options-preflight',
        permission=NO_PERMISSION_REQUIRED,
    )

    config.add_renderer('prettyjson', JSON(indent=4, sort_keys=True))
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('programs', '/playlist')
    config.add_route('program-type-list', '/program-type-list')
    config.add_route('program-type-news', '/program-type-news')
    config.add_route('playlist', '/playlist/{playlist_id}')
    config.add_route('playlist-per-type', '/type-playlist/{playlist_id}')
    config.add_route('radio', '/radio')
    config.add_route('radio-program-type-list', '/radio-program-type-list')
    config.add_route('radio-playlist-per-type', '/type-rplaylist/{playlist_id}')
    config.add_route('radio-stations', '/radio-stations')
    config.add_route('radio-station-program-list', '/radio-station-programs/{station_id}')
    config.add_route('radioplaylist', '/rplaylist/{playlist_id:[a-zA-Z0-9\.\-\/]+}')
    config.add_route('episode', '/episode/{episode_url:[a-zA-Z0-9\.\-\/]+}')
    config.scan()
    return config.make_wsgi_app()
开发者ID:erral,项目名称:eitbapi,代码行数:40,代码来源:__init__.py

示例4: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route_predicate [as 别名]
def main(global_config, **settings):
    config = Configurator(
        autocommit=True,
        settings=settings,
        authentication_policy=AuthenticationPolicy(settings['auth.file'], __name__),
        authorization_policy=AuthorizationPolicy(),
        route_prefix=route_prefix(settings),
    )
    config.include('pyramid_exclog')
    config.include("cornice")
    config.add_forbidden_view(forbidden)
    config.add_request_method(request_params, 'params', reify=True)
    config.add_request_method(authenticated_role, reify=True)
    config.add_request_method(extract_tender, 'tender', reify=True)
    config.add_request_method(check_accreditation)
    config.add_renderer('prettyjson', JSON(indent=4))
    config.add_renderer('jsonp', JSONP(param_name='opt_jsonp'))
    config.add_renderer('prettyjsonp', JSONP(indent=4, param_name='opt_jsonp'))
    config.add_subscriber(add_logging_context, NewRequest)
    config.add_subscriber(set_logging_context, ContextFound)
    config.add_subscriber(set_renderer, NewRequest)
    config.add_subscriber(beforerender, BeforeRender)
    config.scan("openprocurement.api.views.spore")
    config.scan("openprocurement.api.views.health")

    # tender procurementMethodType plugins support
    config.add_route_predicate('procurementMethodType', isTender)
    config.registry.tender_procurementMethodTypes = {}
    config.add_request_method(tender_from_data)
    config.add_directive('add_tender_procurementMethodType', register_tender_procurementMethodType)

    # search for plugins
    plugins = settings.get('plugins') and settings['plugins'].split(',')
    for entry_point in iter_entry_points('openprocurement.api.plugins'):
        if not plugins or entry_point.name in plugins:
            plugin = entry_point.load()
            plugin(config)

    # CouchDB connection
    db_name = os.environ.get('DB_NAME', settings['couchdb.db_name'])
    server = Server(settings.get('couchdb.url'), session=Session(retry_delays=range(10)))
    if 'couchdb.admin_url' not in settings and server.resource.credentials:
        try:
            server.version()
        except Unauthorized:
            server = Server(extract_credentials(settings.get('couchdb.url'))[0])
    config.registry.couchdb_server = server
    if 'couchdb.admin_url' in settings and server.resource.credentials:
        aserver = Server(settings.get('couchdb.admin_url'), session=Session(retry_delays=range(10)))
        config.registry.admin_couchdb_server = aserver
        users_db = aserver['_users']
        if SECURITY != users_db.security:
            LOGGER.info("Updating users db security", extra={'MESSAGE_ID': 'update_users_security'})
            users_db.security = SECURITY
        username, password = server.resource.credentials
        user_doc = users_db.get('org.couchdb.user:{}'.format(username), {'_id': 'org.couchdb.user:{}'.format(username)})
        if not user_doc.get('derived_key', '') or PBKDF2(password, user_doc.get('salt', ''), user_doc.get('iterations', 10)).hexread(int(len(user_doc.get('derived_key', '')) / 2)) != user_doc.get('derived_key', ''):
            user_doc.update({
                "name": username,
                "roles": [],
                "type": "user",
                "password": password
            })
            LOGGER.info("Updating api db main user", extra={'MESSAGE_ID': 'update_api_main_user'})
            users_db.save(user_doc)
        security_users = [username, ]
        if 'couchdb.reader_username' in settings and 'couchdb.reader_password' in settings:
            reader_username = settings.get('couchdb.reader_username')
            reader = users_db.get('org.couchdb.user:{}'.format(reader_username), {'_id': 'org.couchdb.user:{}'.format(reader_username)})
            if not reader.get('derived_key', '') or PBKDF2(settings.get('couchdb.reader_password'), reader.get('salt', ''), reader.get('iterations', 10)).hexread(int(len(reader.get('derived_key', '')) / 2)) != reader.get('derived_key', ''):
                reader.update({
                    "name": reader_username,
                    "roles": ['reader'],
                    "type": "user",
                    "password": settings.get('couchdb.reader_password')
                })
                LOGGER.info("Updating api db reader user", extra={'MESSAGE_ID': 'update_api_reader_user'})
                users_db.save(reader)
            security_users.append(reader_username)
        if db_name not in aserver:
            aserver.create(db_name)
        db = aserver[db_name]
        SECURITY[u'members'][u'names'] = security_users
        if SECURITY != db.security:
            LOGGER.info("Updating api db security", extra={'MESSAGE_ID': 'update_api_security'})
            db.security = SECURITY
        auth_doc = db.get(VALIDATE_DOC_ID, {'_id': VALIDATE_DOC_ID})
        if auth_doc.get('validate_doc_update') != VALIDATE_DOC_UPDATE % username:
            auth_doc['validate_doc_update'] = VALIDATE_DOC_UPDATE % username
            LOGGER.info("Updating api db validate doc", extra={'MESSAGE_ID': 'update_api_validate_doc'})
            db.save(auth_doc)
        # sync couchdb views
        sync_design(db)
        db = server[db_name]
    else:
        if db_name not in server:
            server.create(db_name)
        db = server[db_name]
        # sync couchdb views
        sync_design(db)
#.........这里部分代码省略.........
开发者ID:yshalenyk,项目名称:openprocurement.api,代码行数:103,代码来源:__init__.py

示例5: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route_predicate [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    from pymongo import MongoClient
    from pyramid.authorization import ACLAuthorizationPolicy
    from pyramid.config import Configurator
    from pyramid.security import NO_PERMISSION_REQUIRED

    from hel.resources import Root
    from hel.utils.authentication import (
        HELAuthenticationPolicy,
        get_user,
        is_logged_in
    )

    # Auth
    auth_secret = "巏⇟ू攛劈ᜤ漢࿅䓽奧䬙摀曇䰤䙙൪ᴹ喼唣壆"
    if 'AUTH_SECRET' in os.environ:  # pragma: no cover
        auth_secret = os.environ["AUTH_SECRET"]
    authentication_policy = HELAuthenticationPolicy(
            auth_secret, hashalg='sha512', reissue_time=0)
    authorization_policy = ACLAuthorizationPolicy()

    # Custom config settings
    settings['activation.length'] = int(settings.get(
        'activation.length', '64'))
    settings['activation.time'] = int(settings.get(
        'activation.time', '3600'))
    settings['controllers.packages.list_length'] = int(settings.get(
        'controllers.packages.list_length', '20'))
    settings['controllers.users.list_length'] = int(settings.get(
        'controllers.users.list_length', '20'))

    settings['authentication.salt'] = (b'\xc4x\xc1\x1a\x0f\xa5$\xb1\x95AT\x03'
                                       b'\x8d\x03bk\xfc\xe9\x1c\x88')
    if 'AUTH_SALT' in os.environ:
        settings['authentication.salt'] = os.environ['AUTH_SALT'].encode()

    config = Configurator(settings=settings, root_factory=Root)

    config.add_route_predicate('cors_preflight', CorsPreflightPredicate)
    config.add_subscriber(add_cors_to_response, 'pyramid.events.NewResponse')

    config.add_route(
        'cors-options-preflight', '/{catch_all:.*}',
        cors_preflight=True)
    config.add_view(
        cors_options_view,
        route_name='cors-options-preflight',
        permission=NO_PERMISSION_REQUIRED,
    )

    config.set_authentication_policy(authentication_policy)
    config.set_authorization_policy(authorization_policy)
    config.include('pyramid_chameleon')
    config.add_renderer('json', MongoJSONRenderer)
    config.add_static_view('static', 'static', cache_max_age=3600)

    # Setup MongoDB
    url = 'mongodb://localhost:27017/'
    if 'MONGODB_URL' in os.environ:  # pragma: no cover
        url = os.environ['MONGODB_URL']
    elif 'mongo_db_url' in settings:  # pragma: no cover
        url = settings['mongo_db_url']
    config.registry.mongo = MongoClient(url)

    def add_db(request):
        return config.registry.mongo.hel
    config.add_request_method(add_db, 'db', reify=True)

    def get_version(request):
        return VERSION
    config.add_request_method(get_version, 'version', reify=True)

    # Auth again
    config.add_request_method(get_user, 'user', reify=True)
    config.add_request_method(is_logged_in, 'logged_in', reify=True)

    # Setup routes
    config.add_route('auth', '/auth')
    config.add_route('curuser', '/profile')
    config.scan()
    return config.make_wsgi_app()
开发者ID:hel-repo,项目名称:hel,代码行数:85,代码来源:__init__.py


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