# Copyright 2006 The Trustees of Indiana University. # Use, modification and distribution is subject to the Boost Software # License, Version 1.0. (See copy at http://www.boost.org/LICENSE_1_0.txt) # Authors: Chris Mueller # Andrew Lumsdaine import string # ------------------------------ # HTML Generation Task Examples # ------------------------------ class Tag: """ Base class for a HTML tag of the form . Subclasses just need to set the TAG name and any attributes. """ TAG = None ATTRS = {} def __init__(self, state = None, index = 0, value = None): self._call = 0 self._index = index self._value = value self._state = state return def _fmtAttrs(self): retStr = '' if len(self.ATTRS) > 0: retStr = ' ' + string.join(['%s="%s"' % (attr, value) for attr, value in zip(self.ATTRS.keys(), self.ATTRS.values())], ' ') return retStr def _printStart(self): print ' ' * self._index, '<%s%s>' % (self.TAG, self._fmtAttrs()) return def _printEnd(self): print ' ' * self._index, '' % (self.TAG) return def __iter__(self): self._call = 0 return self def next(self): if self._call == 0: self._printStart() self._call = 1 else: self._printEnd() raise StopIteration return class HTMLtr(Tag): TAG = 'tr' class HTMLtd(Tag): TAG = 'td' class HTMLtable(Tag): TAG = 'table' ATTRS = {'border':'1', 'width':'100%'} class HTMLhtml(Tag): TAG = 'html' if __name__=='__main__': from psweep import * # Gererate an HTML table with 10 rows and 5 columns. html = range(1) table = range(1) rows = range(10) cols = range(5) params = [html, table, rows, cols] state = BoundState(params) state.bind(html, HTMLhtml) state.bind(table, HTMLtable) state.bind(rows, HTMLtr) state.bind(cols, HTMLtd) e = enumerator(params, state) for s in e: print ' ' * len(state) * 2, 'Hello PSWEEP!' state.Finish()