Demo.modjy_webapp.demo_app.py Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython-standalone Show documentation
Show all versions of jython-standalone Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
import sys
def escape_html(s): return s.replace(
'&', '&').replace('<', '<').replace('>', '>')
def cutoff(s, n=100):
if len(s) > n:
return s[:n] + '.. cut ..'
return s
def handler(environ, start_response):
writer = start_response("200 OK", [('content-type', 'text/html')])
response_parts = []
response_parts.append("")
response_parts.append("")
response_parts.append("Modjy demo application ")
response_parts.append("")
response_parts.append("")
response_parts.append(
"Modjy servlet running correctly: jython %s on %s:
" % (sys.version, sys.platform))
response_parts.append("Hello WSGI World!
")
response_parts.append(
"Here are the contents of the WSGI environment
")
environ_str = ""
keys = environ.keys()
keys.sort()
for ix, name in enumerate(keys):
if ix % 2:
background = '#ffffff'
else:
background = '#eeeeee'
style = " style='background-color:%s;'" % background
value = escape_html(cutoff(str(environ[name]))) or ' '
environ_str = "%s\n%s %s " % \
(environ_str, style, name, style, value)
environ_str = "%s\n
" % environ_str
response_parts.append(environ_str)
response_parts.append("")
response_parts.append("")
response_text = "\n".join(response_parts)
return [response_text]