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


Python Configurator.route_prefix方法代码示例

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


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

示例1: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import route_prefix [as 别名]
def main(global_config, **settings):
    config = Configurator(settings=settings)
    config.set_authentication_policy(AuthenticationPolicy(None))
    config.set_authorization_policy(AuthorizationPolicy())
    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(set_renderer, NewRequest)
    config.include("cornice")
    config.route_prefix = '/api/{}'.format(VERSION)
    config.scan("openprocurement.api.views")

    # CouchDB connection
    server = Server(settings.get('couchdb.url'))
    config.registry.couchdb_server = server
    db_name = os.environ.get('DB_NAME', settings['couchdb.db_name'])
    if db_name not in server:
        server.create(db_name)
    config.registry.db = server[db_name]

    # sync couchdb views
    sync_design(config.registry.db)

    # migrate data
    migrate_data(config.registry.db)

    # S3 connection
    if 'aws.access_key' in settings and 'aws.secret_key' in settings and 'aws.bucket' in settings:
        connection = S3Connection(settings['aws.access_key'], settings['aws.secret_key'])
        config.registry.s3_connection = connection
        bucket_name = settings['aws.bucket']
        if bucket_name not in [b.name for b in connection.get_all_buckets()]:
            connection.create_bucket(bucket_name, location=Location.EU)
        config.registry.bucket_name = bucket_name
    return config.make_wsgi_app()
开发者ID:gitter-badger,项目名称:openprocurement.api,代码行数:37,代码来源:__init__.py

示例2: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import route_prefix [as 别名]
def main(global_config, **settings):
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(settings=settings)

    # XXX Add client static files and index route for dev purpose only
    config.add_static_view('static', os.path.join(settings['client_dir'], 'static'), cache_max_age=3600)
    config.add_view('localfinance.views.index', route_name='index')
    config.add_route('index', '/')

    # API
    if settings['route_prefix']:
        config.route_prefix = settings['route_prefix']
    config.include("cornice")
    config.route_prefix = settings['route_prefix']
    config.scan("localfinance.views")
    return config.make_wsgi_app()
开发者ID:RouxRC,项目名称:nosfinanceslocales,代码行数:20,代码来源:__init__.py

示例3: test_kinto_core_includes_are_included_manually

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import route_prefix [as 别名]
    def test_kinto_core_includes_are_included_manually(self):
        config = Configurator(settings={**kinto.core.DEFAULT_SETTINGS})
        config.add_settings({'includes': 'elastic history'})
        config.route_prefix = 'v2'

        with mock.patch.object(config, 'include'):
            with mock.patch.object(config, 'scan'):
                kinto.core.includeme(config)

                config.include.assert_any_call('elastic')
                config.include.assert_any_call('history')
开发者ID:glasserc,项目名称:kinto,代码行数:13,代码来源:test_initialization.py

示例4: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import route_prefix [as 别名]
def main(global_config, **settings):
    config = Configurator(settings=settings)
    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(set_renderer, NewRequest)
    config.include("cornice")
    config.route_prefix = '/api/{}'.format(VERSION)
    config.scan("openprocurement.api.views")

    # CouchDB connection
    server = Server(settings.get('couchdb.url'))
    config.registry.couchdb_server = server
    db_name = os.environ.get('DB_NAME', settings['couchdb.db_name'])
    if db_name not in server:
        server.create(db_name)
    config.registry.db = server[db_name]

    # sync couchdb views
    sync_design(config.registry.db)

    # migrate data
    migrate_data(config.registry.db)
    return config.make_wsgi_app()
开发者ID:bbuz,项目名称:openprocurement.api,代码行数:26,代码来源:__init__.py

示例5: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import route_prefix [as 别名]
def main(global_config, **settings):
    Service.cors_origins = ("*",)

    settings = settings_expandvars(settings)
    config = Configurator(settings=settings, root_factory=RootFactory)
    config.include("cornice")

    # Redirect to the current version of the API if the prefix isn't used.
    config.add_route(name="redirect_to_version", pattern="/{path:(?!%s).*}" % API_VERSION)
    config.add_view(view=redirect_to_version, route_name="redirect_to_version")

    config.route_prefix = "/%s" % API_VERSION

    # Permission management

    policies = [
        BasicAuthAuthenticationPolicy(check_credentials),
        HawkAuthenticationPolicy(decode_hawk_id=get_credentials),
    ]
    authn_policy = MultiAuthenticationPolicy(policies)

    # Unauthorized view
    config.add_forbidden_view(forbidden_view)

    # Global permissions
    model_creators = settings.get("daybed.can_create_model", "Everyone")
    token_creators = settings.get("daybed.can_create_token", "Everyone")
    token_managers = settings.get("daybed.can_manage_token", None)

    authz_policy = DaybedAuthorizationPolicy(
        model_creators=build_list(model_creators),
        token_creators=build_list(token_creators),
        token_managers=build_list(token_managers),
    )
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    # We need to scan AFTER setting the authn / authz policies
    config.scan("daybed.views")

    # Attach the token to the request, coming from Pyramid as userid
    def get_credentials_id(request):
        try:
            credentials_id, _ = get_credentials(request, request.authenticated_userid)
            return credentials_id
        except ValueError:
            return None

    config.add_request_method(get_credentials_id, "credentials_id", reify=True)

    # Events

    # Helper for notifying events
    def notify(request, event, *args):
        klass = config.maybe_dotted("daybed.events." + event)
        event = klass(*(args + (request,)))
        request.registry.notify(event)

    config.add_request_method(notify, "notify")

    # Backend

    config.registry.tokenHmacKey = settings["daybed.tokenHmacKey"]

    # backend initialisation
    backend_class = config.maybe_dotted(settings["daybed.backend"])
    config.registry.backend = backend_class.load_from_config(config)

    # Indexing

    # Connect client to hosts in conf
    index_hosts = build_list(settings.get("elasticsearch.hosts", "localhost:9200"))
    indices_prefix = settings.get("elasticsearch.indices_prefix", "daybed_")
    config.registry.index = index = indexer.ElasticSearchIndexer(index_hosts, indices_prefix)

    # Suscribe index methods to API events
    config.add_subscriber(index.on_model_created, events.ModelCreated)
    config.add_subscriber(index.on_model_updated, events.ModelUpdated)
    config.add_subscriber(index.on_model_deleted, events.ModelDeleted)
    config.add_subscriber(index.on_record_created, events.RecordCreated)
    config.add_subscriber(index.on_record_updated, events.RecordUpdated)
    config.add_subscriber(index.on_record_deleted, events.RecordDeleted)

    # Renderers

    # Force default accept header to JSON
    def add_default_accept(event):
        json_mime = "application/json"
        accept = event.request.headers.get("Accept", json_mime)
        if json_mime in accept:
            accept = json_mime
        event.request.headers["Accept"] = accept

    config.add_subscriber(add_default_accept, NewRequest)

    # JSONP
    config.add_renderer("jsonp", JSONP(param_name="callback"))

    # Geographic data renderer
    config.add_renderer("geojson", GeoJSON())
#.........这里部分代码省略.........
开发者ID:chid,项目名称:daybed,代码行数:103,代码来源:__init__.py


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