allura
リビジョン | d2beb7ff63ffabf54b309f2d0fda241ade19e97e (tree) |
---|---|
日時 | 2010-06-23 01:18:28 |
作者 | Rick Copeland <rcopeland@geek...> |
コミッター | Rick Copeland |
[#574] - Diff based on words, not characters
@@ -8,6 +8,7 @@ import tg | ||
8 | 8 | import pylons |
9 | 9 | import pkg_resources |
10 | 10 | from paste import fileapp |
11 | +from paste.deploy.converters import asbool | |
11 | 12 | from pylons.util import call_wsgi_application |
12 | 13 | from tg.controllers import DecoratedController |
13 | 14 | from webob import exc, Request |
@@ -177,6 +178,7 @@ class StatsMiddleware(object): | ||
177 | 178 | self.active = False |
178 | 179 | try: |
179 | 180 | self.sample_rate = config.get('stats.sample_rate', 0.25) |
181 | + self.debug = asbool(config.get('debug', 'false')) | |
180 | 182 | self.instrument_pymongo() |
181 | 183 | self.instrument_template() |
182 | 184 | self.active = True |
@@ -205,7 +207,7 @@ class StatsMiddleware(object): | ||
205 | 207 | req = Request(environ) |
206 | 208 | req.environ['sf.stats'] = s = StatsRecord(req, random() < self.sample_rate) |
207 | 209 | with s.timing('total'): |
208 | - resp = req.get_response(self.app) | |
210 | + resp = req.get_response(self.app, catch_exc_info=self.debug) | |
209 | 211 | result = resp(environ, start_response) |
210 | 212 | if s.active: |
211 | 213 | self.log.info('Stats: %r', s) |
@@ -243,17 +243,19 @@ def absurl(url): | ||
243 | 243 | return request.scheme + '://' + request.host + url |
244 | 244 | |
245 | 245 | def diff_text(t1, t2, differ=None): |
246 | + t1_words = re.split(' ', t1) | |
247 | + t2_words = re.split(' ', t2) | |
246 | 248 | if differ is None: |
247 | - differ = difflib.SequenceMatcher(None, t1, t2) | |
249 | + differ = difflib.SequenceMatcher(None, t1_words, t2_words) | |
248 | 250 | result = [] |
249 | 251 | for tag, i1, i2, j1, j2 in differ.get_opcodes(): |
250 | 252 | if tag in ('delete', 'replace'): |
251 | - result += [ '<del>', t1[i1:i2], '</del>' ] | |
253 | + result += [ '<del>' ] + t1_words[i1:i2] + [ '</del>' ] | |
252 | 254 | if tag in ('insert', 'replace'): |
253 | - result += [ '<ins>', t2[j1:j2], '</ins>' ] | |
255 | + result += [ '<ins>' ] + t2_words[j1:j2] + [ '</ins>' ] | |
254 | 256 | if tag == 'equal': |
255 | - result += t1[i1:i2] | |
256 | - return ''.join(result).replace('\n', '<br/>\n') | |
257 | + result += t1_words[i1:i2] | |
258 | + return ' '.join(result).replace('\n', '<br/>\n') | |
257 | 259 | |
258 | 260 | def diff_text_genshi(t1, t2): |
259 | 261 | Markup = genshi.Markup |