[Zope-Checkins] CVS: Zope/lib/python/ZServer/medusa/script_handler_demo - form.mpy:1.1.2.1 persistent.py:1.1.2.1 start_demo.py:1.1.2.1 today.mpy:1.1.2.1
Chris McDonough
chrism@zope.com
Tue, 17 Sep 2002 01:16:10 -0400
Update of /cvs-repository/Zope/lib/python/ZServer/medusa/script_handler_demo
In directory cvs.zope.org:/tmp/cvs-serv12650/lib/python/ZServer/medusa/script_handler_demo
Added Files:
Tag: chrism-install-branch
form.mpy persistent.py start_demo.py today.mpy
Log Message:
Moved ZServer into lib/python.
=== Added File Zope/lib/python/ZServer/medusa/script_handler_demo/form.mpy ===
# -*- Mode: Python; tab-width: 4 -*-
# send and process a POST form
import sys
# anything on stdin?
data = sys.stdin.read()
form = """<html><form method=POST action="form.mpy">
%s<hr>
<input name=test size=50 value="">
<input type=submit name=search value="Search">
</form></html>"""
if data:
import cgi
info = '<h2>CGI variables:</h2>%s\r\n' % repr(cgi.parse_qs(data))
else:
info = ''
print form % info
=== Added File Zope/lib/python/ZServer/medusa/script_handler_demo/persistent.py ===
# -*- Mode: Python; tab-width: 4 -*-
# demo of bobo-like persistent script handler
# how this is different from CGI:
# rather than passing request info in the 'environment',
# we give the 'main' function direct access to the medusa
# request object.
# stdin, stdout, and stderr all act in a cgi-ish fashion.
# [i.e, form/put/post data can be found on stdin, use the
# cgi module to handle forms...]
# some quick persistence comments:
# You can add a command URI that will reload the module
# if you need to. You might also change persistent_script_handler
# to automatically reload a module if it's changed on disk.
# You can preserve data across a reload. Using 'count' as
# an example, replace the line below with:
# try:
# count
# except NameError;
# count = 0
#
count = 0
import string
def html_clean (s):
s = string.replace (s, '<', '<')
s = string.replace (s, '>', '>')
return s
def main (request):
global count
count = count + 1
print '<html><h1>Hit Count=%d</h1>' % count
print '<h3>Request Attributes:</h3><ul>'
print '<li>command : %s' % request.command
print '<li>uri: %s' % html_clean (request.uri)
print '<li>channel: %s' % html_clean (repr (request.channel))
print '</ul>'
print '</html>'
=== Added File Zope/lib/python/ZServer/medusa/script_handler_demo/start_demo.py ===
# -*- Mode: Python; tab-width: 4 -*-
import asyncore
import http_server
import script_handler
import filesys
h = http_server.http_server ('', 8081)
fs = filesys.os_filesystem ('.')
sh = script_handler.script_handler (fs)
import persistent
ph = script_handler.persistent_script_handler()
ph.add_module ('per', persistent)
# install the two handlers
# Hit me as: http://www.your_server.com:8081/per
h.install_handler (ph)
# Hit me as: http://www.your_server.com:8081/form.mpy
h.install_handler (sh)
asyncore.loop()
=== Added File Zope/lib/python/ZServer/medusa/script_handler_demo/today.mpy ===
# -*- Mode: Python; tab-width: 4 -*-
print '<html>'
import time
print "<p align=center>It is %s here at <b>nightmare.com</b></p>"% (
time.ctime (time.time())
)
import string
def uptime ():
return string.atof (
string.split (
open ('/proc/uptime', 'r').readline()
)[0]
)
print "<p align=center>This machine has been up since: %s </p>" % (
time.ctime (time.time() - uptime())
)
print '</html>'