本文整理汇总了Python中page.Page.printed_output方法的典型用法代码示例。如果您正苦于以下问题:Python Page.printed_output方法的具体用法?Python Page.printed_output怎么用?Python Page.printed_output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类page.Page
的用法示例。
在下文中一共展示了Page.printed_output方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_response
# 需要导入模块: from page import Page [as 别名]
# 或者: from page.Page import printed_output [as 别名]
def generate_response(instance_path):
profiler = None
# capture stdout
real_stdout = sys.stdout
sys.stdout = StringIO.StringIO()
try:
try:
system.setup(instance_path)
session.load_session()
user.setup()
manager.setup()
system.subject = get_subject()
visited(system.subject, session.sid)
csrf_token = data.pop('csrf_token',None)
if request.method == 'POST' and system.csrf_validation:
if csrf_token == session.csrf_token:
del session.csrf_token
else:
raise CrossSiteRequestForgeryAttempt('expected:%s got:%s' % (session.csrf_token, csrf_token))
requested_app_name = manager.requested_app_name()
default_app_name = manager.default_app_name()
os.chdir(system.config.sites_path)
if not request.route:
request.route.append(default_app_name)
if manager.can_run(requested_app_name):
system.app = manager.get_app(requested_app_name)
profiler = system.profile and cProfile.Profile()
if profiler:
profiler.enable()
response = system.app.run()
if profiler:
profiler.disable()
elif not requested_app_name:
system.app = manager.get_app(default_app_name)
response = system.app.run()
elif manager.can_run(default_app_name):
response = redirect_to('/')
else:
response = Page('<H1>Page Missing</H1>Page not found').render()
response.status = '404'
session.save_session(response)
except CrossSiteRequestForgeryAttempt:
logger.security('cross site forgery attempt')
if not (system.config.get('error','users','0')=='1' or user.is_developer or user.is_administrator):
raise
else:
response = redirect_to('/')
except SessionExpiredException:
response = Page(load_template('system_application_session_expired', SESSION_EXPIRED_MESSAGE)).render()
except:
t = traceback.format_exc()
logger.error(t)
if system.show_errors or user.is_developer or user.is_administrator:
msg = load_template('system_application_error_developer', STANDARD_ERROR_MESSAGE)
response = Page(msg % dict(message=t)).render()
else:
msg = load_template('system_application_error_user', FRIENDLY_ERROR_MESSAGE)
response = Page(msg).render()
if profiler:
stats_s = StringIO.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(profiler, stream=stats_s)
ps.sort_stats(sortby)
ps.print_stats(.1)
t = stats_s.getvalue()
t = t.replace(system.lib_path, '~zoom'
).replace('/usr/lib/python2.7/dist-packages/','~'
).replace('/usr/local/lib/python2.7/dist-packages/','~')
print t
finally:
printed_output = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = real_stdout
if system.logging:
logger.complete()
if hasattr(response,'printed_output'):
response.printed_output = printed_output.replace('<','<').replace('>','>')
return response