本文整理汇总了Python中tw2.core.make_middleware函数的典型用法代码示例。如果您正苦于以下问题:Python make_middleware函数的具体用法?Python make_middleware怎么用?Python make_middleware使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_middleware函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'
开发者ID:Cito,项目名称:tw2.core,代码行数:14,代码来源:test_template.py
示例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
开发者ID:RobertSudwarts,项目名称:tw2.core,代码行数:15,代码来源:test_widgets.py
示例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)
开发者ID:nphilipp,项目名称:tw2.jquery,代码行数:7,代码来源:test_jquery.py
示例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)
开发者ID:abele,项目名称:tw2.devtools,代码行数:30,代码来源:server.py
示例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>")
开发者ID:toscawidgets,项目名称:tw2.core,代码行数:7,代码来源:test_template.py
示例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
开发者ID:lmacken,项目名称:tw2.core,代码行数:7,代码来源:test_template.py
示例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>')
开发者ID:Cito,项目名称:tw2.core,代码行数:8,代码来源:test_template.py
示例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
开发者ID:bbcf,项目名称:biorepo,代码行数:45,代码来源:middleware.py
示例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"
开发者ID:toscawidgets,项目名称:tw2.core,代码行数:18,代码来源:test_template.py
示例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)
开发者ID:toscawidgets,项目名称:tw2.core,代码行数:9,代码来源:test_template.py
示例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
开发者ID:paj28,项目名称:tw2.core,代码行数:18,代码来源:test_widgets.py
示例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>')
开发者ID:lmacken,项目名称:tw2.core,代码行数:11,代码来源:test_template.py
示例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>',
)
开发者ID:Cito,项目名称:tw2.core,代码行数:13,代码来源:test_template.py
示例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])
开发者ID:beckastar,项目名称:cleaner_markov,代码行数:13,代码来源:base.py
示例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)
开发者ID:paj28,项目名称:tw2.core,代码行数:14,代码来源:test_widgets.py
示例16: test_widget_relative_inheritance
def test_widget_relative_inheritance(self):
twc.core.request_local()["middleware"] = twc.make_middleware(None)
# These aren't yet supported in the tests yet.
ignored_engines = ["jinja", "kajiki", "chameleon"]
for engine in engines:
if engine in ignored_engines:
continue
template = "%s:tw2.core.test_templates.child_%s" % (engine, engine)
test = twc.Widget(id="x", template=template)
expected = """
<html>
<head><title>Parent</title></head>
<body>Child</body>
</html>
"""
assert_eq_xhtml(test.display(), expected)
开发者ID:toscawidgets,项目名称:tw2.core,代码行数:18,代码来源:test_template.py
示例17: 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 gearbox 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
import tw2.sqla as tws
app = rtm.TM(app, tws.commit_veto)
if weberror:
import weberror.errormiddleware as we
app = we.ErrorMiddleware(app, debug=True)
# TODO - this got left behind in the python3 port. Revive it.
#if logging:
# import paste.translogger as pt
# app = pt.TransLogger(app)
# Handle old and new versions of gearbox.
try:
from gearbox.commands.serve import wsgiref_server_runner
except ImportError:
from gearbox.commands.server import wsgiref_server_runner
wsgiref_server_runner(
app,
host=host, port=port,
use_threadpool=use_threadpool,
threadpool_workers=threadpool_workers,
request_queue_size=request_queue_size,
)
开发者ID:toscawidgets,项目名称:tw2.devtools,代码行数:40,代码来源:server.py
示例18: 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>")
开发者ID:toscawidgets,项目名称:tw2.core,代码行数:5,代码来源:test_template.py
示例19: tw_middleware
def tw_middleware(app):
conf = {'default_view':'genshi'}
return twc.make_middleware(app, **conf)
开发者ID:abele,项目名称:tw2.devtools,代码行数:3,代码来源:cherrypy.py
示例20: __init__
def __init__(self, app):
self.app = app
self.app.extensions['toscawidgets'] = self
config = self.extract_config(self.app)
self.mw = twc.make_middleware(self.app.wsgi_app, **config)
self.app.wsgi_app = self.mw
开发者ID:dplepage,项目名称:flask-tw2,代码行数:6,代码来源:flask_tw2.py
注:本文中的tw2.core.make_middleware函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论