Skip to content

Commit 61be8d2

Browse files
committed
Some clean-up in CGIWrapper.
1 parent b5e24f8 commit 61be8d2

14 files changed

+225
-238
lines changed

CGIWrapper/AdminPage.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def writeHeader(self):
5656
self.writeToolbar()
5757

5858
def writeBody(self):
59-
raise NotImplementedError, 'Should be overridden in a subclass'
59+
raise NotImplementedError('Should be overridden in a subclass')
6060

6161
def writeFooter(self):
6262
self.writeln('''
@@ -75,10 +75,10 @@ def bodyTags(self):
7575
def writeBanner(self):
7676
self.writeln('''
7777
<table align="center" bgcolor="#202080" cellpadding="5" cellspacing="0" width="100%%">
78-
<tr><td align="center" style="color:white;font-weight:bold;font-family:Tahoma,Verdana,Arial,Helvetica,sans-serif">
79-
<div style="font-size:14pt">CGI Wrapper</div>
80-
<div style="font-size:16pt">%s</div>
81-
</td></tr>
78+
<tr><td align="center" style="color:white;font-weight:bold;font-family:Tahoma,Verdana,Arial,Helvetica,sans-serif">
79+
<div style="font-size:14pt">CGI Wrapper</div>
80+
<div style="font-size:16pt">%s</div>
81+
</td></tr>
8282
</table>''' % self.title())
8383

8484
def writeToolbar(self):

CGIWrapper/CGIWrapper.py

+114-112
Large diffs are not rendered by default.

CGIWrapper/Docs/UsersGuide.phtml

+8-8
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ This is where the wrapper always looks for the CGI scripts. This location would
102102

103103
<dl>
104104
<dt><b>ChangeDir</b>
105-
&nbsp; <code> = 1</code></dt>
105+
&nbsp; <code> = True</code></dt>
106106
<dd>
107107
If true, the current working directory is changed to the same directory as the target script. Otherwise, the current working directory is left alone and likely to be the same as the CGI Wrapper.
108108
</dd>
@@ -126,7 +126,7 @@ This is the index into <code>sys.path</code> where the <code>ExtraPath</code> va
126126

127127
<dl>
128128
<dt><b>LogScripts</b>
129-
&nbsp; <code> = 1</code></dt>
129+
&nbsp; <code> = True</code></dt>
130130
<dd>
131131
If true, then the execution of each script is logged with useful information such as time, duration and whether or not an error occurred.
132132
</dd>
@@ -161,7 +161,7 @@ This is the list of class names that CGI Wrapper looks for after executing a scr
161161

162162
<dl>
163163
<dt><b>ShowDebugInfoOnErrors</b>
164-
&nbsp; <code> = 1</code></dt>
164+
&nbsp; <code> = True</code></dt>
165165
<dd>
166166
If true, then the uncaught exceptions will not only display a message for the user, but debugging information for the developer as well. This includes the traceback, HTTP headers, CGI form fields, environment and process ids.
167167
</dd>
@@ -177,7 +177,7 @@ This is the error message that is displayed to the user when an uncaught excepti
177177

178178
<dl>
179179
<dt><b>LogErrors</b>
180-
&nbsp; <code> = 1</code></dt>
180+
&nbsp; <code> = True</code></dt>
181181
<dd>
182182
If true, then CGI Wrapper logs exceptions. Each entry contains the date &amp; time, filename, pathname, exception name &amp; data, and the HTML error message filename (assuming there is one).
183183
</dd>
@@ -193,7 +193,7 @@ This is the name of the file where CGI Wrapper logs exceptions if <code>LogError
193193

194194
<dl>
195195
<dt><b>SaveErrorMessages</b>
196-
&nbsp; <code> = 1</code></dt>
196+
&nbsp; <code> = True</code></dt>
197197
<dd>
198198
If true, then errors (e.g., uncaught exceptions) will produce an HTML file with both the user message and debugging information. Developers/administrators can view these files after the fact, to see the details of what went wrong.
199199
</dd>
@@ -209,7 +209,7 @@ This is the name of the directory where HTML error messages get stored if <code>
209209

210210
<dl>
211211
<dt><b>EmailErrors</b>
212-
&nbsp; <code> = 0</code></dt>
212+
&nbsp; <code> = False</code></dt>
213213
<dd>
214214
If true, error messages are e-mail out according to the ErrorEmailServer and ErrorEmailHeaders settings. This setting defaults to false because the other settings need to be configured first.
215215
</dd>
@@ -273,8 +273,8 @@ A list of IP addresses or networks from which admin scripts can be accessed.
273273

274274
<p>The resulting page will look something like the following. (Note: Those links aren't real!)</p>
275275

276-
<table cellspacing="2" align="center">
277-
<tr><th align="right">Size</th><th rowspan="8">&nbsp;</th><th align="left">Script</th><th rowspan="8">&nbsp;</th><th align="left">View</th></tr>
276+
<table cellspacing="0" cellpadding="4" border="1" align="center">
277+
<tr><th align="right">Size</th><th align="left">Script</th><th align="left">View</th></tr>
278278
<tr><td align="right">96</td><td><a href="Hello">Hello</a></td><td><a href="View?filename=Hello">view</a></td></tr>
279279
<tr><td align="right">167</td><td><a href="Time">Time</a></td><td><a href="View?filename=Time">view</a></td></tr>
280280
<tr><td align="right">210</td><td><a href="Error">Error</a></td><td><a href="View?filename=Error">view</a></td></tr>

CGIWrapper/Examples/Colors.py

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
if fields.has_key('bgcolor'):
2+
if 'bgcolor' in fields:
33
bgcolor = fields['bgcolor'].value
44
bgcolorArg = 'bgcolor="%s"' % bgcolor
55
else:
@@ -8,17 +8,17 @@
88

99
print '''<!DOCTYPE HTML SYSTEM>
1010
<html>
11-
<head>
12-
<title>Colors</title>
13-
</head>
14-
<body %s>
15-
<h1 align="center">Colors</h1>
16-
<center>
17-
<form action="Colors">
18-
bgcolor: <input type="text" name="bgcolor" value="%s">
19-
<input type="submit" value="Go">
20-
</form>
21-
<table cellspacing="2" cellpadding="2">
11+
<head>
12+
<title>Colors</title>
13+
</head>
14+
<body %s>
15+
<h1 align="center">Colors</h1>
16+
<center>
17+
<form action="Colors">
18+
bgcolor: <input type="text" name="bgcolor" value="%s">
19+
<input type="submit" value="Go">
20+
</form>
21+
<table cellspacing="2" cellpadding="2">
2222
''' % (bgcolorArg, bgcolor)
2323

2424
space = '&nbsp;'*10
@@ -35,15 +35,12 @@
3535
# Compute brightness given RGB
3636
brightness = (0.3*r**gamma + 0.6*g**gamma + 0.1*b**gamma)**(1/gamma)
3737
# We then use brightness to determine a good font color for high contrast
38-
if brightness < 0.5:
39-
textcolor = 'white'
40-
else:
41-
textcolor = 'black'
38+
textcolor = brightness < 0.5 and 'white' or 'black'
4239
print '<td style="color:%s;background-color:%s;">%s</td>' % (textcolor, color, color)
4340
print '</tr>'
4441

4542
print '''
46-
</table>
47-
</center>
48-
</body>
43+
</table>
44+
</center>
45+
</body>
4946
</html>'''

CGIWrapper/Examples/Directory.py

+29-39
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,42 @@
11
import os
2+
from operator import itemgetter
23
from stat import ST_SIZE
34

45
print '''%s
56
<html>
6-
<head>
7-
<title>Webware CGI Examples Directory</title>
8-
</head>
9-
<body>
10-
<h1 align="center">Webware CGI Examples</h1>
7+
<head>
8+
<title>Webware CGI Examples Directory</title>
9+
</head>
10+
<body>
11+
<h1 align="center">Webware CGI Examples</h1>
1112
''' % wrapper.docType()
1213

13-
def sizeSorter(a, b):
14-
"""Sort by size
15-
16-
Used for sorting when the elements are dictionaries and the
17-
attribute to sort by is 'size'.
18-
19-
"""
20-
return int(a['size'] - b['size'])
21-
2214
# Create a list of dictionaries, where each dictionary stores information about
2315
# a particular script.
24-
scripts = []
25-
for filename in os.listdir(os.curdir):
26-
if len(filename) > 3 and filename[-3:] == '.py':
27-
script = {}
28-
script['pathname'] = filename
29-
script['size'] = os.stat(script['pathname'])[ST_SIZE]
30-
script['shortname'] = filename[:-3]
31-
scripts.append(script)
32-
scripts.sort(sizeSorter)
16+
scripts = sorted((dict(pathname=filename,
17+
shortname=filename[:-3], size=os.stat(filename)[ST_SIZE])
18+
for filename in os.listdir(os.curdir)
19+
if len(filename) > 3 and filename.endswith('.py')),
20+
key=itemgetter('size'))
3321

34-
print '<table cellspacing="2" cellpadding="2" align="center">'
35-
print '<tr>',
36-
print '<th align="right">Size</th>',
37-
print '<th align="left">Script</th>',
38-
print '<th align="left">View</th>',
39-
print '</tr>'
4022

41-
for script in scripts:
42-
print '<tr>',
43-
print '<td align=right> %d </td>' % script['size'],
44-
print '<td> <a href="%s">%s</a> </td>' % (script['shortname'], script['shortname']),
45-
print '<td> <a href="View?filename=%s">view</a> </td>' % script['shortname'],
46-
print '</tr>'
47-
48-
print '</table>'
23+
print '''\
24+
<table cellspacing="0" cellpadding="4" border="1" align="center">
25+
<tr>
26+
<th align="right">Size</th>
27+
<th align="left">Script</th>
28+
<th align="left">View</th>
29+
</tr>'''
4930

50-
print '''
51-
</body>
31+
for script in scripts:
32+
print '''\
33+
<tr>
34+
<td align=right>%(size)d</td>
35+
<td><a href="%(shortname)s">%(shortname)s</a></td>
36+
<td><a href="View?filename=%(shortname)s">view</a></td>
37+
</tr>''' % script
38+
39+
print '''\
40+
</table>
41+
</body>
5242
</html>'''

CGIWrapper/Examples/Error.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""Error.py
22
3-
This program specifically imports a module with an unknown name,
4-
which causes Python to throw an exception. Consequently, you can
5-
see how CGI Wrapper handles errors.
3+
This program causes Python to throw an exception.
4+
Consequently, you can see how CGI Wrapper handles errors.
65
76
"""
87

9-
import UnknownModuleName
8+
raise StandardError('Error example')

CGIWrapper/Examples/Hello.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
print '''%s
33
<html>
4-
<head>
5-
<title>Hello, word!</title>
6-
</head>
7-
<body>
8-
<h1 align="center">Hello, World!</h1>
9-
<p align="center">This is CGI Wrapper %s speaking...</p>
10-
</body>
4+
<head>
5+
<title>Hello, word!</title>
6+
</head>
7+
<body>
8+
<h1 align="center">Hello, World!</h1>
9+
<p align="center">This is CGI Wrapper %s speaking...</p>
10+
</body>
1111
</html>''' % (wrapper.docType(), wrapper.version())

CGIWrapper/Examples/Introspect.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11

22
print '''%s
33
<html>
4-
<head>
5-
<title>Python Introspection</title>
6-
</head>
7-
<body>
8-
<h2>Basic Python Introspection</h2>
4+
<head>
5+
<title>Python Introspection</title>
6+
</head>
7+
<body>
8+
<h2>Basic Python Introspection</h2>
99
''' % wrapper.docType()
1010

1111
def printKeys(name, obj):
12-
keys = obj.keys()
13-
keys.sort()
14-
print '<p> <b>%s</b> = %s' % (name, ', '.join(keys))
12+
print '<p> <b>%s</b> = %s' % (name, ', '.join(sorted(obj)))
1513

1614
printKeys('globals', globals())
1715
printKeys('locals', locals())
@@ -21,8 +19,8 @@ def printKeys(name, obj):
2119
printKeys('wrapper.__dict__', wrapper.__dict__)
2220

2321
print '''
24-
<hr>
25-
<p>Note that the <a href="Error">Error</a> script
26-
results in a much better display of introspection.</p>
27-
</body>
22+
<hr>
23+
<p>Note that the <a href="Error">Error</a> script
24+
results in a much better display of introspection.</p>
25+
</body>
2826
</html>'''

CGIWrapper/Examples/Time.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
print '''%s
55
<html>
6-
<head>
7-
<title>Time</title>
8-
</head>
9-
<body>
10-
<h3>Current Time</h3>
11-
<p>%s</p>
12-
</body>
13-
</html>''' % (wrapper.docType(), time.asctime(time.localtime(time.time())))
6+
<head>
7+
<title>Time</title>
8+
</head>
9+
<body>
10+
<h3>Current Time</h3>
11+
<p>%s</p>
12+
</body>
13+
</html>''' % (wrapper.docType(), time.asctime(time.localtime()))

CGIWrapper/Examples/View.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

33
print '''%s
44
<html>
5-
<head>
6-
<title>Webware View CGI Source</title>
7-
</head>
8-
<body>
9-
<h1>Webware View CGI Source</h1>
5+
<head>
6+
<title>Webware View CGI Source</title>
7+
</head>
8+
<body>
9+
<h1>Webware View CGI Source</h1>
1010
''' % wrapper.docType()
1111

1212
if not fields.has_key('filename'):
1313
print '<p>No filename specified.</p>'
1414
else:
15-
if fields.has_key('tabSize'):
15+
if 'tabSize' in fields:
1616
tabSize = int(fields['tabSize'].value)
1717
else:
1818
tabSize = 4
19-
filename = os.path.basename(fields['filename'].value) + '.py'
19+
filename = os.path.basename(fields['filename'].value)
20+
if not filename.endswith('.py'):
21+
fielname += '.py'
2022
try:
2123
contents = open(filename).read()
2224
except IOError:

CGIWrapper/Properties.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
version = ('X', 'Y', 0)
44

55
docs = [
6-
{'name': "User's Guide", 'file': 'UsersGuide.html'},
6+
{'name': "User's Guide", 'file': 'UsersGuide.html'},
77
]
88

99
status = 'stable'

CGIWrapper/_accessDenied.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
print '''%s
66
<html>
7-
<head>
8-
<title>Access denied</title>
9-
</head>
10-
<body>
11-
<h1>Access denied</h1>
12-
</body>
7+
<head>
8+
<title>Access denied</title>
9+
</head>
10+
<body>
11+
<h1>Access denied</h1>
12+
</body>
1313
</html>''' % wrapper.docType()

0 commit comments

Comments
 (0)