Thanks for the thought and effort on this--it'd be really nice to
resolve for 3.1 final. I'd like to pursue the idea of requiring an
error_page callable to return HTML (but possibly do other things)...have
a look at the branch I made for ticket 800 and see if you can modify it
to do what you described.
I'm still pretty adamantly opposed to using 0 as a magic number to mean
'default'. IMO that sort of information-encoding is a holdover from C
and similar languages where 1) your identifiers need to fit in a CPU
register and 2) static typing promotes shoving out-of-band information
into a struct it was never designed for. In other words, I'd rather see
a new "error_page_default" attribute, or even error_page['default'],
than error_page[0].
Robert Brewer
fuma...@aminus.org
You send the whole page as "body", similar as sending a "message":
def foobar(uri):
try:
location = get_uri(uri)
data = get_data(location)
success = Template(file=filename, searchList=[data])
except:
error = Template(file=filename, searchList=[locals()])
raise HTTPError(404, body=error)
foobar.exposed = True
OK. I'll look at the branch and propose a patch ASAP.
> I'm still pretty adamantly opposed to using 0 as a magic number to mean
> 'default'. IMO that sort of information-encoding is a holdover from C
> and similar languages where 1) your identifiers need to fit in a CPU
> register and 2) static typing promotes shoving out-of-band information
> into a struct it was never designed for. In other words, I'd rather see
> a new "error_page_default" attribute, or even error_page['default'],
> than error_page[0].
I completely agree with that: I'm going to use error_page['default'].
Thanks,
Nicolas
Braydon,
It seems your patch doesn't solve the same kind of problem.
Ticket #800 is about providing a way to customize the error page
returned by default by every HTTPError.
But your proposal, if I understand it well, is about adding a
parameter "body" to HTTPError, in order to customize the error page
returned by a specific instance of HTTPError.
If I am correct, we probably should discuss this in a dedicated
thread, with a descriptive title.
Here is the patch I promised some hours ago. Of course, I've updated
related docstrings and unit tests. I hope it can help solve the ticket
#800.
As I am sending this patch, I think the "callable" should be
authorized to return document types outside of HTML. This is useful
for some kind of servers, like XML-RPC. What do you think about that?
Of course. We wouldn't want the overhead of validating HTML anyway. ;)
The callable can set any Content-Type it likes, and whatever it returns
gets bound to cherrypy.response.body.
Robert Brewer
fuma...@aminus.org
Do you want me resending the patch with updated stringdocs for
inclusion into SVN?
Okay, trunked in http://www.cherrypy.org/changeset/1949. Thanks for the
work!
Just to make things clearer for myself, I also added a slick new chart
to http://www.cherrypy.org/wiki/ErrorsAndExceptions. It sure helped me
decide to favor Nicolas' patch over my own. ;)
Robert Brewer
fuma...@aminus.org
Thanks Robert!
I'm happy to give back something useful to CherryPy :-)
Following Robert's comment: Great work. This is one of the features people
will immediately enjoy :)
- Sylvain
>
> >
--
Sylvain Hellegouarch
http://www.defuze.org