-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathcontentapp.py
50 lines (36 loc) · 1.29 KB
/
contentapp.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
#!/usr/bin/python3
"""
contentApp class
Simple web application for managing content
Copyright Jesus M. Gonzalez-Barahona, Gregorio Robles 2009-2015
jgb, grex @ gsyc.es
TSAI, SAT and SARO subjects (Universidad Rey Juan Carlos)
October 2009 - March 2015
"""
import webapp
class contentApp (webapp.webApp):
"""Simple web application for managing content.
Content is stored in a dictionary, which is intialized
with the web content."""
# Declare and initialize content
content = {'/': 'Root page',
'/page': 'A page'
}
def parse(self, request):
"""Return the resource name (including /)"""
return request.split(' ', 2)[1]
def process(self, resourceName):
"""Process the relevant elements of the request.
Finds the HTML text corresponding to the resource name,
ignoring requests for resources not in the dictionary.
"""
if resourceName in self.content.keys():
httpCode = "200 OK"
htmlBody = "<html><body>" + self.content[resourceName] \
+ "</body></html>"
else:
httpCode = "404 Not Found"
htmlBody = "Not Found"
return (httpCode, htmlBody)
if __name__ == "__main__":
testWebApp = contentApp("localhost", 1234)