当前位置: 首页>>代码示例>>Python>>正文


Python Page.printed_output方法代码示例

本文整理汇总了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('<','&lt;').replace('>','&gt;')

    return response
开发者ID:hwaring,项目名称:python-zoom,代码行数:100,代码来源:startup.py


注:本文中的page.Page.printed_output方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。