-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.cgi
executable file
·39 lines (26 loc) · 877 Bytes
/
index.cgi
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
#!/local/bin/python
import cgi,cgitb
cgitb.enable()
import imports
import os
from postcontroller import PostController
from commentcontroller import CommentController
from usercontroller import UserController
url_args = cgi.FieldStorage()
# map controller names to their classes
classes = {
'user' : UserController,
'post' : PostController,
'comment' : CommentController
}
#build argument list
args = dict()
arg_keys = url_args.keys()
for key in arg_keys:
args[key] = url_args.getvalue(key)
# get class name from url args
className = url_args.getvalue('class') if 'class' in url_args.keys() else 'post'
# get method from url -- defaults to show()
methodName = url_args.getvalue('method') if 'method' in url_args.keys() else 'show'
#call the class and method from the URL
getattr(classes[className](), methodName)(args)