WebKit.ExceptionHandler | index /usr/local/share/webware/WebKit/ExceptionHandler.py

`Exception handling.`

Modules
`` |  |
os poplib | smtplib sys | traceback |

Classes
`` |  | __builtin__.object ExceptionHandler Singleton
class ExceptionHandler(__builtin__.object)
`` | `Exception handling. ExceptionHandler is a utility class for Application that is created to handle a particular exception. The object is a one-shot deal. After handling an exception, it should be removed. At some point, the exception handler sends `writeExceptionReport` to the transaction (if present), which in turn sends it to the other transactional objects (application, request, response, etc.) The handler is the single argument for this message. Classes may find it useful to do things like this:: exceptionReportAttrs = 'foo bar baz'.split() def writeExceptionReport(self, handler): handler.writeTitle(self.__class__.__name__) handler.writeAttrs(self, self.exceptionReportAttrs) The handler write methods that may be useful are: * write * writeTitle * writeDict * writeAttrs Derived classes must not assume that the error occured in a transaction. self._tra may be None for exceptions outside of transactions. **HOW TO CREATE A CUSTOM EXCEPTION HANDLER** In the ``__init__.py`` of your context:: from WebKit.ExceptionHandler import ExceptionHandler as _ExceptionHandler class ExceptionHandler(_ExceptionHandler): _hideValuesForFields = _ExceptionHandler._hideValuesForFields + ['foo', 'bar'] def work(self): _ExceptionHandler.work(self) # do whatever # override other methods if you like def contextInitialize(app, ctxPath): app._exceptionHandlerClass = ExceptionHandler You can also control the errors with settings in ``Application.config```
| Methods defined here: __init__(self, application, transaction, excInfo, formatOptions=None) `Create an exception handler instance. ExceptionHandler instances are created anew for each exception. Instantiating ExceptionHandler completes the process -- the caller need not do anything else.` basicServletName(self) `The base name for the servlet (sans directory).` emailException(self, htmlErrMsg) `Email the exception. Send the exception via mail, either as an attachment, or as the body of the mail.` errorPageFilename(self) `Create filename for error page. Construct a filename for an HTML error page, not including the ``ErrorMessagesDir`` setting (which `saveError` adds on).` filterDictValue(self, value, key, dict) `Filter dictionary values. Filters keys from a dict. Currently ignores the dictionary, and just filters based on the key.` filterValue(self, value, key) `Filter values. This is the core filter method that is used in all filtering. By default, it simply returns self._hiddenString if the key is in self._hideValuesForField (case insensitive). Subclasses could override for more elaborate filtering techniques.` htmlDebugInfo(self) `Return the debug info. Return HTML-formatted debugging information about the current exception. Calls `writeHTML`, which uses ``write(...)`` to add content.` logExceptionToConsole(self, stderr=None) `Log an exception. Logs the time, servlet name and traceback to the console (typically stderr). This usually results in the information appearing in console/terminal from which AppServer was launched.` logExceptionToDisk(self, errorMsgFilename=None) `Log the exception to disk. Writes a tuple containing (date-time, filename, pathname, exception-name, exception-data,error report filename) to the errors file (typically 'Errors.csv') in CSV format. Invoked by `handleException`.` privateErrorPage(self) `Return a private error page. Returns an HTML page intended for the developer with useful information such as the traceback. Most of the contents are generated in `htmlDebugInfo`.` publicErrorPage(self) `Return a public error page. Returns a brief error page telling the user that an error has occurred. Body of the message comes from ``UserErrorMessage`` setting.` repr(self, value) `Get HTML encoded representation. Returns the repr() of value already HTML encoded. As a special case, dictionaries are nicely formatted in table. This is a utility method for `writeAttrs`.` saveErrorPage(self, html) `Save the error page. Saves the given HTML error page for later viewing by the developer, and returns the filename used.` servletPathname(self) `The full filesystem path for the servlet.` setting(self, name) `Settings are inherited from Application.` work(self) `Main error handling method. Invoked by `__init__` to do the main work. This calls `logExceptionToConsole`, then checks settings to see if it should call `saveErrorPage` (to save the error to disk) and `emailException`. It also sends gives a page from `privateErrorPage` or `publicErrorPage` (which one based on ``ShowDebugInfoOnErrors``).` write(self, s) `Output `s` to the body.` writeAttrs(self, obj, attrNames) `Output object attributes. Writes the attributes of the object as given by attrNames. Tries ``obj._name` first, followed by ``obj.name()``. Is resilient regarding exceptions so as not to spoil the exception report.` writeDict(self, d, heading=None, encoded=None) `Output a table-formated dictionary.` writeEnvironment(self) `Output environment. Writes the environment this is being run in. This is *not* the environment that was passed in with the request (holding the CGI information) -- it's just the information from the environment that the AppServer is being executed in.` writeFancyTraceback(self) `Output a fancy traceback, using CGITraceback.` writeHTML(self) `Write the traceback. Writes all the parts of the traceback, invoking: * `writeTraceback` * `writeMiscInfo` * `writeTransaction` * `writeEnvironment` * `writeIds` * `writeFancyTraceback`` writeIds(self) `Output OS identification. Prints some values from the OS (like processor ID).` writeMiscInfo(self) `Output misc info. Write a couple little pieces of information about the environment.` writeTitle(self, s) `Output the sub-heading to define a section.` writeTraceback(self) `Output the traceback. Writes the traceback, with most of the work done by `WebUtils.HTMLForException.HTMLForException`.` writeTransaction(self) `Output transaction. Lets the transaction talk about itself, using `Transaction.writeExceptionReport`.` writeln(self, s) `Output `s` plus a newline.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class Singleton(__builtin__.object)
`` | `A singleton object.`
| Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`

Functions
`` |  | StringIO(...) `StringIO([s]) -- Return a StringIO-like stream for reading or writing` docType() `Return the document type for the page.` htStyle() `Return the page style.` htTitle(name) `Format a `name` as a section title.` localtime(...) `localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min, tm_sec,tm_wday,tm_yday,tm_isdst) Convert seconds since the Epoch to a time tuple expressing local time. When 'seconds' is not passed in, convert the current time instead.` osIdDict() `Get all OS id information. Returns a dictionary containing id information such as uid, gid, etc., all obtained from the os module.` time(...) `time() -> floating point number Return the current time in seconds since the Epoch. Fractions of a second may be present if the system clock provides them.`