Mercurial > hg > wordstream
comparison wordstream/handlers.py @ 11:676ff92e2b1e
py3
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 24 Nov 2020 10:36:47 -0800 |
parents | c576f5877459 |
children | 5a45f0c4cb87 |
comparison
equal
deleted
inserted
replaced
10:bad7e66f4f24 | 11:676ff92e2b1e |
---|---|
1 """ | 1 """ |
2 request handlers: | 2 request handlers: |
3 these are instantiated for every request, then called | 3 these are instantiated for every request, then called |
4 """ | 4 """ |
5 | 5 |
6 import urllib2 | 6 from urllib2.request import urlopen |
7 | 7 |
8 from pprint import pprint | 8 from pprint import pprint |
9 from urlparse import urlparse | 9 from urlparse import urlparse |
10 from webob import Response, exc | 10 from webob import Response, exc |
11 from StringIO import StringIO | 11 from StringIO import StringIO |
12 from wordstream.api import Corpus | 12 from .api import Corpus |
13 from wordstream.dissociate import dissociate | 13 from .dissociate import dissociate |
14 | |
14 | 15 |
15 class HandlerMatchException(Exception): | 16 class HandlerMatchException(Exception): |
16 """the handler doesn't match the request""" | 17 """the handler doesn't match the request""" |
17 | 18 |
19 | |
18 class Handler(object): | 20 class Handler(object): |
19 | 21 |
20 methods = set(['GET']) # methods to listen to | 22 methods = set(['GET']) # methods to listen to |
21 handler_path = [] # path elements to match | 23 handler_path = [] # path elements to match |
22 | 24 |
23 @classmethod | 25 @classmethod |
24 def match(cls, app, request): | 26 def match(cls, app, request): |
25 | 27 |
26 # check the method | 28 # check the method |
157 | 159 |
158 | 160 |
159 return GenshiHandler.Get(self) | 161 return GenshiHandler.Get(self) |
160 | 162 |
161 def url_contents(self, url): | 163 def url_contents(self, url): |
162 return urllib2.urlopen(url).read() | 164 return urlopen(url).read() |
163 | 165 |
164 def dissociation(self, contents): | 166 def dissociation(self, contents): |
165 corpus = Corpus() | 167 corpus = Corpus() |
166 corpus.feed_stream(contents) | 168 corpus.feed_stream(contents) |
167 corpus.scramble() | 169 corpus.scramble() |