-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathView.py
More file actions
35 lines (32 loc) · 892 Bytes
/
Copy pathView.py
File metadata and controls
35 lines (32 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
print '''%s
<html>
<head>
<title>Webware View CGI Source</title>
</head>
<body>
<h1>Webware View CGI Source</h1>
''' % wrapper.docType()
if 'filename' not in fields:
print '<p>No filename specified.</p>'
else:
if 'tabSize' in fields:
tabSize = int(fields['tabSize'].value)
else:
tabSize = 4
filename = os.path.basename(fields['filename'].value)
if not filename.endswith('.py'):
fielname += '.py'
try:
contents = open(filename).read()
except IOError:
contents = '(cannot view file)'
if tabSize > 0:
contents = contents.expandtabs(tabSize)
contents = contents.replace('&', '&')
contents = contents.replace('<', '<')
contents = contents.replace('>', '>')
print '<h2>%s</h2><hr><pre>%s</pre>' % (filename, contents)
print '''
</body>
</html>'''