Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(8)  |  Call(4)  |  Derive(0)  |  Import(4)
Display the response content with a error reaceback in a webbrowser.
TODO: We should delete the temp files after viewing!

        def debug_response(response, browser_traceback=True, msg="", display_tb=True):
    """
    Display the response content with a error reaceback in a webbrowser.
    TODO: We should delete the temp files after viewing!
    """
    global BROWSER_TRACEBACK_OPENED
    if browser_traceback != True or BROWSER_TRACEBACK_OPENED == True:
        return
    # Save for the next traceback
    BROWSER_TRACEBACK_OPENED = True

    content = response.content.decode("utf-8")
    url = response.request["PATH_INFO"]

    stack_info = get_stack_info(filepath_filter="django_tools")
    stack_info.append(msg)
    if display_tb:
        print
        print "debug_response:"
        print "-" * 80
        print "\n".join(stack_info)
        print "-" * 80

    stack_info = escape("".join(stack_info))

    response_info = "
\n" response_info += "\t

template

\n" if hasattr(response, "templates") and response.templates: try: templates = pformat([template.name for template in response.templates]) except AttributeError: templates = "---" else: templates = "---" response_info += "\t
%s
\n" % templates response_info += "\t

messages

\n" msg = messages.get_messages(response.request) if msg: msg = "".join(["%s\n" % x for x in msg]) else: msg = "---" response_info += "\t
%s
\n" % msg for attr in RESPONSE_INFO_ATTR: # FIXME: There must be exist a easier way to display the info response_info += "\t

%s

\n" % attr value = getattr(response, attr, "---") value = pformat(value) value = escape(value) response_info += "\t
%s
\n" % value response_info += "\t

settings

\n" response_info += "\t
%s
\n" % pformat(get_safe_settings()) response_info += "
\n" if "" in content: info = ( "\n

\n" "

Unittest info

\n" "
\n" "

url:

%s
\n" "

traceback:

%s
\n" "

response info:

%s\n" "
\n" "" ) % (url, stack_info, response_info) content = content.replace("", info) else: # Not a html page? content += "\n
\n"
        content += "-" * 79
        content += (
            "\nUnittest info\n"
            "=============\n"
            "url: %s\n"
            "traceback:\n%s\n
" "response info:\n%s\n" ) % (url, stack_info, response_info) fd, file_path = tempfile.mkstemp(prefix="PyLucid_unittest_", suffix=".html") os.write(fd, content.encode("utf-8")) os.close(fd) url = "file://%s" % file_path print "\nDEBUG html page in Browser! (url: %s)" % url try: webbrowser.open(url) except: pass


src/d/j/django-dbpreferences-0.4.5.0803/dbpreferences/tests/unittest_base.py   django-dbpreferences(Download)
from django.contrib.auth.models import User
 
from BrowserDebug import debug_response
 
 
        def error(respose, msg):
            debug_response(
                response, self.one_browser_traceback, msg, display_tb=False
            )
            raise self.failureException, msg

src/d/j/django-tools-0.25.1/django_tools/unittest_utils/unittest_base.py   django-tools(Download)
from django.utils.unittest.util import safe_repr
 
from BrowserDebug import debug_response
import difflib
 
    def raise_browser_traceback(self, response, msg):
        debug_response(
            response, self.browser_traceback, msg, display_tb=False
        )
        msg += " (url: %r)" % response.request.get("PATH_INFO", "???")

src/d/j/django-tools-HEAD/django_tools/unittest_utils/unittest_base.py   django-tools(Download)
from django.utils.unittest.util import safe_repr
 
from BrowserDebug import debug_response
import difflib
 
    def raise_browser_traceback(self, response, msg):
        debug_response(
            response, self.browser_traceback, msg, display_tb=False
        )
        msg += " (url: %r)" % response.request.get("PATH_INFO", "???")

src/d/j/django-dbpreferences-HEAD/dbpreferences/tests/unittest_base.py   django-dbpreferences(Download)
from django.contrib.auth.models import User
 
from BrowserDebug import debug_response
 
 
        def error(respose, msg):
            debug_response(
                response, self.one_browser_traceback, msg, display_tb=False
            )
            raise self.failureException, msg