Changeset 5051
- Timestamp:
- 04/20/07 23:37:31 (2 years ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/views/debug.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r5042 r5051 181 181 remco@diji.biz 182 182 rhettg@gmail.com 183 Armin Ronacher 183 184 Oliver Rutherfurd <http://rutherfurd.net/> 184 185 Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/> django/trunk/django/views/debug.py
r4959 r5051 91 91 frames = [] 92 92 while tb is not None: 93 # support for __traceback_hide__ which is used by a few libraries 94 # to hide internal frames. 95 if tb.tb_frame.f_locals.get('__traceback_hide__'): 96 tb = tb.tb_next 97 continue 93 98 filename = tb.tb_frame.f_code.co_filename 94 99 function = tb.tb_frame.f_code.co_name 95 100 lineno = tb.tb_lineno - 1 96 pre_context_lineno, pre_context, context_line, post_context = _get_lines_from_file(filename, lineno, 7) 97 if pre_context_lineno: 101 loader = tb.tb_frame.f_globals.get('__loader__') 102 module_name = tb.tb_frame.f_globals.get('__name__') 103 pre_context_lineno, pre_context, context_line, post_context = _get_lines_from_file(filename, lineno, 7, loader, module_name) 104 if pre_context_lineno is not None: 98 105 frames.append({ 99 106 'tb': tb, … … 162 169 return HttpResponseNotFound(t.render(c), mimetype='text/html') 163 170 164 def _get_lines_from_file(filename, lineno, context_lines ):171 def _get_lines_from_file(filename, lineno, context_lines, loader=None, module_name=None): 165 172 """ 166 173 Returns context_lines before and after lineno from file. 167 174 Returns (pre_context_lineno, pre_context, context_line, post_context). 168 175 """ 169 try: 170 source = open(filename).readlines() 171 lower_bound = max(0, lineno - context_lines) 172 upper_bound = lineno + context_lines 173 174 pre_context = [line.strip('\n') for line in source[lower_bound:lineno]] 175 context_line = source[lineno].strip('\n') 176 post_context = [line.strip('\n') for line in source[lineno+1:upper_bound]] 177 178 return lower_bound, pre_context, context_line, post_context 179 except (OSError, IOError): 176 source = None 177 if loader is not None: 178 source = loader.get_source(module_name).splitlines() 179 else: 180 try: 181 f = open(filename) 182 try: 183 source = f.readlines() 184 finally: 185 f.close() 186 except (OSError, IOError): 187 pass 188 if source is None: 180 189 return None, [], None, [] 190 191 lower_bound = max(0, lineno - context_lines) 192 upper_bound = lineno + context_lines 193 194 pre_context = [line.strip('\n') for line in source[lower_bound:lineno]] 195 context_line = source[lineno].strip('\n') 196 post_context = [line.strip('\n') for line in source[lineno+1:upper_bound]] 197 198 return lower_bound, pre_context, context_line, post_context 181 199 182 200 # … … 315 333 <tr> 316 334 <th>Exception Location:</th> 317 <td>{{ lastframe.filename }} in {{ lastframe.function}}, line {{ lastframe.lineno }}</td>335 <td>{{ lastframe.filename|escape }} in {{ lastframe.function|escape }}, line {{ lastframe.lineno }}</td> 318 336 </tr> 319 337 </table> … … 362 380 {% for frame in frames %} 363 381 <li class="frame"> 364 <code>{{ frame.filename }}</code> in <code>{{ frame.function}}</code>382 <code>{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code> 365 383 366 384 {% if frame.context_line %}
