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

Modules

``

MimeWriter StringIO WebUtils | os random smtplib | sys time traceback | types

Classes

``

singleton
WebKit.Object.Object(__builtin__.object, MiscUtils.NamedValueAccess.NamedValueAccess)
  ExceptionHandler

class ExceptionHandler(WebKit.Object.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
* writeTable
* 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``
`

Method resolution order:
  ExceptionHandler
  WebKit.Object.Object
  __builtin__.object
  MiscUtils.NamedValueAccess.NamedValueAccess

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.
  Emails the exception, either as an attachment,
  or in 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.`

filterTableValue(self, value, key, row, table)
  `Filter table values.
  Invoked by writeTable() to afford the opportunity to filter the values
  written in tables. These values are already HTML when they arrive here.
  Use the extra key, row and table args as necessary.`

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='')
  `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, x)
  `Get HTML encoded representation.
  Returns the repr() of x 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)
  `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 cgitb.`

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.`

writeTable(self, listOfDicts, keys=None)
  `Output a table from dictionaries.
  Writes a table whose contents are given by `listOfDicts`.
  The keys of each dictionary are expected to be the same.
  If the `keys` arg is None, the headings are taken in alphabetical order
  from the first dictionary. If listOfDicts is false, nothing happens.
  The keys and values are already considered to be HTML,
  and no quoting is applied.
  Caveat: There's no way to influence the formatting or to use
  column titles that are different than the keys.
  Used by `writeAttrs`.`

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 and other attributes defined here:

hiddenString = '*** hidden ***'

hideValuesForFields = ['password', 'passwd', 'pwd', 'creditcard', 'credit card', 'cc']

Methods inherited from WebKit.Object.Object:

deprecated(self, method)
  `Output a deprecation warning.
  The implementation of WebKit sometimes invokes this method which prints
  a warning that the method you are using has been deprecated.
  This method expects that deprecated methods say so at the beginning of
  their doc string and terminate that msg with @. For example:
  DEPRECATED: Class.foo() on 01/24/01 in ver 0.5. Use Class.bar() instead. @
  Putting this information in the doc string is important for accuracy
  in the generated docs.
  Example call:
  deprecated(self.foo)`

Data and other attributes inherited from WebKit.Object.Object:

__dict__ = <dictproxy object>
  `dictionary for instance variables (if defined)`

__weakref__ = <attribute '__weakref__' of 'Object' objects>
  `list of weak references to the object (if defined)`

Methods inherited from MiscUtils.NamedValueAccess.NamedValueAccess:

hasValueForKey(self, key)
  `Returns true if the key is available, although that does not
  guarantee that there will not be errors caused by retrieving the key.`

hasValueForName(self, keysString)

resetKeyBindings(self)

setValueForKey(self, key, value)
  `Suppose key is 'foo'. This method sets the value with the following precedence:
  1. Public attributes before private attributes
  2. Methods before non-methods
  More specifically, this method then uses one of the following:
  @@ 2000-03-04 ce: fill in
  ...or invokes handleUnknownSetKey().`

valueForKey(self, key, default=<class MiscUtils.NoDefault>)
  `Suppose key is 'foo'. This method returns the value with the following precedence:
  1. Methods before non-methods
  2. Public attributes before private attributes
  More specifically, this method then returns one of the following:
  * foo()
  * _foo()
  * self.foo
  * self._foo
  ...or default, if it was specified,
  otherwise invokes and returns result of valueForUnknownKey().
  Note that valueForUnknownKey(), normally returns an exception.
  See valueForName() which is a more advanced version of this method that allows
  multiple, qualified keys.`

valueForKeySequence(self, listOfKeys, default=None)

valueForName(self, keysString, default=None)
  `Returns the value for the given keysString. This is the more advanced version of
  valueForKey(), which can only handle single names. This method can handle
  'foo', 'foo1.foo2', 'a.b.c.d', etc. It will traverse dictionaries if needed.`

valueForUnknownKey(self, key, default)
  `# Errors`

valuesForNames(self, keys, default=None, defaults=None, forgive=0, includeNames=0)
  `Returns a list of values that match the given keys, each of which is passed
  through valueForName() and so could be of the form 'a.b.c'.
  keys is a sequence. default is any kind of object. defaults is a sequence.
  forgive and includeNames is a flag.
  If default is not None, then it is substituted when a key is not found.
  Otherwise, if defaults is not None, then it's corresponding/parallel value
  for the current key is substituted when a key is not found.
  Otherwise, if forgive=1, then unknown keys simply don't produce any values.
  Otherwise, if default and defaults are None, and forgive=0, then the unknown
  keys will probably raise an exception through valueForUnknownKey() although
  that method can always return a final, default value.
  if keys is None, then None is returned. If keys is an empty list, then None
  is returned.
  Often these last four arguments are specified by key.
  Examples:
  names = ['origin.x', 'origin.y', 'size.width', 'size.height']
  obj.valuesForNames(names)
  obj.valuesForNames(names, default=0.0)
  obj.valuesForNames(names, defaults=[0.0, 0.0, 100.0, 100.0])
  obj.valuesForNames(names, forgive=0)
  @@ 2000-03-04 ce: includeNames is only supported when forgive=1.
  It should be supported for the other cases.
  It should be documented.
  It should be included in the test cases.`

class singleton
`` |  |

Functions

``

asctime(...)
  `asctime([tuple]) -> string
  Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.
  When the time tuple is not present, current time as returned by localtime()
  is used.`

htStyle()
  `Defines the page style.`

htTitle(name)
  `Formats a `name` as a section title.`

localtime(...)
  `localtime([seconds]) -> (tm_year,tm_mon,tm_day,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.`

osIdTable()
  `Get all OS id information.
  Returns a list of dictionaries contained id information such as
  uid, gid, etc., all obtained from the os module.
  Dictionary keys are ``"name"`` and ``"value"``.`