Skip to content

Commit

Permalink
Bring back ntob and the call that relies on it in CherryPy tests. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Nov 18, 2017
1 parent 53e23de commit 1995c6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v5.9.1
======

- #58: Reverted encoding behavior in wsgi module to correct
regression in CherryPy tests.

v5.9.0
======

Expand Down
13 changes: 13 additions & 0 deletions cheroot/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import six

if six.PY3:
def ntob(n, encoding='ISO-8859-1'):
"""Return the given native string as a byte string in the given encoding."""
assert_native(n)
# In Python 3, the native string type is unicode
return n.encode(encoding)

def ntou(n, encoding='ISO-8859-1'):
"""Return the given native string as a unicode string with the given encoding."""
assert_native(n)
Expand All @@ -16,6 +22,13 @@ def bton(b, encoding='ISO-8859-1'):
return b.decode(encoding)
else:
# Python 2
def ntob(n, encoding='ISO-8859-1'):
"""Return the given native string as a byte string in the given encoding."""
assert_native(n)
# In Python 2, the native string type is bytes. Assume it's already
# in the given encoding, which for ISO-8859-1 is almost always what
# was intended.
return n

def ntou(n, encoding='ISO-8859-1'):
"""Return the given native string as a unicode string with the given encoding."""
Expand Down
4 changes: 2 additions & 2 deletions cheroot/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def my_crazy_app(environ, start_response):

from . import server
from .workers import threadpool
from ._compat import bton
from ._compat import ntob, bton


class Server(server.HTTPServer):
Expand Down Expand Up @@ -161,7 +161,7 @@ def start_response(self, status, headers, exc_info=None):
'WSGI response header value %r is not of type str.' % v)
if k.lower() == 'content-length':
self.remaining_bytes_out = int(v)
out_header = k.encode('iso-8859-1'), v.encode('iso-8859-1')
out_header = ntob(k), ntob(v)
self.req.outheaders.append(out_header)

return self.write
Expand Down

0 comments on commit 1995c6c

Please sign in to comment.