> Couldn't you do this by overriding _q_traverse on your root
> Directory instance? Something like:
That's a reasonable place, but it has the same problem: I don't have
access to the output in the case of exceptions because it hasn't been
generated yet. And in fact, I can't get the publisher to do
finish_*_request from _q_traverse().
Here's what I wound up doing looks like:
def try_publish(self, request):
self.start_request()
path = request.get_environ('PATH_INFO', '')
assert path[:1] == '/'
# split path into components
path = path[1:].split('/')
try:
output = None
# code A, save stuff
output = self.root_directory._q_traverse(path)
finally:
if output is None:
exc_info = sys.exc_info()
exc = exc_info[1]
if isinstance(exc, quixote.error.PublishError):
output = self.finish_interrupted_request(exc)
else:
output = self.finish_failed_request()
output = self.filter_output(req, output)
# code B, uses output and saved stuff
# The callable ran OK, commit any changes to the session
self.finish_successful_request()
return output
Clearly, calling finish_*_request multiple times is not ideal.