本文整理汇总了Python中tw2.core.make_middleware函数的典型用法代码示例。如果您正苦于以下问题:Python make_middleware函数的具体用法?Python make_middleware怎么用?Python make_middleware使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_middleware函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rendering_extension_propagation
def test_rendering_extension_propagation(self):
mw = twc.make_middleware(None, preferred_rendering_engines=['genshi', 'jinja'],
rendering_extension_lookup={'genshi':['genshi', 'html'],
'jinja':['jinja']})
assert twc.templating.get_engine_name('tw2.core.test_templates.parent_genshi', mw) == 'genshi'
#flush caches to avoid wrong results due to cached results
twc.util.flush_memoization()
twc.templating.engine_name_cache = {}
mw = twc.make_middleware(None, preferred_rendering_engines=['genshi', 'jinja'],
rendering_extension_lookup={'genshi':['genshi'],
'jinja':['jinja', 'html']})
assert twc.templating.get_engine_name('tw2.core.test_templates.parent_genshi', mw) == 'jinja'
示例2: test_params_as_vars
def test_params_as_vars(self):
import mako
class MyTest(twc.Widget):
template = 'mako:tw2.core.test_templates.simple_mako'
test= twc.Param('blah', default='hello')
testapi.request(1)
twc.core.request_local()['middleware'] = twc.make_middleware(None, params_as_vars=True)
MyTest.display()
twc.core.request_local()['middleware'] = twc.make_middleware(None, params_as_vars=False)
try:
MyTest.display()
assert(False)
except TypeError:
# this will raise a type error because "Undefined" is found (not a string)
pass
示例3: test_jquery_script_name
def test_jquery_script_name():
twc.core.request_local()['middleware'] = \
twc.make_middleware(script_name='/lol')
from tw2.jquery import jquery_js
twc.core.request_local()['middleware'].script_name = '/lol'
the_link = '/lol/resources/tw2.jquery/static/jquery/1.7.1/jquery.js'
eq_(jquery_js.req().link, the_link)
示例4: dev_server
def dev_server(
app=None, host='127.0.0.1', port=8000, logging=True, weberror=True,
use_threadpool=None, threadpool_workers=10, request_queue_size=5,
repoze_tm=False, **config):
"""
Run a development server, hosting the ToscaWidgets application.
This requires Paste and WebError, which are only sure to be available if
tw2.devtools is installed.
"""
config.setdefault('debug', True)
config.setdefault('controller_prefix', '/')
app = twc.make_middleware(app, **config)
if repoze_tm:
import repoze.tm as rtm, tw2.sqla as tws
app = rtm.TM(app, tws.commit_veto)
if weberror:
import weberror.errormiddleware as we
app = we.ErrorMiddleware(app, debug=True)
if logging:
import paste.translogger as pt
app = pt.TransLogger(app)
import paste.httpserver as ph
ph.serve(app, host=host, port=port,
use_threadpool=use_threadpool,
threadpool_workers=threadpool_workers,
request_queue_size=request_queue_size)
示例5: test_widget_nesting
def test_widget_nesting(self):
twc.core.request_local()["middleware"] = twc.make_middleware(None)
for outer, inner in itertools.product(engines, engines):
outer = "%s:tw2.core.test_templates.widget_%s" % (outer, outer)
inner = "%s:tw2.core.test_templates.inner_%s" % (inner, inner)
test = twc.CompoundWidget(id="x", template=outer, children=[TestWD(id="y", template=inner)])
eq_(test.display(), "<p>TEST <p>TEST bob</p></p>")
示例6: _check_render
def _check_render(self, template, data, expected, engine=None):
if engine:
mw = twc.make_middleware(None, preferred_rendering_engines=[engine])
testapi.request(1, mw)
out = twc.template.EngineManager().render(template, 'string', data)
assert(isinstance(out, unicode))
assert out == expected, out
示例7: test_widget_display
def test_widget_display(self):
twc.core.request_local()['middleware'] = twc.make_middleware(None)
mtest = TestWD(id='x')
for eng in engines:
test = mtest.req()
test.template = '%s:tw2.core.test_templates.inner_%s' % (eng, eng)
out = test.display()
eq_(out, '<p>TEST bob</p>')
示例8: make_app
def make_app(global_conf, full_stack=True, **app_conf):
"""
Set biorepo up with the settings found in the PasteDeploy configuration
file used.
@param global_conf: The global settings for biorepo (those
defined under the ``[DEFAULT]`` section).
@type global_conf: dict
@param full_stack: Should the whole TG2 stack be set up?
@type full_stack: str or bool
@return: The biorepo application with all the relevant middleware
loaded.
This is the PasteDeploy factory for the biorepo application.
``app_conf`` contains all the application-specific settings (those defined
under ``[app:main]``.
"""
#app = make_base_app(global_conf, full_stack=True, **app_conf)
####begin test
inject_resources = True
serve_resources = True
if 'prefix' in app_conf:
custom = lambda app: twc.make_middleware(app, serve_resources=serve_resources, inject_resources=inject_resources, script_name=app_conf['prefix'])
print app_conf['prefix'], "------- prefix"
else:
custom = lambda app: twc.make_middleware(app, serve_resources=serve_resources, inject_resources=inject_resources)
print "------ no prefix found"
app = make_base_app(global_conf, wrap_app=custom, full_stack=True, **app_conf)
####end test
# Wrap your base TurboGears 2 application with custom middleware here
# This custom middleware is about authentication
app = make_middleware_with_config(
app,
global_conf,
app_conf.get('who.config_file', 'who.ini'),
app_conf.get('who.log_file', 'auth.log'),
app_conf.get('who.log_level', 'debug')
)
return app
示例9: test_rendering_extension_propagation
def test_rendering_extension_propagation(self):
mw = twc.make_middleware(
None,
preferred_rendering_engines=["genshi", "jinja"],
rendering_extension_lookup={"genshi": ["genshi", "html"], "jinja": ["jinja"]},
)
assert twc.templating.get_engine_name("tw2.core.test_templates.parent_genshi", mw) == "genshi"
# flush caches to avoid wrong results due to cached results
twc.util.flush_memoization()
twc.templating.engine_name_cache = {}
mw = twc.make_middleware(
None,
preferred_rendering_engines=["genshi", "jinja"],
rendering_extension_lookup={"genshi": ["genshi"], "jinja": ["jinja", "html"]},
)
assert twc.templating.get_engine_name("tw2.core.test_templates.parent_genshi", mw) == "jinja"
示例10: _check_render
def _check_render(self, template, data, expected, engine=None):
if engine:
mw = twc.make_middleware(None, preferred_rendering_engines=[engine])
testapi.request(1, mw)
twc.util.flush_memoization()
out = twc.templating.render(template, "string", data)
assert isinstance(out, six.text_type)
eq_(out, expected)
示例11: test_params_as_vars
def test_params_as_vars(self):
import mako
class MyTest(twc.Widget):
template = "mako:tw2.core.test_templates.simple_mako"
test = twc.Param("blah", default="hello")
testapi.request(1)
twc.core.request_local()["middleware"] = twc.make_middleware(None, params_as_vars=True)
MyTest.display()
twc.core.request_local()["middleware"] = twc.make_middleware(None, params_as_vars=False)
try:
MyTest.display()
assert False
except NameError:
# this will raise a name error because "Undefined"
# is found (not a string)
pass
示例12: test_widget_nesting
def test_widget_nesting(self):
twc.core.request_local()['middleware'] = twc.make_middleware(None)
for outer in engines:
for inner in engines:
test = twc.CompoundWidget(id='x',
template = '%s:tw2.core.test_templates.widget_%s' % (outer, outer),
children=[
TestWD(id='y', template='%s:tw2.core.test_templates.inner_%s' % (inner, inner)),
]
)
assert(test.display().replace(kid_prefix, '') == '<p>TEST <p>TEST bob</p></p>')
示例13: test_auto_select_unavailable_engine_not_strict
def test_auto_select_unavailable_engine_not_strict(self):
engine = 'mako'
mw = twc.make_middleware(
None,
preferred_rendering_engines=[engine],
strict_engine_selection=False,
)
testapi.request(501, mw)
self._check_render(
'tw2.core.test_templates.simple_genshi',
{'test':'blah!'},
'<p>TEST blah!</p>',
)
示例14: setup
def setup(self):
global _request_local
_request_local = {}
self.mw = twc.make_middleware(self)
self.app = wt.TestApp(self.mw)
js = twc.JSLink(link='paj')
css = twc.CSSLink(link='joe')
TestWidget = twc.Widget(
template='genshi:tw2.core.test_templates.inner_genshi',
test='test',
)
self.inject_widget = TestWidget(id='a', resources=[js, css])
示例15: testAddCall
def testAddCall(self):
class T(wd.Widget):
test = twc.Param("blah", default="hello")
template = "mako:tw2.core.test_templates.simple_mako"
i = T(id="foo").req()
jscall = ["somefunc", "bodybottom"]
i.add_call(jscall[0], jscall[1])
self.assert_(jscall in i._js_calls)
testapi.request(1)
twc.core.request_local()["middleware"] = twc.make_middleware(None, params_as_vars=True)
res = i.display(displays_on="string")
self.assert_(res)
self.assert_(i.resources)