Exemplo n.º 1
0
def exception_with_context():
    """
        formats the last exception as a string and adds context about the
        request.
    """
    has_request = len(rg._object_stack())
    if has_request:
        post_data = werkzeug_multi_dict_conv(rg.request.form)

        # Remove HTTP_COOKIE from the environment since it may contain sensitive info.  It will get
        # filtered and inserted next.
        environ = rg.environ.copy()
        if 'HTTP_COOKIE' in environ:
            del environ['HTTP_COOKIE']
            environ['blazeweb.cookies'] = exception_context_filter(
                rg.request.cookies)
    else:
        post_data = {}
        environ = {}
    post_data = exception_context_filter(post_data)

    retval = '\n== TRACE ==\n\n%s' % format_exc()
    if has_request:
        retval += '\n\n== ENVIRON ==\n\n%s' % pformat(environ, 4)
        retval += '\n\n== POST ==\n\n%s\n\n' % pformat(post_data, 4)
    return retval
Exemplo n.º 2
0
def exception_with_context():
    """
        formats the last exception as a string and adds context about the
        request.
    """
    has_request = len(rg._object_stack())
    if has_request:
        post_data = werkzeug_multi_dict_conv(rg.request.form)

        # Remove HTTP_COOKIE from the environment since it may contain sensitive info.  It will get
        # filtered and inserted next.
        environ = rg.environ.copy()
        if 'HTTP_COOKIE' in environ:
            del environ['HTTP_COOKIE']
            environ['blazeweb.cookies'] = exception_context_filter(rg.request.cookies)
    else:
        post_data = {}
        environ = {}
    post_data = exception_context_filter(post_data)

    retval = '\n== TRACE ==\n\n%s' % format_exc()
    if has_request:
        retval += '\n\n== ENVIRON ==\n\n%s' % pformat(environ, 4)
        retval += '\n\n== POST ==\n\n%s\n\n' % pformat(post_data, 4)
    return retval
Exemplo n.º 3
0
def abort(send):
    """
        An enhanced version of Werkzeug's abort.  `send` is handled differently
        based on what it is:

        int: assumed to be a HTTP status code; not all codes supported by
            default, see the Werkzeug documentation for an explanation.
        string/unicode: will put the string as the body of a response and send
            it.
        callable: assume its a Response object or other WSGI application; wrap
            in proxy HTTPException and raise it;
        anything else: pformat, escape, wrap in <pre> tags, and treat like
            string/unicode above.
    """
    # this is a circular import if done at the module level
    from blazeweb.wrappers import Response

    response_body = reindent(
        """
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <title>abort() Response</title>
    <h1 style="margin-bottom: 25px">abort() Response</h1>

    %s""".strip(), 0)

    if isinstance(send, int) or hasattr(send, '__call__'):
        response = send
    elif isinstance(send, six.string_types):
        response = Response(response_body % escape(send))
    else:
        response = Response(response_body %
                            ('<pre>%s</pre>' % escape(pformat(send))))
    werkzeug.abort(response)
Exemplo n.º 4
0
def abort(send):
    """
        An enhanced version of Werkzeug's abort.  `send` is handled differently
        based on what it is:

        int: assumed to be a HTTP status code; not all codes supported by
            default, see the Werkzeug documentation for an explanation.
        string/unicode: will put the string as the body of a response and send
            it.
        callable: assume its a Response object or other WSGI application; wrap
            in proxy HTTPException and raise it;
        anything else: pformat, escape, wrap in <pre> tags, and treat like
            string/unicode above.
    """
    # this is a circular import if done at the module level
    from blazeweb.wrappers import Response

    response_body = reindent("""
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <title>abort() Response</title>
    <h1 style="margin-bottom: 25px">abort() Response</h1>

    %s""".strip(), 0)

    if isinstance(send, int) or hasattr(send, '__call__'):
        response = send
    elif isinstance(send, six.string_types):
        response = Response(response_body % escape(send))
    else:
        response = Response(response_body % ('<pre>%s</pre>' % escape(pformat(send))))
    werkzeug.abort(response)
Exemplo n.º 5
0
def test_pformat():
    # just making sure no errors
    pformat('')
Exemplo n.º 6
0
def test_pformat():
    # just making sure no errors
    pformat('')