本文整理汇总了Python中pyramid.configuration.Configurator.begin方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.begin方法的具体用法?Python Configurator.begin怎么用?Python Configurator.begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.configuration.Configurator
的用法示例。
在下文中一共展示了Configurator.begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: app
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
def app(global_config, **settings):
""" This function returns a WSGI application.
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
db_string = settings.get("db_string")
if db_string is None:
raise ValueError("No 'db_string' value in application configuration.")
db_echo = settings.get("db_echo", "false")
initialize_sql(db_string, asbool(db_echo))
config = Configurator(settings=settings)
config.begin()
config.add_static_view("static", "tutorial:static")
config.add_route("home", "/", view="tutorial.views.view_wiki")
config.add_route(
"view_page", "/:pagename", view="tutorial.views.view_page", view_renderer="tutorial:templates/view.pt"
)
config.add_route(
"add_page", "/add_page/:pagename", view="tutorial.views.add_page", view_renderer="tutorial:templates/view.pt"
)
config.add_route(
"edit_page", "/:pagename/edit_page", view="tutorial.views.edit_page", view_renderer="tutorial:templates/edit.pt"
)
config.end()
return config.make_wsgi_app()
示例2: TestIntegration
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
class TestIntegration(unittest.TestCase):
def setUp(self):
import pyramid.mako_templating
from pyramid.configuration import Configurator
self.config = Configurator()
self.config.begin()
self.config.add_settings({'mako.directories':
'pyramid.tests:fixtures'})
self.config.add_renderer('.mak',
pyramid.mako_templating.renderer_factory)
def tearDown(self):
self.config.end()
def test_render(self):
from pyramid.renderers import render
result = render('helloworld.mak', {'a':1})
self.assertEqual(result, u'\nHello föö\n')
def test_render_to_response(self):
from pyramid.renderers import render_to_response
result = render_to_response('helloworld.mak', {'a':1})
self.assertEqual(result.ubody, u'\nHello föö\n')
def test_get_renderer(self):
from pyramid.renderers import get_renderer
result = get_renderer('helloworld.mak')
self.assertEqual(result.implementation().render_unicode(),
u'\nHello föö\n')
示例3: ViewPageTests
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
class ViewPageTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
self.config = Configurator()
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')
示例4: TestSubscriber
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
class TestSubscriber(unittest.TestCase):
def setUp(self):
registry = DummyRegistry()
from pyramid.configuration import Configurator
self.config = Configurator(registry)
self.config.begin()
def tearDown(self):
self.config.end()
def _makeOne(self, *ifaces):
from pyramid.events import subscriber
return subscriber(*ifaces)
def test_register(self):
from zope.interface import Interface
class IFoo(Interface): pass
class IBar(Interface): pass
dec = self._makeOne(IFoo, IBar)
def foo(): pass
config = DummyConfigurator()
scanner = Dummy()
scanner.config = config
dec.register(scanner, None, foo)
self.assertEqual(config.subscribed, [(foo, (IFoo, IBar))])
def test___call__(self):
dec = self._makeOne()
dummy_venusian = DummyVenusian()
dec.venusian = dummy_venusian
def foo(): pass
dec(foo)
self.assertEqual(dummy_venusian.attached, [(foo, dec.register, 'bfg')])
示例5: app
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
def app(global_config, **settings):
""" This function returns a WSGI application.
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
db_string = settings.get('db_string')
if db_string is None:
raise ValueError("No 'db_string' value in application configuration.")
db_echo = settings.get('db_echo', 'false')
initialize_sql(db_string, asbool(db_echo))
config = Configurator(settings=settings)
config.begin()
config.add_static_view('static', 'tutorial:static')
config.add_route('home', '/', view='tutorial.views.view_wiki')
config.add_route('view_page', '/:pagename',
view='tutorial.views.view_page',
view_renderer='tutorial:templates/view.pt')
config.add_route('add_page', '/add_page/:pagename',
view='tutorial.views.add_page',
view_renderer='tutorial:templates/edit.pt')
config.add_route('edit_page', '/:pagename/edit_page',
view='tutorial.views.edit_page',
view_renderer='tutorial:templates/edit.pt')
config.end()
return config.make_wsgi_app()
示例6: app
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
def app(global_config, **settings):
""" This function returns a WSGI application.
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
config = Configurator(root_factory=get_root, settings=settings)
config.begin()
session_factory = session_factory_from_settings(settings)
config.set_session_factory(session_factory)
tictactroll.gamestate.set_db_path(settings.get('db_path'))
config.add_view("tictactroll.views.game", name="game",
renderer="tictactroll:templates/game.mako")
config.add_view("tictactroll.views.about", name="about",
renderer="tictactroll:templates/about.mako")
config.add_view("tictactroll.views.welcome",
renderer="tictactroll:templates/welcome.mako")
config.add_view("tictactroll.views.enter_game", name="enter_game")
config.add_view("tictactroll.views.new_game", name="new_game")
config.add_view("tictactroll.views.add_grid", name="add_grid",
renderer="json")
config.add_view("tictactroll.views.next_troll_grid",
name="next_troll_grid", renderer="json")
config.add_view("tictactroll.views.gameover_html", name="gameover",
renderer="tictactroll:templates/gameover.mako")
config.add_static_view("static", "tictactroll:static")
config.end()
return config.make_wsgi_app()
示例7: AddPageTests
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
class AddPageTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
self.config = Configurator()
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!')
示例8: TestGetSettings
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
class TestGetSettings(unittest.TestCase):
def setUp(self):
from pyramid.configuration import Configurator
from pyramid.registry import Registry
registry = Registry('testing')
self.config = Configurator(registry=registry)
self.config.begin()
from zope.deprecation import __show__
__show__.off()
def tearDown(self):
self.config.end()
from zope.deprecation import __show__
__show__.on()
def _callFUT(self):
from pyramid.settings import get_settings
return get_settings()
def test_it_nosettings(self):
self.assertEqual(self._callFUT(), None)
def test_it_withsettings(self):
settings = {'a':1}
self.config.registry.settings = settings
self.assertEqual(self._callFUT(), settings)
示例9: setUp
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
def setUp(self):
from pyramid.configuration import Configurator
config = Configurator(root_factory=self.root_factory)
config.begin()
config.load_zcml(self.config)
app = config.make_wsgi_app()
from webtest import TestApp
self.testapp = TestApp(app)
self.config = config
示例10: BaseViewTests
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
class BaseViewTests(unittest.TestCase):
def setUp(self):
config['io_device'] = {'class': MockDriver, 'kw':{}}
self.config = Configurator()
self.config.begin()
registerSettings(io_dev='')
self.front_page = get_root(None)
def tearDown(self):
self.config.end()
示例11: Base
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
class Base(object):
def setUp(self):
from pyramid.configuration import Configurator
self.config = Configurator()
self.config.begin()
import os
here = os.path.abspath(os.path.dirname(__file__))
self.templates_dir = os.path.join(here, 'fixtures')
def tearDown(self):
self.config.end()
示例12: main
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(root_factory=get_root, settings=settings)
config.begin()
config.add_view('som.views.my_view',
context='som.models.MyModel',
renderer='som:templates/mytemplate.pt')
config.add_static_view('static', 'som:static')
config.end()
return config.make_wsgi_app()
示例13: app
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
def app(global_config, **settings):
""" This function returns a WSGI application.
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
config = Configurator(root_factory=get_root, settings=settings)
config.begin()
config.load_zcml('configure.zcml')
config.end()
return config.make_wsgi_app()
示例14: app
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
def app(global_config, **settings):
db_uri = settings.get('db_uri')
db_name = settings.get('db_name')
if db_uri is None or db_name is None:
raise ValueError("db_uri AND db_name must be defined"
" in application initilization configuration file")
zcml_file = settings.get('configure_zcml', 'configure.zcml')
config = Configurator(root_factory=RootFactory, settings=settings)
config.begin()
config.load_zcml(zcml_file)
config.end()
return config.make_wsgi_app()
示例15: ViewTests
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import begin [as 别名]
class ViewTests(unittest.TestCase):
def setUp(self):
self.config = Configurator()
self.config.begin()
def tearDown(self):
self.config.end()
def test_my_view(self):
from pyramidapp.views import my_view
request = testing.DummyRequest()
info = my_view(request)
self.assertEqual(info['project'], 'pyramidapp')