@@ -3,38 +3,60 @@ \section{\module{cgitb} ---
33
44\declaremodule {standard}{cgitb}
55\modulesynopsis {Configurable traceback handler for CGI scripts.}
6- \moduleauthor {Ka
Ping Yee}{
[email protected] }
6+ \moduleauthor {Ka
- Ping Yee}{
[email protected] }
77\sectionauthor {Fred L. Drake, Jr.}{
[email protected] }
88
9+ \versionadded {2.2}
10+ \index {CGI!exceptions}
911\index {CGI!tracebacks}
12+ \index {exception!in CGI scripts}
1013\index {traceback!in CGI scripts}
1114
1215The \module {cgitb} module provides a special exception handler for CGI
13- scripts. Using this module, an exception raised and left uncaught in
14- a CGI script can be presented as colorized HTML in the user's Web
15- browser. The options to the \function {enable()} function can be used
16- to control whether the colorized traceback is presented and whether
17- the traceback is logged to a file for later analysis.
16+ scripts. After this module is activated using the \function {enable()}
17+ function, if an uncaught exception occurs, a detailed, formatted
18+ report will be sent to the Web browser. The report includes a
19+ traceback showing excerpts of the source code for each level, as well
20+ as the values of the arguments and local variables to currently
21+ running functions, to help you debug the problem. Optionally, you can
22+ save this information to a file instead of sending it to the browser.
23+
24+ To enable this feature, simply add one line to the top of your CGI script:
25+
26+ \begin {verbatim }
27+ import cgitb; cgitb.enable()
28+ \end {verbatim }
29+
30+ The options to the \function {enable()} function control whether the
31+ report is displayed in the browser and whether the report is logged
32+ to a file for later analysis.
1833
1934
2035\begin {funcdesc }{enable}{\optional {display\optional {, logdir\optional {,
2136 context}}}}
2237 This function causes the \module {cgitb} module to take over the
23- interpreters default handling for exceptions that propogate out of
24- the top level of a script. The causes \module {cgitb} to set the
38+ interpreter's default handling for exceptions by setting the
2539 value of \code {\refmodule {sys}.excepthook}.
40+ \withsubitem {(in module sys)}{\ttindex {excepthook()}}
2641
27- The optional argument \var {display} defaults to true and can be set
28- to false to suppress sending the traceback to the browser.
29- \var {logdir}, if given, should be a directory to cause tracebacks to
30- be written to files there; by default tracebacks will not be written
31- to files. \var {context} is the number of lines of context around
32- the offending line in a traceback display; this defaults to
33- \code {5}.
42+ The optional argument \var {display} defaults to \code {1} and can be set
43+ to \code {0} to suppress sending the traceback to the browser.
44+ If the argument \var {logdir} is present, the traceback reports are
45+ written to files. The value of \var {logdir} should be a directory
46+ where these files will be placed.
47+ The optional argument \var {context} is the number of lines of
48+ context to display around the current line of source code in the
49+ traceback; this defaults to \code {5}.
3450\end {funcdesc }
3551
3652\begin {funcdesc }{handler}{\optional {info}}
37- This function handles an exception using the default settings. This
38- can be used when you've caught an exception and want to report it
39- using \module {cgitb}, but need to continue processing.
53+ This function handles an exception using the default settings
54+ (that is, show a report in the browser, but don't log to a file).
55+ This can be used when you've caught an exception and want to
56+ report it using \module {cgitb}. The optional \var {info} argument
57+ should be a 3-tuple containing an exception type, exception
58+ value, and traceback object, exactly like the tuple returned by
59+ \code {\refmodule {sys}.exc_info()}. If the \var {info} argument
60+ is not supplied, the current exception is obtained from
61+ \code {\refmodule {sys}.exc_info()}.
4062\end {funcdesc }
0 commit comments