Skip to content

Commit

Permalink
Avoid casting the body to a string when it is already a string
Browse files Browse the repository at this point in the history
  • Loading branch information
ale-rt committed Apr 30, 2024
1 parent 516fd00 commit 8cfde70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst
For details, see
`#1202 <https://github.com/zopefoundation/Zope/issues/1202>`_.

- Small optimization when encoding the response body.

5.9 (2023-11-24)
----------------
Expand Down
4 changes: 3 additions & 1 deletion src/ZPublisher/HTTPResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ def setBody(self, body, title='', is_error=False, lock=None):
except (TypeError, UnicodeError):
pass
if not isinstance(body, bytes):
body = self._encode_unicode(str(body))
if not isinstance(body, str):
body = str(body)
body = self._encode_unicode(body)

# At this point body is always binary
b_len = len(body)
Expand Down

0 comments on commit 8cfde70

Please sign in to comment.