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


Python Configurator.add_route方法代码示例

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


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

示例1: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, "sqlalchemy.")
    settings["db.sessionmaker"] = DBSession
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    initialize_sql(engine, [populate, populate_wiki, populate_feeds])
    session_factory = session_factory_from_settings(settings)
    root_factory = "trumpet.resources.RootGroupFactory"
    request_factory = "trumpet.request.AlchemyRequest"
    config = Configurator(
        settings=settings,
        root_factory=root_factory,
        request_factory=request_factory,
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
        session_factory=session_factory,
    )
    configure_static(config)

    # config.include('pyramid_fanstatic')
    configure_base_layout(config)

    config.add_static_view("static", "static", cache_max_age=3600)
    config.add_route("home", "/")
    config.add_view("plum.views.MainViewer", route_name="home", renderer=basetemplate, layout="base")

    configure_login(config)
    configure_rssviewer(config, "/rssviewer")
    configure_wiki(config, "/wiki")

    return config.make_wsgi_app()
开发者ID:umeboshi2,项目名称:raspbian-setup,代码行数:36,代码来源:__init__.py

示例2: setUp

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
    def setUp(self):
        configurator = Configurator()
        configurator.add_route("example", "/example", request_method="GET")
        configurator.add_route("trace_context", "/trace_context", request_method="GET")

        configurator.add_view(
            example_application, route_name="example", renderer="json")

        configurator.add_view(
            local_tracing_within_context, route_name="trace_context", renderer="json")

        self.observer = mock.Mock(spec=BaseplateObserver)
        self.server_observer = mock.Mock(spec=ServerSpanObserver)
        def _register_mock(context, server_span):
            server_span.register(self.server_observer)
        self.observer.on_server_span_created.side_effect = _register_mock

        self.baseplate = Baseplate()
        self.baseplate.register(self.observer)
        self.baseplate_configurator = BaseplateConfigurator(
            self.baseplate,
            trust_trace_headers=True,
        )
        configurator.include(self.baseplate_configurator.includeme)
        app = configurator.make_wsgi_app()
        self.test_app = webtest.TestApp(app)
开发者ID:ckwang8128,项目名称:baseplate,代码行数:28,代码来源:pyramid_tests.py

示例3: Test_route_url_filter

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
class Test_route_url_filter(unittest.TestCase):
    def setUp(self):
        self.environment = Environment()
        from pyramid_jinja2.filters import route_url_filter
        self.environment.filters['route_url'] = route_url_filter
        from pyramid.config import Configurator
        self.config = Configurator(autocommit=True)
        self.config.begin(request=DummyRequest())
        self.config.add_route('dummy_route1', '/dummy/')
        self.config.add_route('dummy_route2', '/dummy/:name/')

    def tearDown(self):
        self.config.end()

    def _callFUT(self, context, tmpl):
        tmpl = self.environment.from_string(tmpl)
        return tmpl.render(**context)

    def test_filter(self):
        rendered = self._callFUT({}, "{{'dummy_route1' | route_url }}")
        self.assertEqual(rendered, 'http://example.com/dummy/')

    def test_filter_with_arguments(self):
        rendered = self._callFUT({}, "{{'dummy_route2' | route_url('x', name='test') }}")
        self.assertEqual(rendered, 'http://example.com/dummy/test/x')
开发者ID:kschuetz,项目名称:pyramid_jinja2,代码行数:27,代码来源:test_filters.py

示例4: create_app

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
def create_app(settings):
    from pyramid.config import Configurator
    from pyramid.authorization import ACLAuthorizationPolicy
    from pyramid.path import AssetResolver
    from pyramid.response import FileResponse

    from h.auth import HybridAuthenticationPolicy
    from h.models import groupfinder

    authn_policy = HybridAuthenticationPolicy(callback=groupfinder)
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(
        settings=settings,
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
    )

    favicon = AssetResolver().resolve('h:favicon.ico')
    config.add_route('favicon', '/favicon.ico')
    config.add_view(
        lambda request: FileResponse(favicon.abspath(), request=request),
        route_name='favicon'
    )

    config.add_route('ok', '/ruok')
    config.add_view(lambda request: 'imok', renderer='string', route_name='ok')

    # Include all the pyramid subcomponents
    config.include(includeme)

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

示例5: app

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
def app():
    config = Configurator()
    config.include('pyramid_wiring')

    graph = Graph()
    graph.register_scope(RequestScope, RequestScope())
    class Counter(object):
        def __init__(self):
            self.count = 1
    graph.register_provider('counter', FactoryProvider(Counter, scope=RequestScope))
    config.set_object_graph(graph)

    def count(request, counter=injected('counter')):
        # Increment the counter
        count = counter.count
        counter.count += 1

        # Get the counter from the graph again and make sure it's the same
        assert graph.get('counter') is counter

        return count
    config.add_route('count', '/count')
    config.add_view(count, route_name='count', renderer='string')

    return TestApp(config.make_wsgi_app())
开发者ID:veeti,项目名称:pyramid_wiring,代码行数:27,代码来源:test_scope.py

示例6: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
def main(global_config, **app_settings):
    """ This function returns a Pyramid WSGI application.
    """
    settings = global_config
    settings.update(app_settings)
    initialize_web_database(settings)
    session_factory = session_factory_from_settings(settings)
    auth_policy = AuthTktAuthenticationPolicy(
        settings['auth_tkt.secret'],
        callback=models.user.get_user_groups,
        hashalg='sha512',
    )
    set_cache_regions_from_settings(settings)
    config = Configurator(settings=settings,
                          request_factory=NDRequest,
                          session_factory=session_factory,
                          root_factory=_rsr.Root,
                          authentication_policy=auth_policy)

    config.include('pyramid_mako')
    config.include('pyramid_layout')

    config.include('notification_demo.lib.client_script')
    config.include("pyramid_vgid_oauth2")
    config.include("notification_demo.views")
    config.include("notification_demo.lib.notification")

    config.add_static_view('static', STATIC_DIR, cache_max_age=3600)
    config.add_route('home', '/')
    config.scan()
    return config.make_wsgi_app()
开发者ID:phamthanhnhan14,项目名称:noti_copy,代码行数:33,代码来源:__init__.py

示例7: assert_cache_enabled

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
    def assert_cache_enabled(self, cache_factory):
        settings = {
            "boto3.sessions": "default",
            "boto3.clients": "s3",
            "boto3.client.s3.session": "default",
            "boto3.client.s3.service_name": "s3",
            "boto3.resources": "s3",
            "boto3.resource.s3.session": "default",
            "boto3.resource.s3.service_name": "s3",
            "boto3.cache_factory": cache_factory,
        }
        config = Configurator(settings=settings)
        config.include("pyramid_boto3")

        def aview(request):
            session = request.find_service(name="boto3.session.default")
            self.assertIsNotNone(session)
            s3cli = request.find_service(name="boto3.client.s3")
            self.assertIsNotNone(s3cli)
            s3res = request.find_service(name="boto3.resource.s3")
            self.assertIsNotNone(s3res)
            return "OK"

        config.add_view(aview, route_name="root", renderer="json")
        config.add_route("root", pattern="/")
        app = config.make_wsgi_app()
        request = Request.blank("/")
        response = request.get_response(app)
        self.assertEqual(response.json_body, "OK")
        del app
开发者ID:gjo,项目名称:pyramid_boto3,代码行数:32,代码来源:test_functional.py

示例8: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    initialize_sql(engine)
    config = Configurator(settings=settings)
    config.add_static_view('static', 'pyramidapp:static')
    config.add_route('home', '/')
    config.add_view('pyramidapp.views.my_view',
                    route_name='home',
                    renderer='templates/mytemplate.pt')

    # pyramid_formalchemy's configuration
    config.include('pyramid_fanstatic')
    config.include('pyramid_formalchemy')
    config.include('fa.jquery')

    # register an admin UI
    config.formalchemy_admin('/admin', package='pyramidapp', view='fa.jquery.pyramid.ModelView')

    # register an admin UI for a single model
    config.formalchemy_model('/foo', package='pyramidapp',
                                    view='fa.jquery.pyramid.ModelView',
                                    model='pyramidapp.models.Foo')

    return config.make_wsgi_app()
开发者ID:FormAlchemy,项目名称:pyramid_formalchemy,代码行数:28,代码来源:jquery.py

示例9: make_wsgi_app

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
def make_wsgi_app(app_config):
    cfg = config.parse_config(app_config)
    signer = MessageSigner(cfg.ads_tracking.click_secret)

    metrics_client = make_metrics_client(app_config)

    baseplate = Baseplate()
    baseplate.configure_logging()
    baseplate.configure_metrics(metrics_client)
    baseplate.add_to_context("events", events.EventQueue("production"))
    baseplate.add_to_context("events_test", events.EventQueue("test"))

    configurator = Configurator(settings=app_config)

    baseplate_configurator = BaseplateConfigurator(baseplate)
    configurator.include(baseplate_configurator.includeme)

    controller = TrackingService(
        signer=signer,
    )
    configurator.add_route("health", "/health", request_method="GET")
    configurator.add_view(
        controller.is_healthy, route_name="health", renderer="json")

    configurator.add_route("click", "/click", request_method="GET")
    configurator.add_view(
        controller.track_click, route_name="click", renderer="json")

    return configurator.make_wsgi_app()
开发者ID:reddit,项目名称:reddit-service-ads-tracking,代码行数:31,代码来源:__init__.py

示例10: Server

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
class Server(object):
    def __init__(self):
        self.appconfig = Configurator()
        self.appconfig.include("pyramid_chameleon")
        self.appconfig.include("pyramid_mako")
        self.compatActions = {}

    def addPage(self, location, function, renderer, reqType):
        name = str(uuid.uuid4())
        self.appconfig.add_route(name, location, request_method=reqType)
        self.appconfig.add_view(function, route_name=name, renderer=renderer)

    def getApp(self):
        ### Add code to add static locations here ###
        self.appconfig.add_static_view(name='static', path='__main__:static')
        self.appconfig.add_static_view(name='swagger', path='__main__:swagger')
        app = self.appconfig.make_wsgi_app()
        return app

    def addCompatAction(self, name, page):
        self.compatActions[name] = page

    def getCompatAction(self, name):
        if self.compatActions.has_key(name):
            return self.compatActions[name]
        else:
            return None
开发者ID:johnmdilley,项目名称:xenrt,代码行数:29,代码来源:server.py

示例11: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
def main(global_config, **settings):
    config = Configurator(settings=settings, root_factory=Site.root_factory)
    config.include('substanced')
    config.add_route('languages', '/language/{name}')
    config.add_view(www, context='pyramid.httpexceptions.HTTPNotFound')
    config.scan('hugitout')
    return config.make_wsgi_app()
开发者ID:breckprog,项目名称:hugitout,代码行数:9,代码来源:__init__.py

示例12: main

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

    # templates
    config.add_notfound_view(notfound, append_slash=False)
    config.add_renderer('.html', 'pyramid_jinja2.renderer_factory')
    config.add_renderer('.jinja2', 'pyramid_jinja2.renderer_factory')
    config.add_jinja2_search_path('templates')

    # apps
    config.include('main')
    config.include('businesses', route_prefix='/api/v1')
    config.include('reviews', route_prefix='/api/v1')
    config.include('auth', route_prefix='/api/v1')

    # static files
    config.add_route('catchall_static', '/*subpath')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_view('service.static.static_view', route_name='catchall_static')

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

示例13: main

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

    # Includes for any packages that hook into configuration.
    config.include('pyramid_tm')

    # Extending an existing package allows you to override
    # view mappings and other configuration details.
    # config.include('base_package_name')

    # overriding templates should be done as follows:

    # config.override_asset('base_package_name:templates/base.pt',
    #                       'speak_friend:templates/override.pt')

    # Configuring URLs
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    includeme(config)
    config.include('sixfeetup.bowab')
    config.scan()

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

示例14: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_route [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    models.initialize(engine)
    config = Configurator(settings=settings,
                          root_factory='bonanza.lib:RootFactory',
                          session_factory=session_factory_from_settings(settings),
                          # authentication_policy=AuthTktAuthenticationPolicy(
                          #     '5e04c5f06208def3c5becd6db74f8d11733a912a',
                          #     callback=bonanza.security.lookup_userid),
                          # authorization_policy=ACLAuthorizationPolicy()
                          )

    config.include('pyramid_jinja2')
    config.include('pyramid_scss')

    config.add_static_view('static', 'bonanza:static', cache_max_age=3600)

    # entity
    config.add_route('home', '/')
    config.add_view(route_name='home', view='bonanza.controllers.home.get_index',
        renderer='/home/index.jinja2', request_method='GET')

    # scss
    config.add_route('css', '/css/{stylesheet}.css')
    config.add_view(route_name='css', view='bonanza.controllers.static.get_css',
        renderer='scss', request_method='GET')

    config.commit()
    add_template_filters(config)
    return config.make_wsgi_app()
开发者ID:jessedhillon,项目名称:bonanza,代码行数:34,代码来源:__init__.py

示例15: main

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

    config.include('pyramid_mailer')
    config.add_translation_dirs(
        'colander:locale/',
        'deform:locale/',
        'c3sintent:locale/')
    config.add_static_view('static',
                           'c3sintent:static', cache_max_age=3600)

    config.add_subscriber('c3sintent.subscribers.add_base_template',
                          'pyramid.events.BeforeRender')
    config.add_subscriber('c3sintent.subscribers.add_locale_to_cookie',
                          'pyramid.events.NewRequest')
    # home /
    # membership application form
    config.add_route('intent', '/')

    config.scan()
    return config.make_wsgi_app()
开发者ID:violet18,项目名称:C3SIntent,代码行数:29,代码来源:__init__.py


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