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


Python Configurator.end方法代码示例

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


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

示例1: Test_route_url_filter

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import end [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

示例2: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import end [as 别名]
def main(global_config, **settings):
    """ This function returns a WSGI application.
    """
    authn_p = AuthTktAuthenticationPolicy(secret='demo-secret', callback=groupfinder)
    authz_p = ACLAuthorizationPolicy()
    session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')

    engine = engine_from_config(settings, 'sqlalchemy.')
    config = Configurator(
        settings=settings,
        session_factory=session_factory,
        request_factory=RequestWithAttributes,
        authentication_policy=authn_p,
        authorization_policy=authz_p,
    )
    config.begin()
    ## Database
    config.scan('demo.models')
    M.initialize_sql(engine)

    ## Routing & Views
    config.include(default_routes, route_prefix='')
    config.include(user_routes, route_prefix='/user')

    ## Velruse Auth
    config.include('velruse.providers.facebook')
    config.include('velruse.providers.twitter')

    config.scan('demo.views')
    config.add_static_view('static', 'demo:static')

    config.end()
    return config.make_wsgi_app()
开发者ID:wwitzel3,项目名称:velruse_demo,代码行数:35,代码来源:__init__.py

示例3: ViewPageTests

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import end [as 别名]
class ViewPageTests(unittest.TestCase):
    def setUp(self):
        self.session = _initTestingDB()
        self.config = Configurator(autocommit=True)
        self.config.begin()

    def tearDown(self):
        self.session.remove()
        self.config.end()
        
    def _callFUT(self, request):
        from tutorial.views import view_page
        return view_page(request)

    def test_it(self):
        from tutorial.models import Page
        request = testing.DummyRequest()
        request.matchdict['pagename'] = 'IDoExist'
        page = Page('IDoExist', 'Hello CruelWorld IDoExist')
        self.session.add(page)
        _registerRoutes(self.config)
        info = self._callFUT(request)
        self.assertEqual(info['page'], page)
        self.assertEqual(
            info['content'], 
            '<div class="document">\n'
            '<p>Hello <a href="http://example.com/add_page/CruelWorld">'
            'CruelWorld</a> '
            '<a href="http://example.com/IDoExist">'
            'IDoExist</a>'
            '</p>\n</div>\n')
        self.assertEqual(info['edit_url'],
                         'http://example.com/IDoExist/edit_page')
开发者ID:jkrebs,项目名称:pyramid,代码行数:35,代码来源:tests.py

示例4: main

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

    # adds cornice
    config.include("cornice")

    config.registry.settings['api_key'] = settings['api_key']

    config.registry.settings['jenkins'] = Jenkins(settings['jenkins_url'], settings['jenkins_username'], settings['jenkins_password'])

    config.registry.settings['github'] = PloneGithub(settings['github_user'], settings['github_password'])

    config.registry.settings['core'] = ReposDB(settings['core_repos_db'])
    config.registry.settings['pulls'] = PullsDB(settings['core_pulls_db'])

    config.registry.settings['log_file'] = settings['log_file']

    # adds cornice
    config.include("cornice")

    config.scan("plonejenkins.middleware.views")

    config.end()

    return config.make_wsgi_app()
开发者ID:plone,项目名称:plonejenkins.middleware,代码行数:30,代码来源:__init__.py

示例5: make_app

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import end [as 别名]
def make_app(global_config, **settings):
    """ ripped from ptah/__init__.py:initializeSettings """

    config = Configurator(settings=settings)
    try:
        # This is magic land.
        ptah.initialize(None, config, global_config)
    except memphis.config.StopException:
        memphis.config.shutdown()
        raise

    # Pyramid
    app = config.make_wsgi_app()

    # Using settings file; create database connections
    # Then .create_all() schemas whose models are registered but tables do not

    Base = pyramid_sqla.get_base()
    Base.metadata.create_all() 

    config.begin()

    # Memphis, send ApplicationStarting event
    memphis.config.start(config)

    # Ptah, app initialized
    config.registry.notify(ptah.AppInitialized(app, config))

    config.end()
    config.commit()

    # commit possible transaction
    transaction.commit()

    return app
开发者ID:mcdonc,项目名称:devel,代码行数:37,代码来源:start4.py

示例6: main

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

    config.begin()
        
    config.scan('sawhoosh.model')    
    initialize_sql(engine)
    
    config.add_route('index', '')
    config.add_route('search', '/search')
    
    config.add_route('author_new', '/author/new')
    config.add_route('author_edit', '/author/{id}/edit')
    config.add_route('author_instance', pattern='/author/{id}')
    config.add_route('author', pattern='/author')
    
    config.add_route('document_new', '/document/new')
    config.add_route('document_edit', '/document/{id}/edit')
    config.add_route('document_instance', pattern='/document/{id}')
    config.add_route('document', pattern='/document')
     
    config.add_static_view('static', 'sawhoosh:static')
    config.scan('sawhoosh.views')
    
    config.end()
    return HttpMethodOverrideMiddleware(config.make_wsgi_app())
开发者ID:theresia,项目名称:sawhoosh,代码行数:35,代码来源:__init__.py

示例7: main

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


    secret = 'azazayourmom'
    authentication_policy = AuthTktAuthenticationPolicy(secret=secret)
    authorization_policy = ACLAuthorizationPolicy()
    config = Configurator(authentication_policy=authentication_policy,
                          authorization_policy=authorization_policy,
                          settings=settings)
    config.include('pyramid_chameleon')

    config.add_renderer('indentedjson', DebugRendererFactory(
        indent=4, sort_keys=True, ensure_ascii=False)
    )
    #config.add_route('appindex', 'app/\!')

    config.add_static_view('app', 'app', cache_max_age=3600)

    for name, pattern in routes:
        config.add_route(name, pattern)


    config.scan()
    config.end()

    return config.make_wsgi_app()
开发者ID:Firfi,项目名称:y-backup,代码行数:32,代码来源:__init__.py

示例8: Test_model_url_filter

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import end [as 别名]
class Test_model_url_filter(unittest.TestCase):
    def setUp(self):
        self.environment = Environment()
        from pyramid_jinja2.filters import model_url_filter
        self.environment.filters['model_url'] = model_url_filter
        from pyramid.config import Configurator
        self.config = Configurator(autocommit=True)
        self.config.begin(request=DummyRequest())

    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):
        model = DummyModel()
        rendered = self._callFUT({'model':model}, '{{model|model_url}}')
        self.assertEqual(rendered, 'http://example.com/dummy/')

    def test_filter_with_elements(self):
        model = DummyModel()
        rendered = self._callFUT({'model':model}, "{{model|model_url('edit')}}")
        self.assertEqual(rendered, 'http://example.com/dummy/edit')
开发者ID:kschuetz,项目名称:pyramid_jinja2,代码行数:28,代码来源:test_filters.py

示例9: main

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

    config = Configurator(settings=settings)
    config.end()
    return config.make_wsgi_app()
开发者ID:LaurentChemla,项目名称:CaliOpen,代码行数:9,代码来源:__init__.py

示例10: MyHandlerTests

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import end [as 别名]
class MyHandlerTests(unittest.TestCase):
    def setUp(self):
        from pyramid.config import Configurator
        import pyramid_sqla
        self.engine = pyramid_sqla.add_engine(url='sqlite://')
        self.session = pyramid_sqla.get_session()()
        self.config = Configurator(autocommit=True)
        self.config.begin()
        # Must call ``self.config.begin()`` in tests before using config.

    def tearDown(self):
        import pyramid_sqla
        self.config.end()
        # After calling ``self.config.end()``, don't use config.
        self.session = None
        pyramid_sqla.reset()

    def _makeOne(self, request):
        from simplesite.handlers import MainHandler
        return MainHandler(request)

    def test_index(self):
        request = DummyRequest()
        handler = self._makeOne(request)
        info = handler.index()
        self.assertEqual(info['project'], 'simplesite')
开发者ID:GoodRx,项目名称:pyramid_simpleform,代码行数:28,代码来源:tests.py

示例11: Test_static_url_filter

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import end [as 别名]
class Test_static_url_filter(unittest.TestCase):
    def setUp(self):
        self.environment = Environment()
        from pyramid_jinja2.filters import static_url_filter
        self.environment.filters['static_url'] = static_url_filter
        from pyramid.config import Configurator
        self.config = Configurator(autocommit=True)
        self.config.begin(request=DummyRequest())
        self.config.add_static_view('myfiles', 'dummy1:static')
        self.config.add_static_view('otherfiles/{owner}', 'dummy2:files')
       
    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({}, "{{'dummy1:static/the/quick/brown/fox.svg' | static_url }}")
        self.assertEqual(rendered, 'http://example.com/myfiles/the/quick/brown/fox.svg')

    def test_filter_with_arguments(self):
        rendered = self._callFUT({}, "{{'dummy2:files/report.txt' | static_url(owner='foo') }}")
        self.assertEqual(rendered, 'http://example.com/otherfiles/foo/report.txt')
开发者ID:kschuetz,项目名称:pyramid_jinja2,代码行数:27,代码来源:test_filters.py

示例12: AddPageTests

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import end [as 别名]
class AddPageTests(unittest.TestCase):
    def setUp(self):
        self.session = _initTestingDB()
        self.config = Configurator(autocommit=True)
        self.config.begin()

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

    def _callFUT(self, request):
        from tutorial.views import add_page
        return add_page(request)

    def test_it_notsubmitted(self):
        _registerRoutes(self.config)
        request = testing.DummyRequest()
        request.matchdict = {'pagename':'AnotherPage'}
        info = self._callFUT(request)
        self.assertEqual(info['page'].data,'')
        self.assertEqual(info['save_url'],
                         'http://example.com/add_page/AnotherPage')
        
    def test_it_submitted(self):
        from tutorial.models import Page
        _registerRoutes(self.config)
        request = testing.DummyRequest({'form.submitted':True,
                                        'body':'Hello yo!'})
        request.matchdict = {'pagename':'AnotherPage'}
        self._callFUT(request)
        page = self.session.query(Page).filter_by(name='AnotherPage').one()
        self.assertEqual(page.data, 'Hello yo!')
开发者ID:jkrebs,项目名称:pyramid,代码行数:34,代码来源:tests.py

示例13: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import end [as 别名]
def main(global_config, **settings):
    """
    Get a PyShop WSGI application configured with settings.
    """
    if sys.version_info[0] < 3:
        reload(sys)
        sys.setdefaultencoding('utf-8')

    settings = dict(settings)
    # Scoping sessions for Pyramid ensure session are commit/rollback
    # after the template has been rendered
    create_engine(settings, scoped=True)

    authn_policy = RouteSwitchAuthPolicy(secret=settings['pyshop.cookie_key'],
                                         callback=groupfinder)
    authz_policy = ACLPolicy()
    route_prefix = settings.get('pyshop.route_prefix')

    config = Configurator(settings=settings,
                          root_factory=RootFactory,
                          route_prefix = route_prefix,
                          locale_negotiator=locale_negotiator,
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy)
    config.end()

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

示例14: main

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

    # Scoping sessions for Pyramid ensure session are commit/rollback
    # after the template has been rendered
    create_engine(settings, scoped=True)

    session_factory = UnencryptedCookieSessionFactoryConfig(
        settings['pyvac.cookie_key']
    )

    authn_policy = RouteSwithchAuthPolicy(secret=settings['pyvac.cookie_key'],
                                          callback=groupfinder)
    authz_policy = ACLPolicy()

    config = Configurator(settings=settings,
                          root_factory=RootFactory,
                          locale_negotiator=locale_negotiator,
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy,
                          session_factory=session_factory)

    config.add_subscriber('pyvac.helpers.i18n.add_renderer_globals',
                          IBeforeRender)
    config.add_subscriber('pyvac.helpers.i18n.add_localizer', NewRequest)

    config.end()

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

示例15: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import end [as 别名]
def main(global_config, **settings):
    """Returns WSGI application.
    """
    import cone.app.security as security
    security.ADMIN_USER = settings.get('cone.admin_user', 'admin')
    security.ADMIN_PASSWORD = settings.get('cone.admin_password', 'admin')
    secret_password = settings.get('cone.secret_password', 'secret')
    authn_factory = settings.get('cone.authn_policy_factory', auth_tkt_factory)
    authz_factory = settings.get('cone.authz_policy_factory', acl_factory)
    config = Configurator(
        root_factory=get_root,
        settings=settings,
        authentication_policy=authn_factory(secret=secret_password,
                                            max_age=43200,
                                            include_ip=True),
        authorization_policy=authz_factory(secret=secret_password),
        autocommit=True)
    zcml_file = settings.get('configure_zcml', 'configure.zcml')
    config.include(pyramid_zcml)
    config.begin()
    config.load_zcml(zcml_file)

    theme_dir = os.path.join(APP_PATH, 'etc', 'theme', '')
    theme_css = os.path.join(APP_PATH, 'etc', 'theme', 'theme.css')
    if os.path.isdir(theme_dir):
        config.add_static_view('theme', theme_dir)
    if os.path.isfile(theme_css):
        import cone.app.browser
        cone.app.browser.ADDITIONAL_CSS.append('theme/theme.css')

    config.end()
    return config.make_wsgi_app()
开发者ID:chaoflownet,项目名称:cone.ugm,代码行数:34,代码来源:run.py


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