本文整理汇总了Python中aspen.website.Website.handle_safely方法的典型用法代码示例。如果您正苦于以下问题:Python Website.handle_safely方法的具体用法?Python Website.handle_safely怎么用?Python Website.handle_safely使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aspen.website.Website
的用法示例。
在下文中一共展示了Website.handle_safely方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from aspen.website import Website [as 别名]
# 或者: from aspen.website.Website import handle_safely [as 别名]
def __call__(self, path='/', *a):
"""Given an URL path, return
This only allows you to simulate GET requests with no querystring, so
it's limited. But it's a something. Kind of. Almost.
"""
website = Website(self.argv + list(a))
request = StubRequest(path)
request.website = website
response = website.handle_safely(request)
return response
示例2: test_configuration_script_can_set_renderer_default
# 需要导入模块: from aspen.website import Website [as 别名]
# 或者: from aspen.website.Website import handle_safely [as 别名]
def test_configuration_script_can_set_renderer_default():
CONFIG = """
website.renderer_default="stdlib_format"
"""
SIMPLATE = """
name="program"
[----]
Greetings, {name}!
"""
mk(
('.aspen/configure-aspen.py', CONFIG),
('index.html.spt', SIMPLATE)
)
w = Website(['--www_root', FSFIX, '-p', fix('.aspen'), '--show_tracebacks=yes'])
request = StubRequest(b'/')
request.website = w
response = w.handle_safely(request)
actual = response.body.strip()
expected = 'Greetings, program!'
assert actual == expected, actual
示例3: test_double_failure_still_sets_response_dot_request
# 需要导入模块: from aspen.website import Website [as 别名]
# 或者: from aspen.website.Website import handle_safely [as 别名]
def test_double_failure_still_sets_response_dot_request():
mk( '.aspen'
, ('.aspen/foo.py', """
def bar(response):
response.request
""")
, ( '.aspen/configure-aspen.py'
, 'import foo\nwebsite.hooks.outbound.append(foo.bar)'
)
, ('index.html.spt', "raise heck\n[---]\n")
)
# Intentionally break the website object so as to trigger a double failure.
project_root = os.path.join(FSFIX, '.aspen')
website = Website(['--www_root='+FSFIX, '--project_root='+project_root])
del website.renderer_factories
response = website.handle_safely(StubRequest())
expected = 500
actual = response.code
assert actual == expected, actual
示例4: bar
# 需要导入模块: from aspen.website import Website [as 别名]
# 或者: from aspen.website.Website import handle_safely [as 别名]
, ('.aspen/foo.py', """
def bar(response):
response.request
""")
, ( '.aspen/configure-aspen.py'
, 'import foo\nwebsite.hooks.outbound.append(foo.bar)'
)
, ('index.html', "raise heck")
)
# Intentionally break the website object so as to trigger a double failure.
project_root = os.path.join(FSFIX, '.aspen')
website = Website(['--www_root='+FSFIX, '--project_root='+project_root])
del website.renderer_factories
response = website.handle_safely(StubRequest())
expected = 500
actual = response.code
assert actual == expected, actual
def test_website_doesnt_clobber_outbound():
mk( ( '.aspen/configure-aspen.py'
, 'import random\nwebsite.hooks.outbound.append(random.choice)'
)
)
project_root = os.path.join(FSFIX, '.aspen')
website = Website(['--www_root='+FSFIX, '--project_root='+project_root])