Skip to content

Commit

Permalink
Move _html to base class, to allow (title, body) responses under WSGI.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewWilkes authored and jensens committed May 5, 2017
1 parent 74fd257 commit 52cdeb4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -45,6 +45,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
Expand Down
62 changes: 31 additions & 31 deletions src/ZPublisher/HTTPResponse.py
Expand Up @@ -674,6 +674,37 @@ def listHeaders(self):
result.extend(self.accumulated_headers)
return result

def _html(self, title, body):
return ("<html>\n"
"<head>\n<title>%s</title>\n</head>\n"
"<body>\n%s\n</body>\n"
"</html>\n" % (title, body))

def _error_html(self, title, body):
return ("""<!DOCTYPE html><html>
<head><title>Site Error</title><meta charset="utf-8" /></head>
<body bgcolor="#FFFFFF">
<h2>Site Error</h2>
<p>An error was encountered while publishing this resource.
</p>
<p><strong>%s</strong></p>
%s""" % (title, body) + """
<hr noshade="noshade"/>
<p>Troubleshooting Suggestions</p>
<ul>
<li>The URL may be incorrect.</li>
<li>The parameters passed to this resource may be incorrect.</li>
<li>A resource that this resource relies on may be
encountering an error.</li>
</ul>
<p>If the error persists please contact the site maintainer.
Thank you for your patience.
</p></body></html>""")


class HTTPResponse(HTTPBaseResponse):

Expand Down Expand Up @@ -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 ("<html>\n"
"<head>\n<title>%s</title>\n</head>\n"
"<body>\n%s\n</body>\n"
"</html>\n" % (title, body))

def _error_html(self, title, body):
return ("""<!DOCTYPE html><html>
<head><title>Site Error</title><meta charset="utf-8" /></head>
<body bgcolor="#FFFFFF">
<h2>Site Error</h2>
<p>An error was encountered while publishing this resource.
</p>
<p><strong>%s</strong></p>
%s""" % (title, body) + """
<hr noshade="noshade"/>
<p>Troubleshooting Suggestions</p>
<ul>
<li>The URL may be incorrect.</li>
<li>The parameters passed to this resource may be incorrect.</li>
<li>A resource that this resource relies on may be
encountering an error.</li>
</ul>
<p>If the error persists please contact the site maintainer.
Thank you for your patience.
</p></body></html>""")

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

0 comments on commit 52cdeb4

Please sign in to comment.