PSP Examples

Hello from PSP!

Python Server Pages

This is the sample/test page
for an implementation of
Python Server Pages.

Read the PSP documentation. See the source for this page.

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.


The text below comes from another psp page which was inserted into this one with the <%@ include %> directive.

Hello from included file!

Fri Sep 20 02:36:39 2024

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

If you use <%@ include file="somefile" %>, it will effectively insert the contents of the other file before class creation time.

Using <psp:include path="somefile"> will insert the output of the specified WebKit URL into the page dynamically.


This is A HTML file that is dynamically inserted.


Time at which dynamic output was generated:

Fri Sep 20 02:36:39 2024


Below is a loop test:

Loops are the trickiest part of PSP due to Python indentation for blocks syntax.

  • Outer loop: 1
    • Inner loop: 1 (still in the inner loop)
    • Inner loop: 2 (still in the inner loop)
  • Outer loop: 2
    • Inner loop: 1 (still in the inner loop)
    • Inner loop: 2 (still in the inner loop)

The use of braces can make things easier here.


Unix system info:

OS name: Linux
Hostname: ddsubuntu1804
OS release: 4.15.0-112-generic
OS version: #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020
Hardware: x86_64

Path Info:/PSP/Examples/PSPTests
extraURLPath:
Fields:{}
servletURI:/PSP/Examples/PSPTests
uriWebKitRoot: ../../
serverURL:http://didiosistemas.com.ar:18084/PSP/Examples/PSPTests
serverURLDir:http://didiosistemas.com.ar:18084/PSP/Examples/

Request Variables:

HTTP_ACCEPT */*
HTTP_USER_AGENT Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
REMOTE_PORT 21585
GATEWAY_INTERFACE CGI/1.1
REMOTE_ADDR 3.12.147.168
SERVER_SOFTWARE Webware/1.0.2
SCRIPT_NAME 
REQUEST_METHOD GET
HTTP_HOST didiosistemas.com.ar:18084
PATH_INFO /PSP/Examples/PSPTests
SERVER_PORT 18084
SERVER_PROTOCOL HTTP/1.0
QUERY_STRING 
PATH /usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/bin:/bin
HTTP_ACCEPT_ENCODING gzip, br, zstd, deflate
SERVER_ADDR 0.0.0.0
REQUEST_URI /PSP/Examples/PSPTests

Comments:

PSP comments will not show up in the source of the page.

Nothing should be visible here.


Testing a class method defined in the PSP code:

I'm a method. Howdy!


pass can be used to end a block, so test that it can be used by itself too!

If-Test: It's True


That's all, folks.

Fri Sep 20 02:36:39 2024