summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Mailman/htmlformat.py376
1 files changed, 188 insertions, 188 deletions
diff --git a/Mailman/htmlformat.py b/Mailman/htmlformat.py
index c4db6a468..f96e7b49f 100644
--- a/Mailman/htmlformat.py
+++ b/Mailman/htmlformat.py
@@ -43,220 +43,220 @@ NL = '\n'
def HTMLFormatObject(item, indent):
"Return a presentation of an object, invoking their Format method if any."
if type(item) == type(''):
- return item
+ return item
elif not hasattr(item, "Format"):
- return `item`
+ return `item`
else:
- return item.Format(indent)
+ return item.Format(indent)
def CaseInsensitiveKeyedDict(d):
result = {}
for (k,v) in d.items():
- result[k.lower()] = v
+ result[k.lower()] = v
return result
# Given references to two dictionaries, copy the second dictionary into the
# first one.
def DictMerge(destination, fresh_dict):
for (key, value) in fresh_dict.items():
- destination[key] = value
+ destination[key] = value
class Table:
def __init__(self, **table_opts):
- self.cells = []
- self.cell_info = {}
- self.row_info = {}
- self.opts = table_opts
+ self.cells = []
+ self.cell_info = {}
+ self.row_info = {}
+ self.opts = table_opts
def AddOptions(self, opts):
- DictMerge(self.opts, opts)
+ DictMerge(self.opts, opts)
# Sets all of the cells. It writes over whatever cells you had there
# previously.
def SetAllCells(self, cells):
- self.cells = cells
+ self.cells = cells
# Add a new blank row at the end
def NewRow(self):
- self.cells.append([])
+ self.cells.append([])
# Add a new blank cell at the end
def NewCell(self):
- self.cells[-1].append('')
-
+ self.cells[-1].append('')
+
def AddRow(self, row):
- self.cells.append(row)
+ self.cells.append(row)
def AddCell(self, cell):
- self.cells[-1].append(cell)
+ self.cells[-1].append(cell)
def AddCellInfo(self, row, col, **kws):
- kws = CaseInsensitiveKeyedDict(kws)
- if not self.cell_info.has_key(row):
- self.cell_info[row] = { col : kws }
- elif self.cell_info[row].has_key(col):
- DictMerge(self.cell_info[row], kws)
- else:
- self.cell_info[row][col] = kws
-
+ kws = CaseInsensitiveKeyedDict(kws)
+ if not self.cell_info.has_key(row):
+ self.cell_info[row] = { col : kws }
+ elif self.cell_info[row].has_key(col):
+ DictMerge(self.cell_info[row], kws)
+ else:
+ self.cell_info[row][col] = kws
+
def AddRowInfo(self, row, **kws):
- kws = CaseInsensitiveKeyedDict(kws)
- if not self.row_info.has_key(row):
- self.row_info[row] = kws
- else:
- DictMerge(self.row_info[row], kws)
+ kws = CaseInsensitiveKeyedDict(kws)
+ if not self.row_info.has_key(row):
+ self.row_info[row] = kws
+ else:
+ DictMerge(self.row_info[row], kws)
# What's the index for the row we just put in?
def GetCurrentRowIndex(self):
- return len(self.cells)-1
+ return len(self.cells)-1
# What's the index for the col we just put in?
def GetCurrentCellIndex(self):
- return len(self.cells[-1])-1
+ return len(self.cells[-1])-1
def ExtractCellInfo(self, info):
- valid_mods = ['align', 'valign', 'nowrap', 'rowspan', 'colspan',
- 'bgcolor']
- output = ''
+ valid_mods = ['align', 'valign', 'nowrap', 'rowspan', 'colspan',
+ 'bgcolor']
+ output = ''
- for (key, val) in info.items():
- if not key in valid_mods:
- continue
- if key == 'nowrap':
- output = output + ' NOWRAP'
- continue
- else:
- output = output + ' %s="%s"' % (key.upper(), val)
+ for (key, val) in info.items():
+ if not key in valid_mods:
+ continue
+ if key == 'nowrap':
+ output = output + ' NOWRAP'
+ continue
+ else:
+ output = output + ' %s="%s"' % (key.upper(), val)
- return output
+ return output
def ExtractRowInfo(self, info):
- valid_mods = ['align', 'valign', 'bgcolor']
- output = ''
+ valid_mods = ['align', 'valign', 'bgcolor']
+ output = ''
- for (key, val) in info.items():
- if not key in valid_mods:
- continue
- output = output + ' %s="%s"' % (key.upper(), val)
+ for (key, val) in info.items():
+ if not key in valid_mods:
+ continue
+ output = output + ' %s="%s"' % (key.upper(), val)
- return output
+ return output
def ExtractTableInfo(self, info):
- valid_mods = ['align', 'width', 'border', 'cellspacing', 'cellpadding',
- 'bgcolor']
+ valid_mods = ['align', 'width', 'border', 'cellspacing', 'cellpadding',
+ 'bgcolor']
- output = ''
+ output = ''
- for (key, val) in info.items():
- if not key in valid_mods:
- continue
- if key == 'border' and val == None:
- output = output + ' BORDER'
- continue
- else:
- output = output + ' %s="%s"' % (key.upper(), val)
+ for (key, val) in info.items():
+ if not key in valid_mods:
+ continue
+ if key == 'border' and val == None:
+ output = output + ' BORDER'
+ continue
+ else:
+ output = output + ' %s="%s"' % (key.upper(), val)
- return output
+ return output
def FormatCell(self, row, col, indent):
- try:
- my_info = self.cell_info[row][col]
- except:
- my_info = None
+ try:
+ my_info = self.cell_info[row][col]
+ except:
+ my_info = None
- output = '\n' + ' '*indent + '<td'
- if my_info:
- output = output + self.ExtractCellInfo(my_info)
- item = self.cells[row][col]
- item_format = HTMLFormatObject(item, indent+4)
- output = '%s>%s</td>' % (output, item_format)
- return output
+ output = '\n' + ' '*indent + '<td'
+ if my_info:
+ output = output + self.ExtractCellInfo(my_info)
+ item = self.cells[row][col]
+ item_format = HTMLFormatObject(item, indent+4)
+ output = '%s>%s</td>' % (output, item_format)
+ return output
def FormatRow(self, row, indent):
- try:
- my_info = self.row_info[row]
- except:
- my_info = None
+ try:
+ my_info = self.row_info[row]
+ except:
+ my_info = None
- output = '\n' + ' '*indent + '<tr'
- if my_info:
- output = output + self.ExtractRowInfo(my_info)
- output = output + '>'
+ output = '\n' + ' '*indent + '<tr'
+ if my_info:
+ output = output + self.ExtractRowInfo(my_info)
+ output = output + '>'
for i in range(len(self.cells[row])):
output = output + self.FormatCell(row, i, indent + 2)
- output = output + '\n' + ' '*indent + '</tr>'
+ output = output + '\n' + ' '*indent + '</tr>'
- return output
+ return output
def Format(self, indent=0):
- output = '\n' + ' '*indent + '<table'
- output = output + self.ExtractTableInfo(self.opts)
- output = output + '>'
+ output = '\n' + ' '*indent + '<table'
+ output = output + self.ExtractTableInfo(self.opts)
+ output = output + '>'
- for i in range(len(self.cells)):
- output = output + self.FormatRow(i, indent + 2)
+ for i in range(len(self.cells)):
+ output = output + self.FormatRow(i, indent + 2)
- output = output + '\n' + ' '*indent + '</table>\n'
+ output = output + '\n' + ' '*indent + '</table>\n'
- return output
-
+ return output
+
class Link:
def __init__(self, href, text, target=None):
- self.href = href
- self.text = text
- self.target = target
+ self.href = href
+ self.text = text
+ self.target = target
def Format(self, indent=0):
texpr = ""
if self.target != None:
- texpr = ' target="%s"' % self.target
- return '<a href="%s"%s>%s</a>' % (HTMLFormatObject(self.href, indent),
- texpr,
- HTMLFormatObject(self.text, indent))
+ texpr = ' target="%s"' % self.target
+ return '<a href="%s"%s>%s</a>' % (HTMLFormatObject(self.href, indent),
+ texpr,
+ HTMLFormatObject(self.text, indent))
class FontSize:
"""FontSize is being deprecated - use FontAttr(..., size="...") instead."""
def __init__(self, size, *items):
- self.items = list(items)
- self.size = size
+ self.items = list(items)
+ self.size = size
def Format(self, indent=0):
- output = '<font size="%s">' % self.size
- for item in self.items:
- output = output + HTMLFormatObject(item, indent)
- output = output + '</font>'
- return output
+ output = '<font size="%s">' % self.size
+ for item in self.items:
+ output = output + HTMLFormatObject(item, indent)
+ output = output + '</font>'
+ return output
class FontAttr:
"""Present arbitrary font attributes."""
def __init__(self, *items, **kw):
- self.items = list(items)
- self.attrs = kw
+ self.items = list(items)
+ self.attrs = kw
def Format(self, indent=0):
- seq = []
- for k, v in self.attrs.items():
- seq.append('%s="%s"' % (k, v))
- output = '<font %s>' % SPACE.join(seq)
- for item in self.items:
- output = output + HTMLFormatObject(item, indent)
- output = output + '</font>'
- return output
+ seq = []
+ for k, v in self.attrs.items():
+ seq.append('%s="%s"' % (k, v))
+ output = '<font %s>' % SPACE.join(seq)
+ for item in self.items:
+ output = output + HTMLFormatObject(item, indent)
+ output = output + '</font>'
+ return output
class Container:
def __init__(self, *items):
- if not items:
- self.items = []
- else:
- self.items = items
+ if not items:
+ self.items = []
+ else:
+ self.items = items
def AddItem(self, obj):
- self.items.append(obj)
+ self.items.append(obj)
def Format(self, indent=0):
output = []
@@ -299,7 +299,7 @@ class Document(Container):
self.bgcolor = color
def SetTitle(self, title):
- self.title = title
+ self.title = title
def Format(self, indent=0, **kws):
output = [self.get_content_type()]
@@ -349,33 +349,33 @@ class HeadlessDocument(Document):
class StdContainer(Container):
def Format(self, indent=0):
- # If I don't start a new I ignore indent
- output = '<%s>' % self.tag
- output = output + Container.Format(self, indent)
- output = '%s</%s>' % (output, self.tag)
- return output
+ # If I don't start a new I ignore indent
+ output = '<%s>' % self.tag
+ output = output + Container.Format(self, indent)
+ output = '%s</%s>' % (output, self.tag)
+ return output
class QuotedContainer(Container):
def Format(self, indent=0):
- # If I don't start a new I ignore indent
- output = '<%s>%s</%s>' % (
+ # If I don't start a new I ignore indent
+ output = '<%s>%s</%s>' % (
self.tag,
Utils.QuoteHyperChars(Container.Format(self, indent)),
self.tag)
- return output
+ return output
class Header(StdContainer):
def __init__(self, num, *items):
- self.items = items
- self.tag = 'h%d' % num
+ self.items = items
+ self.tag = 'h%d' % num
class Address(StdContainer):
tag = 'address'
class Underline(StdContainer):
tag = 'u'
-
+
class Bold(StdContainer):
tag = 'strong'
@@ -399,36 +399,36 @@ class Center(StdContainer):
class Form(Container):
def __init__(self, action='', method='POST', encoding=None, *items):
- apply(Container.__init__, (self,) + items)
- self.action = action
- self.method = method
+ apply(Container.__init__, (self,) + items)
+ self.action = action
+ self.method = method
self.encoding = encoding
def set_action(self, action):
self.action = action
def Format(self, indent=0):
- spaces = ' ' * indent
+ spaces = ' ' * indent
encoding = ''
if self.encoding:
encoding = 'enctype="%s"' % self.encoding
- output = '\n%s<FORM action="%s" method="%s" %s>\n' % (
+ output = '\n%s<FORM action="%s" method="%s" %s>\n' % (
spaces, self.action, self.method, encoding)
- output = output + Container.Format(self, indent+2)
- output = '%s\n%s</FORM>\n' % (output, spaces)
- return output
+ output = output + Container.Format(self, indent+2)
+ output = '%s\n%s</FORM>\n' % (output, spaces)
+ return output
class InputObj:
def __init__(self, name, ty, value, checked, **kws):
- self.name = name
- self.type = ty
- self.value = value
- self.checked = checked
- self.kws = kws
+ self.name = name
+ self.type = ty
+ self.value = value
+ self.checked = checked
+ self.kws = kws
def Format(self, indent=0):
- output = ['<INPUT name="%s" type="%s" value="%s"' %
+ output = ['<INPUT name="%s" type="%s" value="%s"' %
(self.name, self.type, self.value)]
for item in self.kws.items():
output.append('%s="%s"' % item)
@@ -440,15 +440,15 @@ class InputObj:
class SubmitButton(InputObj):
def __init__(self, name, button_text):
- InputObj.__init__(self, name, "SUBMIT", button_text, checked=0)
+ InputObj.__init__(self, name, "SUBMIT", button_text, checked=0)
class PasswordBox(InputObj):
def __init__(self, name, value='', size=mm_cfg.TEXTFIELDWIDTH):
- InputObj.__init__(self, name, "PASSWORD", value, checked=0, size=size)
+ InputObj.__init__(self, name, "PASSWORD", value, checked=0, size=size)
class TextBox(InputObj):
def __init__(self, name, value='', size=mm_cfg.TEXTFIELDWIDTH):
- InputObj.__init__(self, name, "TEXT", value, checked=0, size=size)
+ InputObj.__init__(self, name, "TEXT", value, checked=0, size=size)
class Hidden(InputObj):
def __init__(self, name, value=''):
@@ -457,25 +457,25 @@ class Hidden(InputObj):
class TextArea:
def __init__(self, name, text='', rows=None, cols=None, wrap='soft',
readonly=0):
- self.name = name
- self.text = text
- self.rows = rows
- self.cols = cols
- self.wrap = wrap
+ self.name = name
+ self.text = text
+ self.rows = rows
+ self.cols = cols
+ self.wrap = wrap
self.readonly = readonly
def Format(self, indent=0):
- output = '<TEXTAREA NAME=%s' % self.name
- if self.rows:
- output += ' ROWS=%s' % self.rows
- if self.cols:
- output += ' COLS=%s' % self.cols
- if self.wrap:
- output += ' WRAP=%s' % self.wrap
+ output = '<TEXTAREA NAME=%s' % self.name
+ if self.rows:
+ output += ' ROWS=%s' % self.rows
+ if self.cols:
+ output += ' COLS=%s' % self.cols
+ if self.wrap:
+ output += ' WRAP=%s' % self.wrap
if self.readonly:
output += ' READONLY'
- output += '>%s</TEXTAREA>' % self.text
- return output
+ output += '>%s</TEXTAREA>' % self.text
+ return output
class FileUpload(InputObj):
def __init__(self, name, rows=None, cols=None, **kws):
@@ -483,7 +483,7 @@ class FileUpload(InputObj):
class RadioButton(InputObj):
def __init__(self, name, value, checked=0, **kws):
- apply(InputObj.__init__, (self, name, 'RADIO', value, checked), kws)
+ apply(InputObj.__init__, (self, name, 'RADIO', value, checked), kws)
class CheckBox(InputObj):
def __init__(self, name, value, checked=0, **kws):
@@ -491,19 +491,19 @@ class CheckBox(InputObj):
class VerticalSpacer:
def __init__(self, size=10):
- self.size = size
+ self.size = size
def Format(self, indent=0):
- output = '<spacer type="vertical" height="%d">' % self.size
- return output
+ output = '<spacer type="vertical" height="%d">' % self.size
+ return output
class WidgetArray:
Widget = None
def __init__(self, name, button_names, checked, horizontal, values):
- self.name = name
- self.button_names = button_names
- self.checked = checked
- self.horizontal = horizontal
+ self.name = name
+ self.button_names = button_names
+ self.checked = checked
+ self.horizontal = horizontal
self.values = values
assert len(values) == len(button_names)
# Don't assert `checked' because for RadioButtons it is a scalar while
@@ -513,7 +513,7 @@ class WidgetArray:
raise NotImplemented
def Format(self, indent=0):
- t = Table(cellspacing=5)
+ t = Table(cellspacing=5)
items = []
for i, name, value in zip(range(len(self.button_names)),
self.button_names,
@@ -524,9 +524,9 @@ class WidgetArray:
if not self.horizontal:
t.AddRow(items)
items = []
- if self.horizontal:
- t.AddRow(items)
- return t.Format(indent)
+ if self.horizontal:
+ t.AddRow(items)
+ return t.Format(indent)
class RadioButtonArray(WidgetArray):
Widget = RadioButton
@@ -561,24 +561,24 @@ class CheckBoxArray(WidgetArray):
class UnorderedList(Container):
def Format(self, indent=0):
- spaces = ' ' * indent
- output = '\n%s<ul>\n' % spaces
- for item in self.items:
- output = output + '%s<li>%s\n' % \
+ spaces = ' ' * indent
+ output = '\n%s<ul>\n' % spaces
+ for item in self.items:
+ output = output + '%s<li>%s\n' % \
(spaces, HTMLFormatObject(item, indent + 2))
- output = output + '%s</ul>\n' % spaces
- return output
+ output = output + '%s</ul>\n' % spaces
+ return output
class OrderedList(Container):
def Format(self, indent=0):
- spaces = ' ' * indent
- output = '\n%s<ol>\n' % spaces
- for item in self.items:
- output = output + '%s<li>%s\n' % \
+ spaces = ' ' * indent
+ output = '\n%s<ol>\n' % spaces
+ for item in self.items:
+ output = output + '%s<li>%s\n' % \
(spaces, HTMLFormatObject(item, indent + 2))
- output = output + '%s</ol>\n' % spaces
- return output
-
+ output = output + '%s</ol>\n' % spaces
+ return output
+
class DefinitionList(Container):
def Format(self, indent=0):
spaces = ' ' * indent