Since the new build has been delayed, I am going to check in my changes unless anybody objects. Here are my changes. The first one may affect others.

• I've changed the implementation of compiled PSP pages so the writeHTML(trans) method doesn't do the actual work, but rather it calls another method, _writeHTML( fileLikeObj ) which does the work but doesn't take a transaction. This is so the PSP unit tests don't need to emulate transactions. The only way this might affect people is if they rely on the 'req' and 'trans' variables that PSPPage sets. You can replace those vars with self.request() and self.transaction() and everything should be fine.
• I've added two features to PSP, <psp:file> and <psp:class>. Below is the description that I added to the documentation.
• There were problems with the adjusting of indentation when the PSP files were written in Macintosh format, i.e. with \r at the end of lines instead of \n. I added test cases for it, and fix the problems.
• Converted test for these components to unittests:
- PSP
- WebUtils
- TaskKit
- half of MiscUtils
- UserKit (but has failures)
• Added a file, AllTests.py, which calls unit tests for all components.
• Fixed style sheet for documentation--a lot of indentation was messed up.

Incidentally, I have to commend the people who wrote the PSP code. It is very clean, and easy to understand. And this one part is the only dependency on the rest of Webware.

-winston
------------------------

File and Class Level Script Tags

"<psp:file>" and "<psp:class>"

<x-tad-bigger>The file and class level script tag allows you to write Python code at the file (module) level or class level. For example, at the file level, you might do imports statements, and some initialization that occurs only when the PSP file is loaded the first time. You can even define other classes that are used in your PSP file.

</x-tad-bigger><x-tad-bigger>Example</x-tad-bigger><x-tad-bigger>
</x-tad-bigger>
<x-tad-bigger><psp:file>
# Since this is at the module level, _log is only defined once for this file
import logging
_log = logging.getLogger( __name__ )
</psp:file>
<html>
<% _log.debug('Okay, Ive been called.') %>
<p>Write stuff here.</p>
</html>
</x-tad-bigger>
<x-tad-bigger>

</x-tad-bigger>
<x-tad-bigger>Example</x-tad-bigger><x-tad-bigger>

At the class level you can define methods using ordinary python syntax instead of the <psp:method > syntax below.
</x-tad-bigger>
<x-tad-bigger><psp:class></x-tad-bigger><x-tad-bigger>
</x-tad-bigger><x-tad-bigger> def writeNavBar(self):
for uri, title in self.menuPages():
self.write( "<a href="%s">%s</a>" % (uri, title) )</x-tad-bigger>
<x-tad-bigger>
</x-tad-bigger><x-tad-bigger></psp:class></x-tad-bigger><x-tad-bigger>

</x-tad-bigger>
<x-tad-bigger>Indentation is adjusted within the file and class blocks. Just make your indentation consistent with the block, and PSP will adjust the whole block to be properly indented for either the class or the file. For example file level Python would normally have no indentation. But in PSP pages, you might want some indentation to show it is inside of the <psp:file>...</psp:file> tags. That is no problem, PSP will adjust accordingly.

There is one special case with adding methods via the <psp:class> tag. The </x-tad-bigger>
<x-tad-bigger>awake()</x-tad-bigger><x-tad-bigger> method requires special handling, so you should always use the <psp:method> tag below if you want to override the awake() method.

The <psp:file> and <psp:class> tags were added to Webware v0.91</x-tad-bigger>

Reply via email to