[PEAK] start of an error template, and a few questions
Wayne Larsen
wayne at larsen.st
Wed Feb 11 01:31:29 EST 2004
Here's the start of an error template to be used while debugging. A few
questions I encountered:
* My emacs ~ files threw me for a loop for a while - ResourceDirectory
won't find the template with the ~ file in the directory - is there any
way to exclude ~ files from being seen?
* Is it possible to nest list domlets? The request environment is a
map, how would you iterate over all items in the map, separating the key
and value?
Any comments on how I'm doing this would be welcome. I'm not sure if
the method for accessing data from the interaction is correct.
Thanks,
Wayne
error_404.pwt:
--------------
<html>
<head>
<title><span domlet="text.notag:httpStatus" /> Error</title>
<style type="text/css">
body { font-family: Verdana, Arial, sans-serif; }
pre { background-color: #eeeeee; border: 1px solid #000; padding: 20px; }
#footer { border-top: 1px solid #000; }
</style>
</head>
<body>
<h1>Error <span domlet="text.notag:httpStatus" /></h1>
<div>An error occurred when visiting the uri: <strong
domlet="text:requestUri">/something/here</strong></div>
<h2>Traceback</h2>
<pre domlet="list:formattedException">
<span define="listItem" domlet="text.notag" /><br />
</pre>
<h2>Request Environment</h2>
<ul domlet="list:environment">
<li define="listItem" domlet="text" >list item</li>
</ul>
<div id='footer'>peak.web</div>
</body>
</html>
Exception Decorator:
--------------------
import traceback
class WebExceptionDecorator(Decorator):
protocols.advise(
instancesProvide = [IWebTraversable],
factoryMethod = 'asTraversableFor',
asAdapterForTypes = [WebException],
)
security.allow(
formattedException = security.Anybody,
environment = security.Anybody,
requestUri = security.Anybody,
)
environment = binding.Make(lambda s: \
s.ob.interaction.request.environment.items())
requestUri = binding.Make(lambda s: \
s.ob.interaction.request.environment['REQUEST_URI'])
formattedException = binding.Make(lambda s: \
traceback.format_exception(s.ob.exc_info[0],
s.ob.exc_info[1],
s.ob.exc_info[2]))
More information about the PEAK
mailing list