PYTHON   65
test py
Guest on 13th August 2022 08:05:34 AM


  1. # Copyright 1999-2014. Parallels IP Holdings GmbH. All Rights Reserved.
  2. import sys
  3. import os
  4. import re
  5.  
  6. def print_environ(environ=os.environ):
  7.     """Dump the shell environment as HTML."""
  8.     keys = environ.keys()
  9.     keys.sort()
  10.     i = 0
  11.     for key in keys:
  12.         if not re.search("^HTTP_|^REQUEST_", key):
  13.                         continue
  14.         if i == 0:
  15.             print """<tr class="normal"><td>""", escape(key), "</td><td>", escape(environ[key]), "</td></tr>"
  16.             i = 1
  17.         else:
  18.             print """<tr class="alt"><td>""", escape(key), "</td><td>", escape(environ[key]), "</td></tr>"
  19.             i = 0
  20.  
  21. def escape(s, quote=None):
  22.     """Replace special characters '&', '<' and '>' by SGML entities."""
  23.     s = s.replace("&", "&amp;") # Must be done first!
  24.     s = s.replace("<", "&lt;")
  25.     s = s.replace(">", "&gt;")
  26.     if quote:
  27.         s = s.replace('"', "&quot;")
  28.     return s
  29.  
  30.  
  31. print """Content-type: text/html
  32.  
  33. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  34. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  35. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  36. <head>
  37. <title></title>
  38. <link rel="stylesheet" type="text/css" href="../../css/style.css" />
  39. </head>
  40. <body class="test-data">
  41. <table cellspacing="0" cellpadding="0" border="0">
  42. <tr class="subhead" align="Left"><th>Name</th><th>Value</th></tr>"""
  43. print_environ()
  44. print """</table>
  45. </body>
  46. </html>"""

Raw Paste

Login or Register to edit or fork this paste. It's free.