[CherryPy] #800: Request ability to override default error template (replaces ticket #795)

1 view
Skip to first unread message

CherryPy

unread,
Mar 19, 2008, 9:22:31 AM3/19/08
to cherrypy...@googlegroups.com
#800: Request ability to override default error template (replaces ticket #795)
----------------------------------+-----------------------------------------
Reporter: scha...@mischko.com | Owner: rdelon
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: CherryPy code | Keywords:
----------------------------------+-----------------------------------------
It would be nice if we could specify a default error template file.

Simply changing _cperror.py lines 276-280 CP_303:

{{{
# Replace the default template with a custom one?
error_page_file = cherrypy.request.error_page.get(code, '')
if error_page_file:
try:
template = file(error_page_file, 'rb').read()
}}}
to this:
{{{
# Replace the default template with a custom one?
error_page_file = cherrypy.request.error_page.get(code, '')
# If there's no custom one for that error number, is there a default?
if not error_page_file:
error_page_file = cherrypy.request.error_page.get(0, '')
if error_page_file:
try:
# If it's a Python file, import everything from it.
if error_page_file.split('.')[-1].lower() == 'py':
exec('from %s import *' % error_page_file.split('.')[0])
if 'kwargs_update' in locals():
kwargs.update(kwargs_update)
# Otherwise, it's just a template in a file.
else:
template = file(error_page_file, 'rb').read()
}}}

Would change things:

* Defining a default error page handler (where N is the error page
number):
* 'error_page.N': 'error_config.py', or
* 'error_page.N': 'error_config.foo'
* If N is 0, the error_page template will be used in place of the built-
in default.
* Custom error pages are imported if they end in ".py". Otherwise they
are read in.
* Imported pages can include a kwargs_udpate dictionary which will be
included in the kwargs, if present.

This is completely backwards compatible.

--
Ticket URL: <http://www.cherrypy.org/ticket/800>
CherryPy <http://www.cherrypy.org>
CherryPy - a pythonic, object-oriented HTTP framework

CherryPy

unread,
Mar 19, 2008, 12:34:31 PM3/19/08
to cherrypy...@googlegroups.com
#800: Request ability to override default error template (replaces ticket #795)
----------------------------------+-----------------------------------------
Reporter: scha...@mischko.com | Owner: fumanchu
Type: enhancement | Status: assigned
Priority: normal | Milestone: 3.1
Component: CherryPy code | Resolution:
Keywords: |
----------------------------------+-----------------------------------------
Changes (by fumanchu):

* milestone: => 3.1
* owner: rdelon => fumanchu
* status: new => assigned

Comment:

That's starting to get messy IMO. I think, rather than chasing ever-more-
complicated templating declarations, we'd be better off just allowing
users to call arbitrary callables instead of HTTPError.set_response:

{{{
#!python
except (cherrypy.HTTPRedirect, cherrypy.HTTPError), inst:
ep = self.error_page.get(inst.status, '')
if ep and callable(ep):
ep(inst)
else:
inst.set_response()
}}}

Then the user could set the response status, headers, and body however
they liked. I've got this coded up but not passing the test suite yet.

CherryPy

unread,
Mar 25, 2008, 8:43:17 PM3/25/08
to cherrypy...@googlegroups.com
#800: Request ability to override default error template (replaces ticket #795)
----------------------------------+-----------------------------------------
Reporter: scha...@mischko.com | Owner: fumanchu
Type: enhancement | Status: assigned
Priority: normal | Milestone: 3.1
Component: CherryPy code | Resolution:
Keywords: |
----------------------------------+-----------------------------------------
Comment (by fumanchu):

The attached error_page_callable.patch works, but I'm not 100% happy with
it yet. There needs to be an ''obvious'' balance between complete
flexibility and the safety provided by e.g. clean_headers, and IMO just
asking everyone who implements an error_page callable to remember to set
the status and call clean_headers isn't good enough. Somehow those safety
features should be "on by default" but easy to turn off.

CherryPy

unread,
Apr 5, 2008, 4:41:04 PM4/5/08
to cherrypy...@googlegroups.com
#800: Request ability to override default error template (replaces ticket #795)
----------------------------------+-----------------------------------------
Reporter: scha...@mischko.com | Owner: fumanchu
Type: enhancement | Status: assigned
Priority: normal | Milestone: 3.1
Component: CherryPy code | Resolution:
Keywords: |
----------------------------------+-----------------------------------------
Comment (by fumanchu):

Branched in [1941].

CherryPy

unread,
Apr 26, 2008, 6:50:30 PM4/26/08
to cherrypy...@googlegroups.com
#800: Request ability to override default error template (replaces ticket #795)
----------------------------------+-----------------------------------------
Reporter: scha...@mischko.com | Owner: fumanchu
Type: enhancement | Status: closed
Priority: normal | Milestone: 3.1
Component: CherryPy code | Resolution: fixed
Keywords: |
----------------------------------+-----------------------------------------
Changes (by fumanchu):

* resolution: => fixed
* status: assigned => closed

Comment:

Trunked in [1949].
Reply all
Reply to author
Forward
0 new messages