#'$Id: HTMLgen.py,v 2.5 1999/04/20 03:29:14 friedric Exp friedric $'
# COPYRIGHT (C) 1996-9 ROBIN FRIEDRICH email:Robin.Friedrich@pdq.net
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
# THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""A class library for the generation of HTML documents.
Each HTML tag type has a supporting class which is responsible for
emitting itself as valid HTML formatted text. An attempt is made to
provide classes for newer HTML 3.2 and proposed tag elements. The
definitive reference for HTML tag elements can be found at
[W3C]. Also, I used the HTML book by Musciano and
Kennedy from [O Reilly] (2nd. Ed.) as the guiding reference.
The Document classes are container objects which act as a focal point
to populate all the contents of a particular web page. It also can
enforce consistent document formating according to the guidelines from
the [Yale Web Style Manual].
Features include customization of document template graphics / colors
through use of resource files, minimizing the need for modifying or
subclassing from the module source code. Support for tables, frames,
forms (persistent and otherwise) and client-side imagemaps are included.
A newer implementation for the Table support is now included,
TableLite(). In support of this there are new tag classes TD, TH, TR
and Caption. These class instances can be assembled in any way to
populate the TableLite container object.
.. [W3C] http://www.W3.org/TR/REC-html32.html
.. [O Reilly] http://www.oreilly.com/catalog/html3/index.html
.. [Yale Web Style Manual] http://info.med.yale.edu/caim/manual/contents.html
"""
import string, re, time, os
import UserList, copy
from imgsize import imgsize
__author__ = 'Robin Friedrich friedrich@pythonpros.com'
__version__ = '2.2.2'
StringType = type('s')
IntType = type(3)
ListType = type([1])
TupleType = type((1,2))
InstanceType = type(UserList.UserList())
CONTYPE = 'Content-Type: text/html\n\n'
DOCTYPE = '\n\n'
PRINTECHO = 1
#################
# CLASS LIBRARY #
#################
#======= NEW CLASS STRUCTURE ============
# HTMLgen 1 HTMLgen 2
# --------------- ------------------
# Document SeriesDocument
# MinimalDocument SimpleDocument
# BasicDocument (base class)
# TemplateDocument
class BasicDocument:
"""Base class to define an HTML document.
Non-keyword arguments are taken as the initial contents for this object.
Keyword arguments:
title -- HTML TITLE attribute for document
bgcolor -- background color expressed in hex-triplet or names from HTMLcolors.
background -- background image filename
cgi -- flag to indicate if this is used in CGI context (1 if it is)
textcolor -- color to use for normal text
linkcolor -- color to use for hyperlinks
vlinkcolor -- color to use for visited hyperlinks
alinkcolor -- color to use when hyperlink is active
"""
title = ''
cgi = None
bgcolor = None
background = None
textcolor = None
linkcolor = None
vlinkcolor = None
alinkcolor = None
def __init__(self, *args, **kw):
self.contents = list(args)
for name, value in kw.items():
setattr(self, name, value)
def __str__(self):
s = []
if self.cgi:
s.append('Content-Type: text/html\n\n' + DOCTYPE)
else:
s.append(DOCTYPE)
s.append('\n\n')
# build the HEAD and BODY tags
s.append(self.html_head())
s.append(self.html_body_tag())
# DOCUMENT CONTENT SECTION and FOOTER added on
bodystring = '%s\n' * len(self.contents)
s.append((bodystring % tuple(self.contents)))
# CLOSE the document
s.append('\n