FAQ
lynx <a at b.c> wrote in message
news:pJ%n5.43052$QD5.426611 at news.corecomm.net...
any good, simple work-even-remotely-alike for perl's CGI::Carp out there,
Here is something I use for debugging Python CGI scripts.
It's based on various other similar debugging scripts I found and glommed
together.
--- debug.py ---
#!/usr/bin/python
import os, sys, string
import cgi

filename = os.environ["PATH_TRANSLATED"]

# Grab the real stdout from the script we are trying to debug
import StringIO
real_stdout = sys.stdout
sys.stdout = StringIO.StringIO()

try:
execfile(filename)
real_stdout.write( sys.stdout.getvalue() )
except:
real_stdout.write ("Content-type: text/html\n\n")

real_stdout.write ("debugging: " + filename + "<br><br>")

import traceback

IOBuffer = StringIO.StringIO()
traceback.print_exc(file=IOBuffer)

HTML = IOBuffer.getvalue()
HTML = string.replace(HTML,"&","amp;")
HTML = string.replace(HTML,"<","&lt;")
HTML = string.replace(HTML,">","&gt;")
HTML = string.replace(HTML,"\n","<br>")
HTML = string.replace(HTML,"\t","&nbsp;&nbsp;&nbsp;")

real_stdout.write("<tt>")
real_stdout.write(HTML)
real_stdout.write("</tt>")

sys.exit(0)


I place this in my web's root folder and include it in the path.
Debug, send tracebacks to browser: http://adamv.com/debug.py/toy/test.py

Hope this helps,
Adam Vandenberg, Pythoneer 3rd class.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 8 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedAug 21, '00 at 2:46a
activeAug 28, '00 at 3:18p
posts8
users8
websitepython.org

People

Translate

site design / logo © 2022 Grokbase