From d7b7c0ecd5923963f0a75ae791db2fffe3eeb0f3 Mon Sep 17 00:00:00 2001 From: Matthew Wilkes Date: Thu, 2 Feb 2017 18:51:50 +0100 Subject: [PATCH] Move _html to base class, to allow (title, body) responses under WSGI. --- CHANGES.rst | 4 +++ src/ZPublisher/HTTPResponse.py | 62 +++++++++++++++++----------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 954e325964..a480eca8c1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -28,6 +28,10 @@ Bugs Fixed - Use unicode transaction-notes to support ZODB 5. [pbauer] + + - Move _html and _error_html to HTTPBaseResponse to support views that return + a HTML `(title, body)` tuple in WSGIResponses. + [MatthewWilkes] - Don't raise an exception when `WSGIResponse.redirect` is called (these redirects should be followed even when the test browser uses diff --git a/src/ZPublisher/HTTPResponse.py b/src/ZPublisher/HTTPResponse.py index 43bc161ed8..c58d38271e 100644 --- a/src/ZPublisher/HTTPResponse.py +++ b/src/ZPublisher/HTTPResponse.py @@ -674,6 +674,37 @@ def listHeaders(self): result.extend(self.accumulated_headers) return result + def _html(self, title, body): + return ("\n" + "\n%s\n\n" + "\n%s\n\n" + "\n" % (title, body)) + + def _error_html(self, title, body): + return (""" + Site Error + +

Site Error

+

An error was encountered while publishing this resource. +

+

%s

+ + %s""" % (title, body) + """ +
+ +

Troubleshooting Suggestions

+ + + +

If the error persists please contact the site maintainer. + Thank you for your patience. +

""") + class HTTPResponse(HTTPBaseResponse): @@ -721,37 +752,6 @@ def _traceback(self, t, v, tb, as_html=1): tb = format_exception(t, v, tb, as_html=as_html) return '\n'.join(tb) - def _html(self, title, body): - return ("\n" - "\n%s\n\n" - "\n%s\n\n" - "\n" % (title, body)) - - def _error_html(self, title, body): - return (""" - Site Error - -

Site Error

-

An error was encountered while publishing this resource. -

-

%s

- - %s""" % (title, body) + """ -
- -

Troubleshooting Suggestions

- - - -

If the error persists please contact the site maintainer. - Thank you for your patience. -

""") - def notFoundError(self, entry='Unknown'): self.setStatus(404) raise NotFound(self._error_html(