北漂IT民工 的博客

一个Google App Engine的请求分派框架

作了一个APPENGINE的请求分派框架
这样就可以将不同的请求分派到不同的类里面去了。
很容易修改与维护

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

#encoding=UTF-8

import wsgiref.handlers

import os</p>

from os import environ

from google.appengine.ext import webapp

from google.appengine.ext import db

from google.appengine.ext.webapp import template

from appengine_utilities.sessions import Session

import User

import PhoneBook

class MainPage(webapp.RequestHandler):

tpath = os.path.dirname(__file__)

def get(self):

self.response.out.write(template.render(os.path.dirname(__file__) + "/template/index.html",{'register': '/user?act=register', 'login': '/user?act=login'}))

def post(self):

self.response.out.write('Hello, webapp World! Post')

class UnaryPage(webapp.RequestHandler):

def get(self, module):

s = Session()

if module == "user":

user = User(self, "get", s)

if module == "phonebook":

phonebook = PhoneBook(self, "get", s)

def post(self, module):

s = Session()

if module == "user":

user = User(self, 'post', s)

if module == "phonebook":

phonebook = PhoneBook(self, "post", s)

class BinaryPage(webapp.RequestHandler):

def get(self, module, act):

return

def post(self, module, act):

return

class TernaryPage(webapp.RequestHandler):

def get(self, module, act, param):

return

def post(self):

return

def main():

application = webapp.WSGIApplication(

[

('/', MainPage),

('/(.*)/(.*)/(.*)', MainPage.TernaryPage),

('/(.*)/(.*)', MainPage.BinaryPage),

('/(.*)', MainPage.UnaryPage),

],

debug=True)

wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":

main()