[<<] Industrie Toulouse
Half of our power is out, but the airport base station and the gateways are still on. So, todays teaser medicine consists of a "Python" translation of some UserTalk code I wrote (the first major script I wrote in Radio), runnable as an External Method in "Zope". Also included is the UserTalk code, as well as some DTML and ZPT output.

I show this because, personally, I loathe coming across HTML in code. Sorry Jon. Writing for templates increases possibilities for reuse, since the data producing code is independent from the code that displays it. While you can do this in pure python scripts (by having one script produce data, and have another script as a consumer that outputs HTML from within Python), I take a "why bother?" attitude. I've had to maintain that HTML generating code in the past - the long ago past in web time (1996). And I hated the maintenance chores that seemed to go along with even the most trivial HTML. Why do we keep reinventing old problems? The script-inside-HTML way is often as broken, in my mind, as the HTML-inside-scripts way. It always surprises me to see ASP/PHP code that looks like::


<table>
  <% for row in data {
    out.writeln('<tr>');
    out.writeln('<td>' + row.name + '</td>');
    out.writeln('</tr>');
  } %>
</table>

Why bother having the HTML abilities of ?SP/PHP languages at all? I can understand why it happens. I just don't think it should. ";->". But, in the words of Dennis Miller, "Of course, that's just my opinion, I could be wrong".

In any case, I present the Goldberg Variations:

import os
radioWwwFolder = '/Applications/Radio Userland/www'
def listOutlines():
	out  =[]
	path = os.path.join(radioWwwFolder, 'outlines')
	def visit(arg, dirname, fnames):
		for fname in fnames:
			if fname.endswith('.opml'):
				fn = os.path.splitext(fname)[0]    # Split extension off
				if dirname != path:
				    # Deal with subdirectories
				    fn = os.path.join(dirname[len(path):], fn)
				arg.append(fn)
	os.path.walk(path, visit, out)
	return out
 
ZPT = """
<ol>
 <li tal:repeat="item here/listOutlines">
  <a tal:attributes="href string:${item}.html"
     tal:content="item">Outline</a>
 </li>
</ol>
"""
 
DTML = """
<ol>
 <dtml-in listOutlines>
  <li><a href="&dtml-sequence-item;.html"><dtml-var item></a></li>
 </dtml-in>
</ol>
"""
 
USERTALK = """
on listOutlines() {
	local(out = "<ol>\n");
	local(path=user.radio.prefs.wwwFolder + "outlines");
	on visit(f) {
		f = file.fileFromPath(f);
		if string.hasSuffix(".opml", f) {
			f = string.popSuffix(f, '.');
			out = out + " <li><a href=\"" + f + ".html\">" + f + "</a></li>\n"};
		return true};
	file.visitFolder(path, 1, @visit);
	out = out + "</ol>";
	return out
}
"""