Move TemplateIO here. It's intimately tied to the ... (quixote/_py_htmltext.py)
Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Wed, 08 Jan 2003 19:12:26 -0500
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /home/cvs/quixote
In directory hewson:/tmp/cvs-serv20496
Modified Files:
_py_htmltext.py
Log Message:
Move TemplateIO here. It's intimately tied to the htmltext framework
now. Simplify TemplateIO since it's no longer user visible (well,
unless you work hard to find it).
Index: _py_htmltext.py
===================================================================
RCS file: /home/cvs/quixote/_py_htmltext.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- _py_htmltext.py 8 Jan 2003 19:43:03 -0000 1.1
+++ _py_htmltext.py 9 Jan 2003 00:12:24 -0000 1.2
@@ -1,5 +1,5 @@
-"""Python implementation of the htmltext type and the htmlescape function.
-Do not use this module directly. Import from quixote.html instead.
+"""Python implementation of the htmltext type, the htmlescape function and
+TemplateIO.
"""
import sys
@@ -204,4 +204,33 @@
s = s.replace(">", ">")
s = s.replace('"', """)
return htmltext(s)
+
+
+class TemplateIO(object):
+ """Collect output for PTL scripts.
+ """
+
+ __slots__ = ['html', 'data']
+
+ def __init__(self, html=0):
+ self.html = html
+ self.data = []
+
+ def __iadd__(self, other):
+ if other is not None:
+ self.data.append(other)
+ return self
+
+ def __repr__(self):
+ return ("<%s at %x: %d chunks>" %
+ (self.__class__.__name__, id(self), len(self.data)))
+
+ def __str__(self):
+ return str(self.getvalue())
+
+ def getvalue(self):
+ if self.html:
+ return htmltext('').join(map(htmlescape, self.data))
+ else:
+ return ''.join(map(str, self.data))