本文整理汇总了Python中tg.configuration.AppConfig.use_transaction_manager方法的典型用法代码示例。如果您正苦于以下问题:Python AppConfig.use_transaction_manager方法的具体用法?Python AppConfig.use_transaction_manager怎么用?Python AppConfig.use_transaction_manager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tg.configuration.AppConfig
的用法示例。
在下文中一共展示了AppConfig.use_transaction_manager方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sqlalchemy_retry
# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import use_transaction_manager [as 别名]
def test_sqlalchemy_retry(self):
fake_transaction = FakeTransaction()
import transaction
prev_transaction_manager = transaction.manager
transaction.manager = fake_transaction
from transaction.interfaces import TransientError
class RootController(TGController):
attempts = []
@expose()
def test(self):
self.attempts.append(True)
if len(self.attempts) == 3:
return 'HI!'
raise TransientError()
package = PackageWithModel()
conf = AppConfig(minimal=True, root_controller=RootController())
conf.package = package
conf.model = package.model
conf.use_sqlalchemy = True
conf.use_transaction_manager = True
conf['sqlalchemy.url'] = 'sqlite://'
conf['tm.attempts'] = 3
app = conf.make_wsgi_app()
app = TestApp(app)
resp = app.get('/test')
assert 'HI' in resp
transaction.manager = prev_transaction_manager
示例2: test_sqlalchemy_doom
# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import use_transaction_manager [as 别名]
def test_sqlalchemy_doom(self):
fake_transaction = FakeTransaction()
import transaction
prev_transaction_manager = transaction.manager
transaction.manager = fake_transaction
class RootController(TGController):
@expose()
def test(self):
fake_transaction.doom()
return 'HI!'
package = PackageWithModel()
conf = AppConfig(minimal=True, root_controller=RootController())
conf.package = package
conf.model = package.model
conf.use_sqlalchemy = True
conf.use_transaction_manager = True
conf['sqlalchemy.url'] = 'sqlite://'
app = conf.make_wsgi_app()
app = TestApp(app)
app.get('/test')
assert fake_transaction.aborted == True
transaction.manager = prev_transaction_manager
示例3: test_sqlalchemy_commit_veto
# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import use_transaction_manager [as 别名]
def test_sqlalchemy_commit_veto(self):
class RootController(TGController):
@expose()
def test(self):
return 'HI!'
@expose()
def crash(self):
raise Exception('crash')
@expose()
def forbidden(self):
response.status = 403
return 'FORBIDDEN'
@expose()
def notfound(self):
response.status = 404
return 'NOTFOUND'
def custom_commit_veto(environ, status, headers):
if status.startswith('404'):
return True
return False
fake_transaction = FakeTransaction()
import transaction
prev_transaction_manager = transaction.manager
transaction.manager = fake_transaction
package = PackageWithModel()
conf = AppConfig(minimal=True, root_controller=RootController())
conf.package = package
conf.model = package.model
conf.use_sqlalchemy = True
conf.use_transaction_manager = True
conf['sqlalchemy.url'] = 'sqlite://'
conf.commit_veto = custom_commit_veto
app = conf.make_wsgi_app()
app = TestApp(app)
app.get('/test')
assert fake_transaction.aborted == False
try:
app.get('/crash')
except:
pass
assert fake_transaction.aborted == True
app.get('/forbidden', status=403)
assert fake_transaction.aborted == False
app.get('/notfound', status=404)
assert fake_transaction.aborted == True
transaction.manager = prev_transaction_manager
示例4: AppConfig
# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import use_transaction_manager [as 别名]
"""
from tg.configuration import AppConfig
import tghello
from tghello import model
from tghello.lib import app_globals, helpers
base_config = AppConfig()
base_config.renderers = []
base_config.prefer_toscawidgets2 = True
base_config.package = tghello
#Enable json in expose
base_config.renderers.append('json')
#Enable genshi in expose to have a lingua franca for extensions and pluggable apps
#you can remove this if you don't plan to use it.
base_config.renderers.append('genshi')
#Set the default renderer
base_config.default_renderer = 'jinja'
base_config.renderers.append('jinja')
base_config.jinja_extensions = ['jinja2.ext.with_']
#Configure the base Ming Setup
base_config.use_ming = True
base_config.use_sqlalchemy=False
base_config.use_transaction_manager=False
示例5: on_startup
# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import use_transaction_manager [as 别名]
#Enable json in expose
base_config.renderers.append('json')
#Set the default renderer
base_config.default_renderer = 'genshi'
base_config.renderers.append('genshi')
#base_config.renderers.append('mako')
# if you want raw speed and have installed chameleon.genshi
# you should try to use this renderer instead.
# warning: for the moment chameleon does not handle i18n translations
#base_config.renderers.append('chameleon_genshi')
#Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = model
base_config.DBSession = model.DBSession
base_config.use_transaction_manager = True
base_config.use_toscawidgets = True
base_config.use_toscawidgets2 = True
# HOOKS
def on_startup():
import datetime
print ' --- starting application --- ' + str(datetime.datetime.now())
if tg.config.get('plugin.service.url') is None:
print 'WARNING : YOU MUST SET THE "plugin.service.url" in your config file.'
if tg.config.get('plugin.shared.key') is None:
print 'WARNING : YOU MUST SET THE "plugin.shared.key" in your config file.'