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


Python config.Configurator方法代码示例

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


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

示例1: includeme

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def includeme(config: Configurator) -> None:
    """Pyramid knob."""
    config.add_view_deriver(openapi_view)
    config.add_directive("pyramid_openapi3_add_formatter", add_formatter)
    config.add_directive("pyramid_openapi3_add_explorer", add_explorer_view)
    config.add_directive("pyramid_openapi3_spec", add_spec_view)
    config.add_tween("pyramid_openapi3.tween.response_tween_factory", over=EXCVIEW)

    if not config.registry.settings.get(  # pragma: no branch
        "pyramid_openapi3_extract_errors"
    ):
        config.registry.settings["pyramid_openapi3_extract_errors"] = extract_errors

    config.add_exception_view(
        view=openapi_validation_error, context=RequestValidationError, renderer="json"
    )

    config.add_exception_view(
        view=openapi_validation_error, context=ResponseValidationError, renderer="json"
    ) 
开发者ID:Pylons,项目名称:pyramid_openapi3,代码行数:22,代码来源:__init__.py

示例2: _testapp

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def _testapp(self) -> TestApp:
        """Start up the app so that tests can send requests to it."""
        from webtest import TestApp

        with tempfile.NamedTemporaryFile() as document:
            document.write(self.OPENAPI_YAML.encode())
            document.seek(0)

            with Configurator() as config:
                config.include("pyramid_openapi3")
                config.pyramid_openapi3_spec(document.name)
                config.pyramid_openapi3_add_formatter("unique-name", self.UniqueName())
                config.add_route("hello", "/hello")
                config.add_view(
                    openapi=True, renderer="json", view=self.hello, route_name="hello"
                )
                app = config.make_wsgi_app()

            return TestApp(app) 
开发者ID:Pylons,项目名称:pyramid_openapi3,代码行数:21,代码来源:test_extract_errors.py

示例3: main

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

    settings['SOFTWARE_VERSION'] = __VERSION__

    config = Configurator(settings=settings)

    # Addons
    config.include('pyramid_jinja2')
    # http://docs.pylonsproject.org/projects/pyramid-jinja2/en/latest/#adding-or-overriding-a-renderer
    config.add_jinja2_renderer('.html')
    config.include('cornice')

    # Views and routes
    config.add_static_view('static/app', 'static/app', cache_max_age=0)
    config.add_static_view('static/lib', 'static/lib', cache_max_age=60 * 24)
    config.add_route('index', '/')

    config.scan()

    return config.make_wsgi_app() 
开发者ID:daq-tools,项目名称:kotori,代码行数:23,代码来源:app.py

示例4: base_config

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def base_config() -> Configurator:
    config = Configurator()
    config.set_authorization_policy(ACLAuthorizationPolicy())

    config.include("pyramid_jwt")
    config.set_root_factory(Root)
    config.add_route("secure", "/secure")
    config.add_view(
        secure_view, route_name="secure", renderer="string", permission="read"
    )
    config.add_route("extra_claims", "/extra_claims")
    config.add_view(extra_claims, route_name="extra_claims", renderer="json")
    config.add_route("dump_claims", "/dump_claims")
    config.add_view(
        dump_claims, route_name="dump_claims", renderer="json", permission="read"
    )
    return config 
开发者ID:wichert,项目名称:pyramid_jwt,代码行数:19,代码来源:test_integration.py

示例5: test_pyramid_custom_json_encoder

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def test_pyramid_custom_json_encoder(app_config: Configurator):
    """Test we can still use user-defined custom adapter"""
    from pyramid.renderers import json_renderer_factory

    def serialize_anyclass(obj, request):
        assert False  # This asserts this method will not be called

    json_renderer_factory.add_adapter(NonSerializable, serialize_anyclass)

    def other_serializer(obj, request):
        return "other_serializer"

    my_renderer = JSON()
    my_renderer.add_adapter(NonSerializable, other_serializer)
    app_config.add_renderer("json", my_renderer)
    app = TestApp(app_config.make_wsgi_app())

    response = app.get("/extra_claims")
    token = str(response.json_body["token"])

    response = app.get("/dump_claims", headers={"X-Token": token})
    assert response.json_body["extra_claim"] == "other_serializer" 
开发者ID:wichert,项目名称:pyramid_jwt,代码行数:24,代码来源:test_integration.py

示例6: main

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def main(global_config, **settings):
    """ Very basic pyramid app """
    settings['service_name'] = 'acceptance_service'
    settings['zipkin.transport_handler'] = lambda x, y: None
    settings['zipkin.encoding'] = Encoding.V2_JSON

    config = Configurator(settings=settings)

    config.add_route('sample_route', '/sample')
    config.add_route('sample_route_v2', '/sample_v2')
    config.add_route('sample_route_v2_client', '/sample_v2_client')
    config.add_route('sample_route_child_span', '/sample_child_span')
    config.add_route('span_context', '/span_context')
    config.add_route('decorator_context', '/decorator_context')
    config.add_route('pattern_route', '/pet/{petId}')

    config.add_route('server_error', '/server_error')
    config.add_route('client_error', '/client_error')

    config.scan()

    config.add_tween('pyramid_zipkin.tween.zipkin_tween', over=EXCVIEW)

    return config.make_wsgi_app() 
开发者ID:Yelp,项目名称:pyramid_zipkin,代码行数:26,代码来源:__init__.py

示例7: _create_application

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def _create_application():
    """Create the WSGI application, post-fork."""
    mycroft.config.load_staticconf()
    # Initialize configs at the early stage to avoid repeated calculation at runtime.
    mycroft.config.init()

    # Create a basic pyramid Configurator.
    config = Configurator(settings={
        'service_name': 'mycroft',
    })

    # Add the service's custom configuration, routes, etc.
    config.include(mycroft.config.routes)
    config.include(mycroft.config.swagger_views)
    config.include(mycroft.config.renderers)

    config.add_route('status.healthcheck', '/status/healthcheck')

    # Display metrics on the '/status/metrics' endpoint
    # config.include(pyramid_uwsgi_metrics)

    # Scan the service package to attach any decorated views.
    config.scan('mycroft')

    return config.make_wsgi_app() 
开发者ID:Yelp,项目名称:mycroft,代码行数:27,代码来源:webapp.py

示例8: app

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def app(spec):
    """Prepare a Pyramid app."""
    with Configurator() as config:
        config.include("pyramid_openapi3")
        config.pyramid_openapi3_spec(spec)
        config.pyramid_openapi3_add_explorer()
        config.add_route("hello", "/hello")
        config.scan(".")
        return config.make_wsgi_app() 
开发者ID:Pylons,项目名称:pyramid_openapi3,代码行数:11,代码来源:app.py

示例9: app

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def app() -> Router:
    """Prepare a Pyramid app."""
    with Configurator() as config:
        config.include("pyramid_openapi3")
        config.pyramid_openapi3_spec(
            os.path.join(os.path.dirname(__file__), "openapi.yaml")
        )
        config.pyramid_openapi3_add_explorer()
        config.add_route("todo", "/")
        config.scan(".")

        return config.make_wsgi_app() 
开发者ID:Pylons,项目名称:pyramid_openapi3,代码行数:14,代码来源:app.py

示例10: add_explorer_view

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def add_explorer_view(
    config: Configurator,
    route: str = "/docs/",
    route_name: str = "pyramid_openapi3.explorer",
    template: str = "static/index.html",
    ui_version: str = "3.17.1",
) -> None:
    """Serve Swagger UI at `route` url path.

    :param route: URL path where to serve
    :param route_name: Route name that's being added
    :param template: Dotted path to the html template that renders Swagger UI response
    :param ui_version: Swagger UI version string
    """

    def register() -> None:
        resolved_template = AssetResolver().resolve(template)

        def explorer_view(request: Request) -> Response:
            settings = config.registry.settings
            if settings.get("pyramid_openapi3") is None:
                raise ConfigurationError(
                    "You need to call config.pyramid_openapi3_spec for explorer to work."
                )
            with open(resolved_template.abspath()) as f:
                template = Template(f.read())
                html = template.safe_substitute(
                    ui_version=ui_version,
                    spec_url=request.route_url(
                        settings["pyramid_openapi3"]["spec_route_name"]
                    ),
                )
            return Response(html)

        config.add_route(route_name, route)
        config.add_view(route_name=route_name, view=explorer_view)

    config.action(("pyramid_openapi3_add_explorer",), register, order=PHASE0_CONFIG) 
开发者ID:Pylons,项目名称:pyramid_openapi3,代码行数:40,代码来源:__init__.py

示例11: add_formatter

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def add_formatter(config: Configurator, name: str, func: t.Callable) -> None:
    """Add support for configuring formatters."""
    config.registry.settings.setdefault("pyramid_openapi3_formatters", {})
    reg = config.registry.settings["pyramid_openapi3_formatters"]
    reg[name] = func 
开发者ID:Pylons,项目名称:pyramid_openapi3,代码行数:7,代码来源:__init__.py

示例12: app

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def app(spec: str, view: t.Callable, route: str) -> Router:
    """Prepare a Pyramid app."""
    with Configurator() as config:
        config.include("pyramid_openapi3")
        config.pyramid_openapi3_spec(spec)
        config.add_route("foo", route)
        config.add_view(openapi=True, renderer="json", view=view, route_name="foo")
        return config.make_wsgi_app() 
开发者ID:Pylons,项目名称:pyramid_openapi3,代码行数:10,代码来源:test_extract_errors.py

示例13: main

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def main(global_config, **settings):
    """Function returns a Pyramid WSGI application."""
    config = Configurator(settings=settings)
    config.include('pyramid_jinja2')
    # config.include('.vendor')
    # config.include('.models')
    config.include('.routes')
    config.scan()
    return config.make_wsgi_app() 
开发者ID:famavott,项目名称:osint-scraper,代码行数:11,代码来源:__init__.py

示例14: main

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def main(global_config, **settings):
    """Function returns a Pyramid WSGI application."""
    config = Configurator(settings=settings)
    config.include('pyramid_jinja2')
    config.include('.routes')
    config.scan()
    return config.make_wsgi_app() 
开发者ID:famavott,项目名称:osint-scraper,代码行数:9,代码来源:conftest.py

示例15: main

# 需要导入模块: from pyramid import config [as 别名]
# 或者: from pyramid.config import Configurator [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(settings=settings)
    config.include('pyramid_chameleon')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('newlunch', '/newlunch')
    config.scan()
    return config.make_wsgi_app() 
开发者ID:ryansb,项目名称:wut4lunch_demos,代码行数:15,代码来源:__init__.py


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