-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
executable file
·51 lines (41 loc) · 1.22 KB
/
index.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""The basic frontend of our webapp; takes in cgi parameters, sanitizes them,
and passes them off to the rest of the app.
Joe Adkisson
Jamie Emery
Michael Stoneman
"""
#import cgitb
#cgitb.enable()
import cgi
from UserInputParser import UserInputParser
def main():
params = getParameters()
backend = UserInputParser(params)
htmlPage = backend.generateHtmlPageOutput()
print 'Content-type: text/html\r\n\r\n'
print htmlPage
def getParameters():
params = {}
form = cgi.FieldStorage()
param_list = ['senator', 'bill', 'state', 'session', 'committee']
for entry in param_list:
if entry in form:
params[entry] = sanitizeInput(form[entry].value)
#We're not giving a default value to empty cgi params;
#if they become important later, they'll just throw a null pointer
#exception which will get caught.
# page_type gets special treatment so that it defaults to the homepage
if 'page_type' in form:
params['page_type'] = sanitizeInput(form['page_type'].value)
else:
params['page_type'] = 'home'
return params
def sanitizeInput(yarn):
chars_to_remove = ";,\\/:'\"<>@"
for ch in chars_to_remove:
yarn = yarn.replace(ch, '');
return yarn
if __name__ == '__main__':
main()