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