comparison wordstream/handlers.py @ 7:c576f5877459

* fix resolution for bad urls; * change URL post to get
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 19 Nov 2011 18:19:13 -0800
parents e21f53582267
children 676ff92e2b1e
comparison
equal deleted inserted replaced
6:ffe01043ecea 7:c576f5877459
51 application_url = [ self.application_path ] 51 application_url = [ self.application_path ]
52 path = application_url + path 52 path = application_url + path
53 return '/'.join(path) 53 return '/'.join(path)
54 54
55 def redirect(self, location): 55 def redirect(self, location):
56 raise exc.HTTPSeeOther(location=location) 56 return exc.HTTPSeeOther(location=location)
57 57
58 class GenshiHandler(Handler): 58 class GenshiHandler(Handler):
59 59
60 def __init__(self, app, request): 60 def __init__(self, app, request):
61 Handler.__init__(self, app, request) 61 Handler.__init__(self, app, request)
145 145
146 return cls(app, request) 146 return cls(app, request)
147 147
148 def Get(self): 148 def Get(self):
149 if 'url' in self.request.GET: 149 if 'url' in self.request.GET:
150 contents = self.url_contents(self.request.GET['url']) 150 try:
151 contents = self.url_contents(self.request.GET['url'])
152 except:
153 return GenshiHandler.Get(self)
151 dissociation = self.dissociation(contents) 154 dissociation = self.dissociation(contents)
152 return Response(content_type='text/html', 155 return Response(content_type='text/html',
153 body='<html><body>%s</body></html>' % dissociation) 156 body='<html><body>%s</body></html>' % dissociation)
154 157
155 158
166 dissociate(corpus, buffer) 169 dissociate(corpus, buffer)
167 return buffer.getvalue() 170 return buffer.getvalue()
168 171
169 def Post(self): 172 def Post(self):
170 if 'url' in self.request.POST: 173 if 'url' in self.request.POST:
171 contents = self.url_contents(self.request.POST['url']) 174 try:
175 contents = self.url_contents(self.request.POST['url'])
176 except:
177 return GenshiHandler.Get(self)
172 elif 'text' in self.request.POST: 178 elif 'text' in self.request.POST:
173 contents = self.request.POST['text'] 179 contents = self.request.POST['text']
174 elif 'file' in self.request.POST: 180 elif 'file' in self.request.POST:
175 contents = self.request.POST['file'].file.read() 181 contents = self.request.POST['file'].file.read()
176 dissociation = self.dissociation(contents) 182 dissociation = self.dissociation(contents)