本文整理汇总了Python中pyramid.config.Configurator.begin方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.begin方法的具体用法?Python Configurator.begin怎么用?Python Configurator.begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_app
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [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
示例2: base_configure
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [as 别名]
def base_configure(global_config, **settings):
"""Resolve dotted names in settings, include plug-ins and create a
Configurator.
"""
from kotti.resources import appmaker
for key, value in conf_defaults.items():
settings.setdefault(key, value)
# Allow extending packages to change 'settings' w/ Python:
_resolve_dotted(settings, keys=('kotti.configurators',))
for func in settings['kotti.configurators']:
func(settings)
_resolve_dotted(settings)
secret1 = settings['kotti.secret']
settings.setdefault('kotti.secret2', secret1)
config = Configurator(
settings=settings,
)
config.begin()
# Include modules listed in 'kotti.base_includes' and 'kotti.includes':
for module in settings['kotti.base_includes']:
config.include(module)
config.commit()
for module in settings['kotti.includes']:
config.include(module)
config.commit()
engine = engine_from_config(settings, 'sqlalchemy.')
config._set_root_factory(appmaker(engine))
return config
示例3: Test_static_url_filter
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [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')
示例4: AddPageTests
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [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!')
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [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()
示例6: MyHandlerTests
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [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')
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [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())
示例8: Test_model_url_filter
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [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')
示例9: Test_route_url_filter
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [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')
示例10: configure
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [as 别名]
def configure(global_config, **settings):
config = Configurator(settings=settings)
config.begin()
config.include('cornice')
config.scan(ignore=['.testing', '.tests'])
config.commit()
return config
示例11: ViewPageTests
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [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')
示例12: base_configure
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [as 别名]
def base_configure(global_config, **settings):
"""Resolve dotted names in settings, include plug-ins and create a
Configurator.
"""
from kotti.resources import appmaker
for key, value in conf_defaults.items():
settings.setdefault(key, value)
for key, value in settings.items():
if isinstance(settings[key], basestring):
settings[key] = unicode(value, "utf8")
# Allow extending packages to change 'settings' w/ Python:
_resolve_dotted(settings, keys=("kotti.configurators",))
for func in settings["kotti.configurators"]:
func(settings)
_resolve_dotted(settings)
secret1 = settings["kotti.secret"]
settings.setdefault("kotti.secret2", secret1)
# BBB: Merge ``kotti.includes`` into pyramid.includes.
if settings["kotti.includes"]:
warnings.warn(
"The 'kotti.includes' setting has been deprecated as of " "Kotti 0.6.1. Use 'pyramid.includes' instead.",
DeprecationWarning,
)
settings.setdefault("pyramid.includes", "")
settings["pyramid.includes"] += " " + settings["kotti.includes"]
# We'll process ``pyramid_includes`` later by hand, to allow
# overrides of configuration from ``kotti.base_includes``:
pyramid_includes = settings.pop("pyramid.includes", "")
config = Configurator(settings=settings)
config.begin()
config.registry.settings["pyramid.includes"] = pyramid_includes
# Include modules listed in 'kotti.base_includes':
for module in settings["kotti.base_includes"]:
config.include(module)
config.commit()
# Modules in 'pyramid.includes' may override 'kotti.base_includes':
if pyramid_includes:
for module in pyramid_includes.split():
config.include(module)
config.commit()
engine = engine_from_config(settings, "sqlalchemy.")
config._set_root_factory(appmaker(engine))
# add the authenticated user to the request object
from kotti.security import get_user
config.set_request_property(get_user, name="user", reify=True)
return config
示例13: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [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()
示例14: base_configure
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [as 别名]
def base_configure(global_config, **settings):
# Resolve dotted names in settings, include plug-ins and create a
# Configurator.
from kotti.resources import get_root
for key, value in conf_defaults.items():
settings.setdefault(key, value)
for key, value in settings.items():
if key.startswith('kotti') and isinstance(value, basestring):
settings[key] = unicode(value, 'utf8')
# Allow extending packages to change 'settings' w/ Python:
k = 'kotti.configurators'
for func in _resolve_dotted(settings, keys=(k,))[k]:
func(settings)
settings = _resolve_dotted(settings)
secret1 = settings['kotti.secret']
settings.setdefault('kotti.secret2', secret1)
# We'll process ``pyramid_includes`` later by hand, to allow
# overrides of configuration from ``kotti.base_includes``:
pyramid_includes = settings.pop('pyramid.includes', '')
config = Configurator(
request_factory=settings['kotti.request_factory'][0],
settings=settings)
config.begin()
config.hook_zca()
config.include('pyramid_zcml')
# Chameleon bindings were removed from Pyramid core since pyramid>=1.5a2
config.include('pyramid_chameleon')
config.registry.settings['pyramid.includes'] = pyramid_includes
# Include modules listed in 'kotti.base_includes':
for module in settings['kotti.base_includes']:
config.include(module)
config.commit()
# Modules in 'pyramid.includes' and 'kotti.zcml_includes' may
# override 'kotti.base_includes':
if pyramid_includes:
for module in pyramid_includes.split():
config.include(module)
for name in settings['kotti.zcml_includes'].strip().split():
config.load_zcml(name)
config.commit()
config._set_root_factory(get_root)
return config
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import begin [as 别名]
def main(global_config, **settings):
""" This is your application startup."""
config = Configurator(settings=settings,
session_factory = session_factory,
authentication_policy = auth_policy)
# config.commit()
# config.begin()
# init ptah settings
config.ptah_init_settings()
# init sqlalchemy engine
config.ptah_init_sql()
# configure ptah manage
config.ptah_init_manage(
managers = ['*'],
disable_modules = ['rest', 'introspect', 'apps', 'permissions'])
# we love them routes
config.add_route('root', '/')
config.add_route('contact-us', '/contact-us.html')
config.add_route('edit-objects', '/objects/{id}/edit',
factory=models.rackobject.factory, use_global_views=True)
config.add_route('add-object', '/objects/add.html')
config.add_route('login', '/login.html')
config.add_route('logout', '/logout.html')
# static assets
config.add_static_view('rackptahbles', 'rackptahbles:static')
config.scan()
# create sql tables
Base = ptah.get_base()
Base.metadata.create_all()
transaction.commit()
# populate database
config.commit()
config.begin()
Session = ptah.get_session()
# admin user
user = Session.query(User).first()
if user is None:
user = User('Admin', 'admin', '[email protected]', '12345')
Session.add(user)
#bootstrap data here, removed rackptahbles link population
# Need to commit bootstrap data to database manually.
transaction.commit()
return config.make_wsgi_app()