Mercurial > hg > TagInTheMiddle
annotate taginthemiddle/handlers.py @ 18:3bf478cb3166
make a BogusAuth class for testing purposes
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 24 May 2010 07:48:48 -0700 |
parents | c85d42296c06 |
children |
rev | line source |
---|---|
0
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 """ |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 request handlers: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 these are instantiated for every request, then called |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 """ |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 from urlparse import urlparse |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 from webob import Response, exc |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 class HandlerMatchException(Exception): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 """the handler doesn't match the request""" |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 class Handler(object): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 methods = set(['GET']) # methods to listen to |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 handler_path = [] # path elements to match |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 @classmethod |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 def match(cls, app, request): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 # check the method |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 if request.method not in cls.methods: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 return None |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 # check the path |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 if request.environ['path'][:len(cls.handler_path)] != cls.handler_path: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
26 return None |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
27 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
28 try: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
29 return cls(app, request) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
30 except HandlerMatchException: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
31 return None |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
32 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
33 def __init__(self, app, request): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
34 self.app = app |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
35 self.request = request |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
36 self.application_path = urlparse(request.application_url)[2] |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
37 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
38 def link(self, path=(), permanant=False): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
39 if isinstance(path, basestring): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
40 path = [ path ] |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
41 path = [ i.strip('/') for i in path ] |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
42 if permanant: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
43 application_url = [ self.request.application_url ] |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
44 else: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
45 application_url = [ self.application_path ] |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
46 path = application_url + path |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
47 return '/'.join(path) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
48 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
49 def redirect(self, location): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
50 raise exc.HTTPSeeOther(location=location) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
51 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
52 class GenshiHandler(Handler): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
53 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
54 def __init__(self, app, request): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
55 Handler.__init__(self, app, request) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
56 self.data = { 'request': request, |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
57 'link': self.link } |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
58 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
59 def __call__(self): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
60 return getattr(self, self.request.method.title())() |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
61 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
62 def Get(self): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
63 # needs to have self.template set |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
64 template = self.app.loader.load(self.template) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
65 return Response(content_type='text/html', |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
66 body=template.generate(**self.data).render('html')) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
67 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
68 class TagCloud(GenshiHandler): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
69 template = 'cloud.html' |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
70 methods = set(['GET']) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
71 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
72 @classmethod |
2
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
73 def match(cls, app, request): |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
74 |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
75 # check the method |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
76 if request.method not in cls.methods: |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
77 return None |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
78 |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
79 # check the path |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
80 if request.path_info.endswith('/%s' % app.tags_url): |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
81 try: |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
82 return cls(app, request) |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
83 except HandlerMatchException: |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
84 return None |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
85 |
0
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
86 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
87 class ViewTags(GenshiHandler): |
16
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
88 """ |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
89 View for tags on a resource; for app.tags_url == 'tags': |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
90 |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
91 /<resource>/tags/mozilla : |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
92 all paths under /<resource> tagged with 'mozilla' |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
93 |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
94 /<resource>/tags/mozilla+workflow : |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
95 all paths under /<resource> tagged with 'mozilla' and 'workflow' |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
96 (or should it be /<resource>/tags/mozilla/workflow , which would be |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
97 identical to /<resource>/tags/workflow/mozilla ?) |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
98 |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
99 Also handles RSS: |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
100 /<resource>/tags/mozilla?format=rss |
17
c85d42296c06
make the model almost be real
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
101 |
c85d42296c06
make the model almost be real
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
102 Maybe this takes care of the TagCloud too? And/or view as most recent? |
16
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
103 """ |
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
104 |
0
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
105 template = 'tags.html' |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
106 methods = set(['GET']) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
107 |
2
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
108 def __init__(self, app, request): |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
109 GenshiHandler.__init__(self, app, request) |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
110 path = request.path_info.split('/') |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
111 try: |
11
fc55d95be553
it is list.index, not list.find, silly!
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
112 index = path.index(app.tags_url) |
2
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
113 except ValueError: |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
114 raise HandlerMatchException |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
115 self.tags = path[index+1:] |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
116 if not self.tags: |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
117 raise HandlerMatchException |
14
86118cd8912e
display what tags we are talking about
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
118 self.data['tags'] = self.tags |
2
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
119 |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
120 @classmethod |
0
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
121 def match(cls, app, request): |
16
5f492a6fbdd1
add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
122 |
2
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
123 # check the method |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
124 if request.method not in cls.methods: |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
125 return None |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
126 |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
127 try: |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
128 return cls(app, request) |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
129 except HandlerMatchException: |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
130 return None |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
131 |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
132 def Get(self): |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
133 if self.request.GET.get('format') == 'rss': |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
134 pass # TODO |
1182315b18ac
add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
135 return GenshiHandler.Get(self) |
0
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
136 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
137 class PostTags(Handler): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
138 methods = set(['POST']) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
139 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
140 @classmethod |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
141 def match(cls, app, request): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
142 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
143 # check the method |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
144 if request.method not in cls.methods: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
145 return None |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
146 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
147 # check auth |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
148 if not request.remote_user: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
149 return None |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
150 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
151 # check the path |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
152 if request.path_info.endswith('/%s' % app.post_url): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
153 try: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
154 return cls(app, request) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
155 except HandlerMatchException: |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
156 return None |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
157 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
158 def __call__(self): |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
159 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
160 # get the url |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
161 url = self.request.path_info.rsplit('/' + self.app.post_url, 1)[0] |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
162 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
163 # add and remove tags |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
164 # TODO |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
165 |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
166 # redirect to original resource |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
167 return exc.HTTPSeeOther(location=url) |
1c5cbbde4299
initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
168 |