summaryrefslogtreecommitdiff
path: root/cherrypy/test/test_encoding.py
diff options
context:
space:
mode:
Diffstat (limited to 'cherrypy/test/test_encoding.py')
-rw-r--r--cherrypy/test/test_encoding.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/cherrypy/test/test_encoding.py b/cherrypy/test/test_encoding.py
index 62d7fb16..97adad94 100644
--- a/cherrypy/test/test_encoding.py
+++ b/cherrypy/test/test_encoding.py
@@ -54,7 +54,7 @@ class EncodingTests(helper.CPWebCase):
@cherrypy.expose
def reqparams(self, *args, **kwargs):
- return ntob(', ').join(
+ return b', '.join(
[': '.join((k, v)).encode('utf8')
for k, v in sorted(cherrypy.request.params.items())]
)
@@ -129,7 +129,7 @@ class EncodingTests(helper.CPWebCase):
# Here, q is the POUND SIGN U+00A3 encoded in utf8 and then %HEX
self.getPage(URI_TMPL.format(q=url_quote(europoundUtf8_2_bytes)))
# The return value will be encoded as utf8.
- self.assertBody(ntob('q: ') + europoundUtf8_2_bytes)
+ self.assertBody(b'q: ' + europoundUtf8_2_bytes)
# Query strings that are incorrectly encoded MUST raise 404.
# Here, q is the second byte of POUND SIGN U+A3 encoded in utf8
@@ -145,7 +145,7 @@ class EncodingTests(helper.CPWebCase):
def test_urlencoded_decoding(self):
# Test the decoding of an application/x-www-form-urlencoded entity.
europoundUtf8 = europoundUnicode.encode('utf-8')
- body = ntob('param=') + europoundUtf8
+ body = b'param=' + europoundUtf8
self.getPage('/',
method='POST',
headers=[
@@ -157,17 +157,17 @@ class EncodingTests(helper.CPWebCase):
# Encoded utf8 entities MUST be parsed and decoded correctly.
# Here, q is the POUND SIGN U+00A3 encoded in utf8
- body = ntob('q=\xc2\xa3')
+ body = b'q=\xc2\xa3'
self.getPage('/reqparams', method='POST',
headers=[(
'Content-Type', 'application/x-www-form-urlencoded'),
('Content-Length', str(len(body))),
],
body=body),
- self.assertBody(ntob('q: \xc2\xa3'))
+ self.assertBody(b'q: \xc2\xa3')
# ...and in utf16, which is not in the default attempt_charsets list:
- body = ntob('\xff\xfeq\x00=\xff\xfe\xa3\x00')
+ body = b'\xff\xfeq\x00=\xff\xfe\xa3\x00'
self.getPage('/reqparams',
method='POST',
headers=[
@@ -176,12 +176,12 @@ class EncodingTests(helper.CPWebCase):
('Content-Length', str(len(body))),
],
body=body),
- self.assertBody(ntob('q: \xc2\xa3'))
+ self.assertBody(b'q: \xc2\xa3')
# Entities that are incorrectly encoded MUST raise 400.
# Here, q is the POUND SIGN U+00A3 encoded in utf16, but
# the Content-Type incorrectly labels it utf-8.
- body = ntob('\xff\xfeq\x00=\xff\xfe\xa3\x00')
+ body = b'\xff\xfeq\x00=\xff\xfe\xa3\x00'
self.getPage('/reqparams',
method='POST',
headers=[
@@ -199,30 +199,30 @@ class EncodingTests(helper.CPWebCase):
def test_decode_tool(self):
# An extra charset should be tried first, and succeed if it matches.
# Here, we add utf-16 as a charset and pass a utf-16 body.
- body = ntob('\xff\xfeq\x00=\xff\xfe\xa3\x00')
+ body = b'\xff\xfeq\x00=\xff\xfe\xa3\x00'
self.getPage('/decode/extra_charset', method='POST',
headers=[(
'Content-Type', 'application/x-www-form-urlencoded'),
('Content-Length', str(len(body))),
],
body=body),
- self.assertBody(ntob('q: \xc2\xa3'))
+ self.assertBody(b'q: \xc2\xa3')
# An extra charset should be tried first, and continue to other default
# charsets if it doesn't match.
# Here, we add utf-16 as a charset but still pass a utf-8 body.
- body = ntob('q=\xc2\xa3')
+ body = b'q=\xc2\xa3'
self.getPage('/decode/extra_charset', method='POST',
headers=[(
'Content-Type', 'application/x-www-form-urlencoded'),
('Content-Length', str(len(body))),
],
body=body),
- self.assertBody(ntob('q: \xc2\xa3'))
+ self.assertBody(b'q: \xc2\xa3')
# An extra charset should error if force is True and it doesn't match.
# Here, we force utf-16 as a charset but still pass a utf-8 body.
- body = ntob('q=\xc2\xa3')
+ body = b'q=\xc2\xa3'
self.getPage('/decode/force_charset', method='POST',
headers=[(
'Content-Type', 'application/x-www-form-urlencoded'),
@@ -256,7 +256,7 @@ class EncodingTests(helper.CPWebCase):
('Content-Length', str(len(body))),
],
body=body),
- self.assertBody(ntob('submit: Create, text: ab\xe2\x80\x9cc'))
+ self.assertBody(b'submit: Create, text: ab\xe2\x80\x9cc')
@mock.patch('cherrypy._cpreqbody.Part.maxrambytes', 1)
def test_multipart_decoding_bigger_maxrambytes(self):
@@ -286,7 +286,7 @@ class EncodingTests(helper.CPWebCase):
('Content-Length', str(len(body))),
],
body=body),
- self.assertBody(ntob('submit: Create, text: \xe2\x80\x9c'))
+ self.assertBody(b'submit: Create, text: \xe2\x80\x9c')
def test_multipart_decoding_no_successful_charset(self):
# Test the decoding of a multipart entity when the charset (utf16) is
@@ -363,7 +363,7 @@ class EncodingTests(helper.CPWebCase):
def testGzip(self):
zbuf = io.BytesIO()
zfile = gzip.GzipFile(mode='wb', fileobj=zbuf, compresslevel=9)
- zfile.write(ntob('Hello, world'))
+ zfile.write(b'Hello, world')
zfile.close()
self.getPage('/gzip/', headers=[('Accept-Encoding', 'gzip')])