Permalink
Browse files

fix debug error

  • Loading branch information...
1 parent f7abeb0 commit 7a1ff8fb01973b75b850d884c5ed13fc04bd5211 Anand committed Aug 28, 2008
Showing with 28 additions and 37 deletions.
  1. +1 −1 web/application.py
  2. +25 −36 web/debugerror.py
  3. +2 −0 web/wsgi.py
View
@@ -212,8 +212,8 @@ def wsgi(env, start_resp):
except:
print >> web.debug, traceback.format_exc()
web.ctx.status = '500 Internal Server Error'
- web.header('Content-Type', 'text/html')
result = self.internalerror()
+ web.ctx.headers = [('Content-Type', 'text/html')]
if is_generator(result):
result = peep(result)
View
@@ -127,6 +127,24 @@
</head>
<body>
+$def dicttable (d, kls='req', id=None):
+ $ items = d and d.items() or []
+ $items.sort()
+ $:dicttable_items(items, kls, id)
+
+$def dicttable_items(items, kls='req', id=None):
+ $if items:
+ <table class="$kls"
+ $if id: id="$id"
+ ><thead><tr><th>Variable</th><th>Value</th></tr></thead>
+ <tbody>
+ $for k, v in items:
+ <tr><td>$k</td><td class="code"><div>$prettify(v)</div></td></tr>
+ </tbody>
+ </table>
+ $else:
+ <p>No data.</p>
+
<div id="summary">
<h1>$exception_type at $ctx.path</h1>
<h2>$exception_value</h2>
@@ -173,12 +191,7 @@
$if ctx.output or ctx.headers:
<h2>Response so far</h2>
<h3>HEADERS</h3>
- <p class="req"><code>
- $for kv in ctx.headers:
- $kv[0]: $kv[1]<br />
- $else:
- [no headers]
- </code></p>
+ $:dicttable_items(ctx.headers)
<h3>BODY</h3>
<p class="req" style="padding-bottom: 2em"><code>
@@ -194,11 +207,7 @@
$:dicttable(web.cookies())
<h3 id="meta-info">META</h3>
-$ newctx = []
-$# ) and (k not in ['env', 'output', 'headers', 'environ', 'status', 'db_execute']):
-$for k, v in ctx.iteritems():
- $if not k.startswith('_') and (k in x):
- $newctx.append(kv)
+$ newctx = [(k, v) for (k, v) in ctx.iteritems() if not k.startswith('_') and not isinstance(v, dict)]
$:dicttable(dict(newctx))
<h3 id="meta-info">ENVIRONMENT</h3>
@@ -207,33 +216,16 @@
<div id="explanation">
<p>
- You're seeing this error because you have <code>web.internalerror</code>
- set to <code>web.debugerror</code>. Change that if you want a different one.
+ You're seeing this error because you have <code>web.config.debug</code>
+ set to <code>True</code>. Set that to <code>False</code> if you don't to see this.
</p>
</div>
</body>
</html>
"""
-dicttable_t = r"""$def with (d, kls='req', id=None)
-$if d:
- <table class="$kls"\
- $if id: id="$id"\
- ><thead><tr><th>Variable</th><th>Value</th></tr></thead>
- <tbody>
- $ temp = d.items()
- $temp.sort()
- $for kv in temp:
- <tr><td>$kv[0]</td><td class="code"><div>$prettify(kv[1])</div></td></tr>
- </tbody>
- </table>
-$else:
- <p>No data.</p>
-"""
-
-dicttable_r = Template(dicttable_t, filter=websafe)
-djangoerror_r = Template(djangoerror_t, filter=websafe)
+djangoerror_r = Template(djangoerror_t, filename=__file__, filter=websafe)
def djangoerror():
def _get_lines_from_file(filename, lineno, context_lines):
@@ -286,10 +278,9 @@ def prettify(x):
out = '[could not display: <' + e.__class__.__name__ + \
': '+str(e)+'>]'
return out
- dt = dicttable_r
- dt.globals = {'prettify': prettify}
t = djangoerror_r
- t.globals = {'ctx': web.ctx, 'web':web, 'dicttable':dt, 'dict':dict, 'str':str}
+ globals = {'ctx': web.ctx, 'web':web, 'dict':dict, 'str':str, 'prettify': prettify}
+ t.t.func_globals.update(globals)
return t(exception_type, exception_value, frames)
def debugerror():
@@ -300,8 +291,6 @@ def debugerror():
(Based on the beautiful 500 page from [Django](http://djangoproject.com/),
designed by [Wilson Miner](http://wilsonminer.com/).)
"""
-
- web.ctx.headers = [('Content-Type', 'text/html')]
return djangoerror()
def emailerrors(email_address, olderror):
View
@@ -51,4 +51,6 @@ def runwsgi(func):
else:
return runscgi(func)
+ # When running the builtin-server, enable debug mode if not already set.
+ web.config.setdefault('debug', True)
return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))

0 comments on commit 7a1ff8f

Please sign in to comment.