<%-- This is a PSP comment. It won't show up in the HTML or even in the class that this file will generate --%>

<%@ page imports = "sys,os,time"%><%-- Here's the modules that I need in this file --%>
<%-- You normally don't need any of the other page directives used here. --%>
<%@ page imports = "PSP.Examples.PSPExamplePage" %><%-- One more import, the base class, which isn't normally needed --%>
<%@ page method="writeContent" %><%-- This is the method of the base class that I want to override, writeHTML is the default. --%>
<%@ page extends="PSP.Examples.PSPExamplePage"%><%--This is the base class for this page. Page is the default. --%>
<%@ page isInstanceSafe="yes" %><%-- Each instance of this class can be used multiple times. --%>
<%@ page indentType="spaces" %>
<%@ page gobbleWhitespace="YES" %><%-- Default is Yes, so this line isn't needed. --%>

<%--  Method declaration Test --%>
<psp:method name="title" params="">
return "PSP Tests Page"
</psp:method>

<h1 style="text-align:center;color:navy">Hello from PSP!</h1>

<%-- This image is served by WebKit --%>
<p style="text-align:center"><img src="psplogo.png" alt="Python Server Pages"></p>

<h4 style="text-align:center">This is the sample/test page<br>
for an implementation of<br>
<span style="color:navy">Python Server Pages</span>.</h4>

<p style="text-align:center">Read the <a href="PSPDocs.psp"><strong>PSP documentation</strong></a>.
See the <a href="View.py?filename=<%=os.path.basename(self.request().serverSidePath())%>"><strong>source for this page</strong></a>.</p>

<p>The syntax for Python Server Pages is almost identical to that of Java Server Pages (JSP).  Just the scripting language is different! And obviously better.  In fact, just about anything you can do with JSP, you can do with PSP, and more.  With PSP, not only can you create template text that will be inerted in one method when the page is run as a servlet, but you can choose which base class to inherit from, you can choose which method of the base class to over-ride with your template text, and you can add additional methods to the servlet class, all from the PSP template code.</p>

<hr>

<p>The text below comes from another psp page which was inserted into this one with the <code>&lt;%@&nbsp;include&nbsp;%&gt;</code> directive.</p>

<div style="color:red"><%@ include file="my_include.psp" %></div>

<p>There are actually two ways to insert the contents of another file into a PSP page:</p>

<p>If you use <code>&lt;%@&nbsp;include&nbsp;file="somefile"&nbsp;%&gt;</code>, it will effectively insert the contents of the other file before class creation time.</p>

<p>Using <code>&lt;psp:include&nbsp;path="somefile"&gt;</code> will insert the output of the specified WebKit URL into the page <em>dynamically</em>.</p>

<div style="color:red"><psp:insert file="APSPinclude.html"></div>

<p>Time at which dynamic output was generated:</p>
<psp:include path = "APSPinclude.psp">

<h4>Below is a loop test:</h4>

<p>Loops are the trickiest part of PSP due to Python indentation for blocks syntax.</p>

<ul><% for i in range(2): %><%-- loop #1, an automatic loop --%>
<% self.write('<li>Outer loop: '); self.write(i+1) %>
<ul><% for j in range(2): %><%-- loop #2, another automatic loop --%>
<li>Inner loop: <%= j+1 %>
<% self.write('(still in the inner loop)') %></li>
<% end %></ul></li><%-- end loop #2 --%>
<% end %></ul><%-- end loop #1 --%>

<p style="color:navy">The use of <a href="PSPTests-Braces">braces</a> can make things easier here.</p>

<hr>

<h4>Unix system info:</h4>
<table style="background-color:gray"><%
if os.name == 'posix':
    for info, value in zip(('OS name', 'Hostname',
        'OS release', 'OS version', 'Hardware'), os.uname()):
            res.write('<tr><td>' + info + ':&nbsp;</th>'
                '<td style="color:white">' + str(value) + '</td></tr>')
else:
    res.write('<tr><td style="color:white">'
        'This is not a Unix system.</td></tr>')
%></table>

<hr>

<table>
<tr><th style="text-align:left">Path Info:</th><td><%=req.pathInfo()%></td></tr>
<tr><th style="text-align:left">extraURLPath:</th><td><%=req.extraURLPath()%></td></tr>
<tr><th style="text-align:left">Fields:</th><td><%= req.fields() %></td></tr>
<tr><th style="text-align:left">servletURI:</th><td><%= req.servletURI()%></td></tr>
<tr><th style="text-align:left">uriWebKitRoot:&nbsp;</th><td><%= req.uriWebKitRoot() %></td></tr>
<tr><th style="text-align:left">serverURL:</th><td><%= req.serverURL() %></td></tr>
<tr><th style="text-align:left">serverURLDir:</th><td><%= req.serverURLDir() %></td></tr>
</table>

<hr>

<h4>Request Variables:</h4>

<table><% for i, v in self.request()._environ.iteritems():
    res.write('<tr style="vertical-align:top"><td style="color:red;font-size:small">'
        +str(i)+'&nbsp;</td><td style="color:blue;font-size:small">'
        +self.htmlEncode(v).replace(',', ',<wbr>').replace(';', ';<wbr>').replace(':/', ':<wbr>/')
        +'</td></tr>') %></table>

<hr>

<h4>Comments:</h4>

<p>PSP comments will not show up in the source of the page.</p>

<p>Nothing should be visible here.</p>

<%-- Comment check --%><%-- # This kind not even in Python file created. --%>
<!-- Comment Check -->

<hr>

<h4>Testing a class method defined in the PSP code:</h4>

<%--  Method declaration test --%>
<psp:method name="testing" params="val">
self._response.write('<p>I\'m a method. <b style="color:maroon">%s</b></p>' % val)
</psp:method>

<%self.testing('Howdy!')%>

<hr>

<p><code>pass</code> can be used to end a block, so test that it can be used by itself too!</p>

<% pass %>

<p><i>If-Test:</i>
<%if 1:%><b style="color:green">It's True</b><%end%><%else:%>It's false<%end%></p>

<hr>

<p><b>That's all, folks.</b></p>

<p><%= time.ctime()%></p>
