# WebUtils User's Guide

WebUtils version 1.1.1

## Synopsis

The WebUtils package are a basic set of modules for common web related programming tasks such as encoding/decoding HTML, dealing with Cookies, etc.

## Description

### HTMLForException

This module defines a function by the same name:

`def HTMLForException(excInfo=None, options=None)`

HTMLForException returns an HTML string that presents useful information to the developer about the exception. The first argument is a tuple such as returned by sys.exc_info() which is in fact, invoked if the tuple isn't provided. The options parameter can be a dictionary to override the color options in HTMLForExceptionOptions which is currently defined as:

    HTMLForExceptionOptions = {
        'table.bgcolor':        '#F0F0F0',
        'default.fgcolor':      '#000000',
        'row.location.fgcolor': '#006600',
        'row.code.fgcolor':     '#FF0000'
    }

A sample HTML exception string looks like this:

    Traceback (innermost last):
      File "Application.py", line 90, in dispatchRequest
        self.respond(context, response)
      File "Application.py", line 112, in respond
        ctx.component().respond(ctx, response)
      File "HTTPComponent.py", line 30, in respond
        method(ctx, response)
      File "/home/echuck/Projects/Webware/WebKit/Examples/Introspect.py", line 9, in respondToGet
        self.write('<table %s>' % tableOptions)
    NameError: tableOptions

### HTTPStatusCodes

This module provides a list of well known HTTP status codes in list form and in a dictionary that can be keyed by code number or identifier.

You can index the HTTPStatusCodes dictionary by code number such as `200`, or identifier such as `OK`. The dictionary returned has keys `'code'`, `'identifier'` and `'htmlMsg'`. An `'asciiMsg'` key is provided, however, the HTML tags are not yet actually stripped out.

The `HTMLTableOfHTTPStatusCodes()` functions returns a string which is exactly that: a table containing the `HTTPStatusCodes` defined by the module. You can affect the formatting of the table by specifying values for the arguments. It's highly recommended that you use `key=value` arguments since the number and order could easily change in future versions. The definition is:

    def HTMLTableOfHTTPStatusCodes(codes=HTTPStatusCodeList,
        tableArgs='align=center border=2',
        rowArgs='valign=top', colArgs='', headingTag='th', headingArgs='')

If you run the script, it will invoke `HTMLTableOfHTTPStatusCodes()` and print its contents with some minimal HTML wrapping. You could do this:

    > cd Webware/Projects/WebUtils

    > python HTTPStatusCodes.py > HTTPStatusCodes.html

And then open the HTML file in your favorite browser.

### Funcs

See the source or the generated documentation.

## Credit

Author: Chuck Esterbrook.

In Funcs.py, some tips were taken from the Python library source.