• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python configuration.AppConfig类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tg.configuration.AppConfig的典型用法代码示例。如果您正苦于以下问题:Python AppConfig类的具体用法?Python AppConfig怎么用?Python AppConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: __init__

    def __init__(self, folder, values=None):
        if values is None:
            values = {}
        AppConfig.__init__(self)
        #First we setup some base values that we know will work
        self.renderers = ['genshi', 'mako', 'jinja','json']
        if not PY3:
            self.renderers.extend(['chameleon_genshi', 'kajiki'])

        self.render_functions = tg.util.Bunch()
        self.package = tests.test_stack
        self.default_renderer = 'genshi'
        self.globals = self
        self.auth_backend = None
        self.auto_reload_templates = False
        self.use_legacy_renderer = False
        self.use_dotted_templatenames = False
        self.serve_static = False

        root = os.path.dirname(os.path.dirname(tests.__file__))
        test_base_path = os.path.join(root,'tests', 'test_stack',)
        test_config_path = os.path.join(test_base_path, folder)
        self.paths=tg.util.Bunch(
                    root=test_base_path,
                    controllers=os.path.join(test_config_path, 'controllers'),
                    static_files=os.path.join(test_config_path, 'public'),
                    templates=[os.path.join(test_config_path, 'templates')],
                    i18n=os.path.join(test_config_path, 'i18n')
                    )
        # then we override those values with what was passed in
        for key, value in values.items():
            setattr(self, key, value)
开发者ID:Shamefox,项目名称:tg2,代码行数:32,代码来源:__init__.py


示例2: test_mixed_controller_wrapper

    def test_mixed_controller_wrapper(self):
        milestones._reset_all()

        class RootController(TGController):
            @expose()
            def test(self):
                return 'HI!'

        app_wrapper_has_been_visited = []
        def app_controller_wrapper(app_config, caller):
            def call(*args, **kw):
                app_wrapper_has_been_visited.append(True)
                return caller(*args, **kw)
            return call

        wrapper_has_been_visited = []
        def controller_wrapper(app_config, caller):
            def call(*args, **kw):
                wrapper_has_been_visited.append(True)
                return caller(*args, **kw)
            return call

        conf = AppConfig(minimal=True, root_controller=RootController())
        tg.hooks.wrap_controller(app_controller_wrapper)
        tg.hooks.wrap_controller(controller_wrapper, controller=RootController.test)
        conf.package = PackageWithModel()
        app = conf.make_wsgi_app()
        app = TestApp(app)

        assert 'HI!' in app.get('/test')
        assert wrapper_has_been_visited[0] is True
        assert app_wrapper_has_been_visited[0] is True
开发者ID:Shamefox,项目名称:tg2,代码行数:32,代码来源:test_configuration.py


示例3: __init__

    def __init__(self, folder, values=None):
        if values is None:
            values = {}
        AppConfig.__init__(self)

        # First we setup some base values that we know will work
        self.renderers = ["genshi", "mako", "jinja", "json", "jsonp", "kajiki"]
        self.render_functions = tg.util.Bunch()
        self.package = tests.test_stack
        self.default_renderer = "genshi"
        self.globals = self
        self.auth_backend = None
        self.auto_reload_templates = False
        self.use_legacy_renderer = False
        self.use_dotted_templatenames = False
        self.serve_static = False
        self["errorpage.enabled"] = False

        root = os.path.dirname(os.path.dirname(tests.__file__))
        test_base_path = os.path.join(root, "tests", "test_stack")
        test_config_path = os.path.join(test_base_path, folder)
        self.paths = tg.util.Bunch(
            root=test_base_path,
            controllers=os.path.join(test_config_path, "controllers"),
            static_files=os.path.join(test_config_path, "public"),
            templates=[os.path.join(test_config_path, "templates")],
            i18n=os.path.join(test_config_path, "i18n"),
        )

        # then we override those values with what was passed in
        for key, value in values.items():
            setattr(self, key, value)
开发者ID:TurboGears,项目名称:tg2,代码行数:32,代码来源:__init__.py


示例4: test_disconnect_hooks_multiple_listener

    def test_disconnect_hooks_multiple_listener(self):
        hook1_has_been_called = []
        def hook1_listener():
            hook1_has_been_called.append(True)

        hook2_has_been_called = []
        def hook2_listener():
            hook2_has_been_called.append(True)

        class RootController(TGController):
            @expose()
            def test(self):
                tg.hooks.notify('custom_hook', controller=RootController.test)
                return 'HI!'

        conf = AppConfig(minimal=True, root_controller=RootController())
        tg.hooks.register('custom_hook', hook1_listener)
        tg.hooks.register('custom_hook', hook2_listener)
        conf.package = PackageWithModel()
        app = conf.make_wsgi_app()
        app = TestApp(app)

        app.get('/test')
        app.get('/test')
        tg.hooks.disconnect('custom_hook', hook2_listener)
        app.get('/test')

        # Disconnecting an unregistered hook should do nothing.
        tg.hooks.disconnect('unregistered', hook1_listener)

        assert len(hook1_has_been_called) == 3, hook1_has_been_called
        assert len(hook2_has_been_called) == 2, hook2_has_been_called
开发者ID:984958198,项目名称:tg2,代码行数:32,代码来源:test_hooks.py


示例5: setup

 def setup(self):
     conf = AppConfig(minimal=True)
     conf.use_dotted_templatenames = True
     conf.renderers.append('mako')
     conf.package = FakePackage()
     self.conf = conf
     self.app = conf.make_wsgi_app()
开发者ID:984958198,项目名称:tg2,代码行数:7,代码来源:test_render.py


示例6: test_package_no_app_globals

    def test_package_no_app_globals(self):
        class RootController(TGController):
            pass

        conf = AppConfig(minimal=True, root_controller=RootController())
        conf.package = sys.modules[__name__]

        app = conf.make_wsgi_app()
开发者ID:Shamefox,项目名称:tg2,代码行数:8,代码来源:test_configuration.py


示例7: test_application_test_vars

    def test_application_test_vars(self):
        conf = AppConfig(minimal=True, root_controller=None)
        conf.package = PackageWithModel()
        app = conf.make_wsgi_app(global_conf={'debug':True})
        app = TestApp(app)

        assert 'DONE' in app.get('/_test_vars')
        assert request.path == '/_test_vars'
开发者ID:Shamefox,项目名称:tg2,代码行数:8,代码来源:test_configuration.py


示例8: setup

    def setup(self):
        class RootController(TGController):
            @expose()
            def test(self):
                return str(bool(EqualsTwo()))

        conf = AppConfig(minimal=True, root_controller=RootController())
        app = conf.make_wsgi_app()
        self.app = TestApp(app)
开发者ID:984958198,项目名称:tg2,代码行数:9,代码来源:test_predicates.py


示例9: test_setup_jinja_without_package

    def test_setup_jinja_without_package(self):
        class RootController(TGController):
            @expose()
            def test(self):
                return 'HI!'

        conf = AppConfig(minimal=True, root_controller=RootController())
        conf.renderers = ['jinja']
        app = conf.make_wsgi_app()
开发者ID:Shamefox,项目名称:tg2,代码行数:9,代码来源:test_configuration.py


示例10: test_application_wrapper_blocked_after_milestone

    def test_application_wrapper_blocked_after_milestone(self):
        class AppWrapper1:
            pass
        class AppWrapper2:
            pass

        conf = AppConfig(minimal=True)
        conf.register_wrapper(AppWrapper1)
        milestones.environment_loaded.reach()
        conf.register_wrapper(AppWrapper2)
开发者ID:Shamefox,项目名称:tg2,代码行数:10,代码来源:test_configuration.py


示例11: __init__

 def __init__(self, root_controller='root'):
     AppConfig.__init__(self)
     self.root_controller = root_controller
     self.package = allura
     self.renderers = ['json', 'genshi', 'mako', 'jinja']
     self.default_renderer = 'genshi'
     self.use_sqlalchemy = False
     self.use_toscawidgets = True
     self.use_transaction_manager = False
     self.handle_status_codes = [403, 404]
     self.disable_request_extensions = True
开发者ID:AsylumCorp,项目名称:incubator-allura,代码行数:11,代码来源:app_cfg.py


示例12: test_application_empty_controller

    def test_application_empty_controller(self):
        class RootController(object):
            def __call__(self, environ, start_response):
                return None

        conf = AppConfig(minimal=True, root_controller=RootController())
        conf.package = PackageWithModel()
        app = conf.make_wsgi_app(global_conf={'debug':True})
        app = TestApp(app)

        r = app.get('/something', status=500)
        assert 'No content returned by controller' in r
开发者ID:Shamefox,项目名称:tg2,代码行数:12,代码来源:test_configuration.py


示例13: setup

 def setup(self):
     conf = AppConfig(minimal=True, root_controller=i18nRootController())
     conf['paths']['root'] = 'tests'
     conf['i18n_enabled'] = True
     conf['use_sessions'] = True
     conf['beaker.session.key'] = 'tg_test_session'
     conf['beaker.session.secret'] = 'this-is-some-secret'
     conf.renderers = ['json']
     conf.default_renderer = 'json'
     conf.package = _FakePackage()
     app = conf.make_wsgi_app()
     self.app = TestApp(app)
开发者ID:Cito,项目名称:tg2,代码行数:12,代码来源:test_i18n.py


示例14: test_enable_routes

    def test_enable_routes(self):
        if PY3: raise SkipTest()

        conf = AppConfig(minimal=True)
        conf.enable_routes = True
        app = conf.make_wsgi_app()

        a = TGApp()
        assert a.enable_routes == True

        config.pop('routes.map')
        config.pop('enable_routes')
开发者ID:Shamefox,项目名称:tg2,代码行数:12,代码来源:test_configuration.py


示例15: test_setup_ming_persistance_with_url_alone

    def test_setup_ming_persistance_with_url_alone(self):
        if PY3: raise SkipTest()

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=None)
        conf.package = package
        conf.model = package.model
        conf.use_ming = True
        conf['ming.url'] = 'mim://inmemdb'

        app = conf.make_wsgi_app()
        assert app is not None
开发者ID:Shamefox,项目名称:tg2,代码行数:12,代码来源:test_configuration.py


示例16: test_jinja_lookup_nonexisting_template

def test_jinja_lookup_nonexisting_template():
    conf = AppConfig(minimal=True)
    conf.use_dotted_templatenames = True
    conf.renderers.append('jinja')
    conf.package = FakePackage()
    app = conf.make_wsgi_app()

    from jinja2 import TemplateNotFound
    try:
        render_jinja('tg.this_template_does_not_exists', {'app_globals':tg.config['tg.app_globals']})
        assert False
    except TemplateNotFound:
        pass
开发者ID:Shamefox,项目名称:tg2,代码行数:13,代码来源:test_render.py


示例17: test_create_minimal_app

    def test_create_minimal_app(self):
        class RootController(TGController):
            @expose()
            def test(self):
                return 'HI!'

        conf = AppConfig(minimal=True, root_controller=RootController())
        app = conf.make_wsgi_app()
        app = TestApp(app)
        assert 'HI!' in app.get('/test')

        #This is here to avoid that other tests keep using the forced controller
        config.pop('tg.root_controller')
开发者ID:Shamefox,项目名称:tg2,代码行数:13,代码来源:test_configuration.py


示例18: test_setup_ming_persistance_advanced_options

    def test_setup_ming_persistance_advanced_options(self):
        if PY3: raise SkipTest()

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=None)
        conf.package = package
        conf.model = package.model
        conf.use_ming = True
        conf['ming.url'] = 'mim://inmemdb'
        conf['ming.connection.read_preference'] = 'PRIMARY'

        app = conf.make_wsgi_app()
        assert app is not None
开发者ID:Shamefox,项目名称:tg2,代码行数:13,代码来源:test_configuration.py


示例19: test_startup_hook_with_exception

    def test_startup_hook_with_exception(self):
        # Temporary replace the hooks namespace so we register hooks only for this test
        original_hooks, tg.hooks = tg.hooks, _TGGlobalHooksNamespace()

        try:
            def func():
                raise Exception

            tg.hooks.register('startup', func)
            conf = AppConfig(minimal=True)
            app = conf.make_wsgi_app()
        finally:
            tg.hooks = original_hooks
开发者ID:984958198,项目名称:tg2,代码行数:13,代码来源:test_hooks.py


示例20: test_serve_statics

    def test_serve_statics(self):
        class RootController(TGController):
            @expose()
            def test(self):
                return 'HI!'

        conf = AppConfig(minimal=True, root_controller=RootController())
        conf.package = PackageWithModel()
        conf.serve_static = True
        app = conf.make_wsgi_app()
        assert app.__class__.__name__.startswith('Statics')

        app = TestApp(app)
        assert 'HI!' in app.get('/test')
开发者ID:Shamefox,项目名称:tg2,代码行数:14,代码来源:test_configuration.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python controllers.redirect函数代码示例发布时间:2022-05-27
下一篇:
Python config.get函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap