summaryrefslogtreecommitdiff
path: root/cherrypy/test
diff options
context:
space:
mode:
Diffstat (limited to 'cherrypy/test')
-rw-r--r--cherrypy/test/_test_decorators.py3
-rw-r--r--cherrypy/test/benchmark.py11
-rw-r--r--cherrypy/test/helper.py2
-rw-r--r--cherrypy/test/logtest.py2
-rw-r--r--cherrypy/test/test_auth_basic.py2
-rw-r--r--cherrypy/test/test_caching.py13
-rw-r--r--cherrypy/test/test_config.py3
-rw-r--r--cherrypy/test/test_conn.py34
-rw-r--r--cherrypy/test/test_core.py8
-rw-r--r--cherrypy/test/test_encoding.py32
-rw-r--r--cherrypy/test/test_http.py14
-rw-r--r--cherrypy/test/test_httpauth.py4
-rw-r--r--cherrypy/test/test_logging.py4
-rw-r--r--cherrypy/test/test_mime.py44
-rw-r--r--cherrypy/test/test_request_obj.py14
-rw-r--r--cherrypy/test/test_tools.py14
-rw-r--r--cherrypy/test/test_wsgi_ns.py5
-rw-r--r--cherrypy/test/test_wsgiapps.py2
18 files changed, 103 insertions, 108 deletions
diff --git a/cherrypy/test/_test_decorators.py b/cherrypy/test/_test_decorators.py
index f6b3e1b1..74832e40 100644
--- a/cherrypy/test/_test_decorators.py
+++ b/cherrypy/test/_test_decorators.py
@@ -2,7 +2,6 @@
import cherrypy
from cherrypy import expose, tools
-from cherrypy._cpcompat import ntob
class ExposeExamples(object):
@@ -37,4 +36,4 @@ class ToolExamples(object):
@cherrypy.config(**{'response.stream': True})
@tools.response_headers(headers=[('Content-Type', 'application/data')])
def blah(self):
- yield ntob('blah')
+ yield b'blah'
diff --git a/cherrypy/test/benchmark.py b/cherrypy/test/benchmark.py
index 5bfcf699..b57c1945 100644
--- a/cherrypy/test/benchmark.py
+++ b/cherrypy/test/benchmark.py
@@ -28,7 +28,6 @@ import sys
import time
import cherrypy
-from cherrypy._cpcompat import ntob
from cherrypy import _cperror, _cpmodpy
from cherrypy.lib import httputil
@@ -191,15 +190,15 @@ Finished 1000 requests
parse_patterns = [
('complete_requests', 'Completed',
- ntob(r'^Complete requests:\s*(\d+)')),
+ br'^Complete requests:\s*(\d+)'),
('failed_requests', 'Failed',
- ntob(r'^Failed requests:\s*(\d+)')),
+ br'^Failed requests:\s*(\d+)'),
('requests_per_second', 'req/sec',
- ntob(r'^Requests per second:\s*([0-9.]+)')),
+ br'^Requests per second:\s*([0-9.]+)'),
('time_per_request_concurrent', 'msec/req',
- ntob(r'^Time per request:\s*([0-9.]+).*concurrent requests\)$')),
+ br'^Time per request:\s*([0-9.]+).*concurrent requests\)$'),
('transfer_rate', 'KB/sec',
- ntob(r'^Transfer rate:\s*([0-9.]+)'))
+ br'^Transfer rate:\s*([0-9.]+)')
]
def __init__(self, path=SCRIPT_NAME + '/hello', requests=1000,
diff --git a/cherrypy/test/helper.py b/cherrypy/test/helper.py
index bdf74f86..01c5a0c0 100644
--- a/cherrypy/test/helper.py
+++ b/cherrypy/test/helper.py
@@ -344,7 +344,7 @@ class CPWebCase(webtest.WebCase):
epage = re.escape(page)
epage = epage.replace(
esc('<pre id="traceback"></pre>'),
- esc('<pre id="traceback">') + ntob('(.*)') + esc('</pre>'))
+ esc('<pre id="traceback">') + b'(.*)' + esc('</pre>'))
m = re.match(epage, self.body, re.DOTALL)
if not m:
self._handlewebError(
diff --git a/cherrypy/test/logtest.py b/cherrypy/test/logtest.py
index b51a0e32..ed8f1540 100644
--- a/cherrypy/test/logtest.py
+++ b/cherrypy/test/logtest.py
@@ -47,7 +47,7 @@ class LogCase(object):
logfile = None
lastmarker = None
- markerPrefix = ntob('test suite marker: ')
+ markerPrefix = b'test suite marker: '
def _handleLogError(self, msg, data, marker, pattern):
print('')
diff --git a/cherrypy/test/test_auth_basic.py b/cherrypy/test/test_auth_basic.py
index 48582ec2..cb3b344f 100644
--- a/cherrypy/test/test_auth_basic.py
+++ b/cherrypy/test/test_auth_basic.py
@@ -35,7 +35,7 @@ class BasicAuthTest(helper.CPWebCase):
cherrypy.request.login)
userpassdict = {'xuser': 'xpassword'}
- userhashdict = {'xuser': md5(ntob('xpassword')).hexdigest()}
+ userhashdict = {'xuser': md5(b'xpassword').hexdigest()}
def checkpasshash(realm, user, password):
p = userhashdict.get(user)
diff --git a/cherrypy/test/test_caching.py b/cherrypy/test/test_caching.py
index 4a459a3f..1a6ed4f2 100644
--- a/cherrypy/test/test_caching.py
+++ b/cherrypy/test/test_caching.py
@@ -10,7 +10,6 @@ from six.moves import urllib
import pytest
import cherrypy
-from cherrypy._cpcompat import ntob
from cherrypy.lib import httputil
from cherrypy.test import helper
@@ -18,10 +17,10 @@ from cherrypy.test import helper
curdir = os.path.join(os.getcwd(), os.path.dirname(__file__))
-gif_bytes = ntob(
- 'GIF89a\x01\x00\x01\x00\x82\x00\x01\x99"\x1e\x00\x00\x00\x00\x00'
- '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
- '\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x02\x03\x02\x08\t\x00;'
+gif_bytes = (
+ b'GIF89a\x01\x00\x01\x00\x82\x00\x01\x99"\x1e\x00\x00\x00\x00\x00'
+ b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+ b'\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x02\x03\x02\x08\t\x00;'
)
@@ -179,7 +178,7 @@ class CacheTest(helper.CPWebCase):
self.assertHeader('Content-Encoding', 'gzip')
self.assertHeader('Vary')
self.assertEqual(
- cherrypy.lib.encoding.decompress(self.body), ntob('visit #5'))
+ cherrypy.lib.encoding.decompress(self.body), b'visit #5')
# Now check that a second request gets the gzip header and gzipped body
# This also tests a bug in 3.0 to 3.0.2 whereby the cached, gzipped
@@ -187,7 +186,7 @@ class CacheTest(helper.CPWebCase):
self.getPage('/', method='GET', headers=[('Accept-Encoding', 'gzip')])
self.assertHeader('Content-Encoding', 'gzip')
self.assertEqual(
- cherrypy.lib.encoding.decompress(self.body), ntob('visit #5'))
+ cherrypy.lib.encoding.decompress(self.body), b'visit #5')
# Now check that a third request that doesn't accept gzip
# skips the cache (because the 'Vary' header denies it).
diff --git a/cherrypy/test/test_config.py b/cherrypy/test/test_config.py
index 70fe535b..be17df90 100644
--- a/cherrypy/test/test_config.py
+++ b/cherrypy/test/test_config.py
@@ -8,7 +8,6 @@ import unittest
import six
import cherrypy
-import cherrypy._cpcompat as compat
from cherrypy.test import helper
@@ -241,7 +240,7 @@ class ConfigTests(helper.CPWebCase):
self.getPage('/plain', method='POST', headers=[
('Content-Type', 'application/x-www-form-urlencoded'),
('Content-Length', '13')],
- body=compat.ntob('\xff\xfex\x00=\xff\xfea\x00b\x00c\x00'))
+ body=b'\xff\xfex\x00=\xff\xfea\x00b\x00c\x00')
self.assertBody('abc')
diff --git a/cherrypy/test/test_conn.py b/cherrypy/test/test_conn.py
index 06676286..7d60c6fb 100644
--- a/cherrypy/test/test_conn.py
+++ b/cherrypy/test/test_conn.py
@@ -304,7 +304,7 @@ class PipelineTests(helper.CPWebCase):
conn = self.HTTP_CONN
conn.auto_open = False
conn.connect()
- conn.send(ntob('GET /hello HTTP/1.1'))
+ conn.send(b'GET /hello HTTP/1.1')
conn.send(('Host: %s' % self.HOST).encode('ascii'))
# Wait for our socket timeout
@@ -337,7 +337,7 @@ class PipelineTests(helper.CPWebCase):
self.assertBody(str(timeout))
# Make a second request on the same socket
- conn._output(ntob('GET /hello HTTP/1.1'))
+ conn._output(b'GET /hello HTTP/1.1')
conn._output(ntob('Host: %s' % self.HOST, 'ascii'))
conn._send_output()
response = conn.response_class(conn.sock, method='GET')
@@ -350,7 +350,7 @@ class PipelineTests(helper.CPWebCase):
time.sleep(timeout * 2)
# Make another request on the same socket, which should error
- conn._output(ntob('GET /hello HTTP/1.1'))
+ conn._output(b'GET /hello HTTP/1.1')
conn._output(ntob('Host: %s' % self.HOST, 'ascii'))
conn._send_output()
response = conn.response_class(conn.sock, method='GET')
@@ -383,7 +383,7 @@ class PipelineTests(helper.CPWebCase):
# Make another request on the same socket,
# but timeout on the headers
- conn.send(ntob('GET /hello HTTP/1.1'))
+ conn.send(b'GET /hello HTTP/1.1')
# Wait for our socket timeout
time.sleep(timeout * 2)
response = conn.response_class(conn.sock, method='GET')
@@ -431,7 +431,7 @@ class PipelineTests(helper.CPWebCase):
for trial in range(5):
# Put next request
- conn._output(ntob('GET /hello HTTP/1.1'))
+ conn._output(b'GET /hello HTTP/1.1')
conn._output(ntob('Host: %s' % self.HOST, 'ascii'))
conn._send_output()
@@ -446,14 +446,14 @@ class PipelineTests(helper.CPWebCase):
response.begin()
body = response.read(13)
self.assertEqual(response.status, 200)
- self.assertEqual(body, ntob('Hello, world!'))
+ self.assertEqual(body, b'Hello, world!')
# Retrieve final response
response = conn.response_class(conn.sock, method='GET')
response.begin()
body = response.read()
self.assertEqual(response.status, 200)
- self.assertEqual(body, ntob('Hello, world!'))
+ self.assertEqual(body, b'Hello, world!')
conn.close()
@@ -506,7 +506,7 @@ class PipelineTests(helper.CPWebCase):
break
# ...send the body
- body = ntob('I am a small file')
+ body = b'I am a small file'
conn.send(body)
# ...get the final response
@@ -566,11 +566,11 @@ class ConnectionTests(helper.CPWebCase):
self.assertStatus(500)
# Now try a working page with an Expect header...
- conn._output(ntob('POST /upload HTTP/1.1'))
+ conn._output(b'POST /upload HTTP/1.1')
conn._output(ntob('Host: %s' % self.HOST, 'ascii'))
- conn._output(ntob('Content-Type: text/plain'))
- conn._output(ntob('Content-Length: 17'))
- conn._output(ntob('Expect: 100-continue'))
+ conn._output(b'Content-Type: text/plain')
+ conn._output(b'Content-Length: 17')
+ conn._output(b'Expect: 100-continue')
conn._send_output()
response = conn.response_class(conn.sock, method='POST')
@@ -583,7 +583,7 @@ class ConnectionTests(helper.CPWebCase):
break
# ...send the body
- body = ntob('I am a small file')
+ body = b'I am a small file'
conn.send(body)
# ...get the final response
@@ -654,7 +654,7 @@ class ConnectionTests(helper.CPWebCase):
response = conn.getresponse()
self.status, self.headers, self.body = webtest.shb(response)
self.assertStatus('200 OK')
- self.assertBody("thanks for '%s'" % ntob('xx\r\nxxxxyyyyy'))
+ self.assertBody("thanks for '%s'" % b'xx\r\nxxxxyyyyy')
# Try a chunked request that exceeds server.max_request_body_size.
# Note that the delimiters and trailer are included.
@@ -839,7 +839,7 @@ class LimitedRequestQueueTests(helper.CPWebCase):
raise AssertionError('Overflow conn did not get RST ')
finally:
for conn in conns:
- conn.send(ntob('done'))
+ conn.send(b'done')
response = conn.response_class(conn.sock, method='POST')
response.begin()
self.body = response.read()
@@ -857,7 +857,7 @@ class BadRequestTests(helper.CPWebCase):
self.persistent = True
conn = self.HTTP_CONN
- conn.send(ntob('GET /hello HTTP/1.1\n\n'))
+ conn.send(b'GET /hello HTTP/1.1\n\n')
response = conn.response_class(conn.sock, method='GET')
response.begin()
self.body = response.read()
@@ -865,7 +865,7 @@ class BadRequestTests(helper.CPWebCase):
conn.close()
conn.connect()
- conn.send(ntob('GET /hello HTTP/1.1\r\n\n'))
+ conn.send(b'GET /hello HTTP/1.1\r\n\n')
response = conn.response_class(conn.sock, method='GET')
response.begin()
self.body = response.read()
diff --git a/cherrypy/test/test_core.py b/cherrypy/test/test_core.py
index ef5f5016..9834c1f3 100644
--- a/cherrypy/test/test_core.py
+++ b/cherrypy/test/test_core.py
@@ -9,7 +9,7 @@ import types
import six
import cherrypy
-from cherrypy._cpcompat import ntob, ntou
+from cherrypy._cpcompat import ntou
from cherrypy import _cptools, tools
from cherrypy.lib import httputil, static
@@ -235,7 +235,7 @@ class CoreRequestHandlingTest(helper.CPWebCase):
return ['con', 'tent']
def as_yield(self):
- yield ntob('content')
+ yield b'content'
@cherrypy.config(**{'tools.flatten.on': True})
def as_dblyield(self):
@@ -279,8 +279,8 @@ class CoreRequestHandlingTest(helper.CPWebCase):
def header_list(self):
pass
header_list = cherrypy.tools.append_headers(header_list=[
- (ntob('WWW-Authenticate'), ntob('Negotiate')),
- (ntob('WWW-Authenticate'), ntob('Basic realm="foo"')),
+ (b'WWW-Authenticate', b'Negotiate'),
+ (b'WWW-Authenticate', b'Basic realm="foo"'),
])(header_list)
def commas(self):
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')])
diff --git a/cherrypy/test/test_http.py b/cherrypy/test/test_http.py
index 1481492c..cbf10bb8 100644
--- a/cherrypy/test/test_http.py
+++ b/cherrypy/test/test_http.py
@@ -11,7 +11,7 @@ from six.moves.http_client import HTTPConnection
from six.moves import urllib
import cherrypy
-from cherrypy._cpcompat import HTTPSConnection, ntob
+from cherrypy._cpcompat import HTTPSConnection
from cherrypy.test import helper
@@ -106,7 +106,7 @@ class HTTPTests(helper.CPWebCase):
self.body = response.fp.read()
self.status = str(response.status)
self.assertStatus(200)
- self.assertBody(ntob('Hello world!'))
+ self.assertBody(b'Hello world!')
# Now send a message that has no Content-Length, but does send a body.
# Verify that CP times out the socket and responds
@@ -189,7 +189,7 @@ class HTTPTests(helper.CPWebCase):
# Test missing version in Request-Line
c = self.make_connection()
- c._output(ntob('GET /'))
+ c._output(b'geT /')
c._send_output()
if hasattr(c, 'strict'):
response = c.response_class(c.sock, strict=c.strict, method='GET')
@@ -199,7 +199,7 @@ class HTTPTests(helper.CPWebCase):
response = c.response_class(c.sock, method='GET')
response.begin()
self.assertEqual(response.status, 400)
- self.assertEqual(response.fp.read(22), ntob('Malformed Request-Line'))
+ self.assertEqual(response.fp.read(22), b'Malformed Request-Line')
c.close()
def test_request_line_split_issue_1220(self):
@@ -221,7 +221,7 @@ class HTTPTests(helper.CPWebCase):
c.putrequest('GET', '/')
c.putheader('Content-Type', 'text/plain')
# See https://github.com/cherrypy/cherrypy/issues/941
- c._output(ntob('Re, 1.2.3.4#015#012'))
+ c._output(b're, 1.2.3.4#015#012')
c.endheaders()
response = c.getresponse()
@@ -255,14 +255,14 @@ class HTTPTests(helper.CPWebCase):
def test_garbage_in(self):
# Connect without SSL regardless of server.scheme
c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
- c._output(ntob('gjkgjklsgjklsgjkljklsg'))
+ c._output(b'gjkgjklsgjklsgjkljklsg')
c._send_output()
response = c.response_class(c.sock, method='GET')
try:
response.begin()
self.assertEqual(response.status, 400)
self.assertEqual(response.fp.read(22),
- ntob('Malformed Request-Line'))
+ b'Malformed Request-Line')
c.close()
except socket.error:
e = sys.exc_info()[1]
diff --git a/cherrypy/test/test_httpauth.py b/cherrypy/test/test_httpauth.py
index 3a5cff27..eed3666c 100644
--- a/cherrypy/test/test_httpauth.py
+++ b/cherrypy/test/test_httpauth.py
@@ -45,7 +45,7 @@ class HTTPAuthTest(helper.CPWebCase):
return sha1(ntob(password)).hexdigest()
def fetch_password(username):
- return sha1(ntob('test')).hexdigest()
+ return sha1(b'test').hexdigest()
conf = {
'/digest': {
@@ -57,7 +57,7 @@ class HTTPAuthTest(helper.CPWebCase):
'tools.basic_auth.on': True,
'tools.basic_auth.realm': 'localhost',
'tools.basic_auth.users': {
- 'test': md5(ntob('test')).hexdigest()
+ 'test': md5(b'test').hexdigest()
}
},
'/basic2': {
diff --git a/cherrypy/test/test_logging.py b/cherrypy/test/test_logging.py
index 4d686775..c4948c20 100644
--- a/cherrypy/test/test_logging.py
+++ b/cherrypy/test/test_logging.py
@@ -6,7 +6,7 @@ from unittest import mock
import six
import cherrypy
-from cherrypy._cpcompat import ntob, ntou
+from cherrypy._cpcompat import ntou
from cherrypy.test import helper, logtest
localDir = os.path.dirname(__file__)
@@ -177,7 +177,7 @@ class AccessLogTests(helper.CPWebCase, logtest.LogCase):
self.getPage('/slashes')
self.assertStatus(200)
if six.PY3:
- self.assertLog(-1, ntob('"GET /slashed\\path HTTP/1.1"'))
+ self.assertLog(-1, b'"GET /slashed\\path HTTP/1.1"')
else:
self.assertLog(-1, r'"GET /slashed\\path HTTP/1.1"')
diff --git a/cherrypy/test/test_mime.py b/cherrypy/test/test_mime.py
index 6f5987c1..ef35d10e 100644
--- a/cherrypy/test/test_mime.py
+++ b/cherrypy/test/test_mime.py
@@ -1,7 +1,7 @@
"""Tests for various MIME issues, including the safe_multipart Tool."""
import cherrypy
-from cherrypy._cpcompat import ntob, ntou
+from cherrypy._cpcompat import ntou
from cherrypy.test import helper
@@ -107,28 +107,28 @@ class SafeMultipartHandlingTest(helper.CPWebCase):
('Connection', 'Keep-Alive'),
('Cache-Control', 'no-cache'),
]
- filedata = ntob('<?xml version="1.0" encoding="UTF-8"?>\r\n'
- '<projectDescription>\r\n'
- '</projectDescription>\r\n')
- body = (ntob(
- '------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6\r\n'
- 'Content-Disposition: form-data; name="Filename"\r\n'
- '\r\n'
- '.project\r\n'
- '------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6\r\n'
- 'Content-Disposition: form-data; '
- 'name="Filedata"; filename=".project"\r\n'
- 'Content-Type: application/octet-stream\r\n'
- '\r\n') +
+ filedata = (b'<?xml version="1.0" encoding="UTF-8"?>\r\n'
+ b'<projectDescription>\r\n'
+ b'</projectDescription>\r\n')
+ body = (
+ b'------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6\r\n'
+ b'Content-Disposition: form-data; name="Filename"\r\n'
+ b'\r\n'
+ b'.project\r\n'
+ b'------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6\r\n'
+ b'Content-Disposition: form-data; '
+ b'name="Filedata"; filename=".project"\r\n'
+ b'Content-Type: application/octet-stream\r\n'
+ b'\r\n' +
filedata +
- ntob('\r\n'
- '------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6\r\n'
- 'Content-Disposition: form-data; name="Upload"\r\n'
- '\r\n'
- 'Submit Query\r\n'
- # Flash apps omit the trailing \r\n on the last line:
- '------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6--'
- ))
+ b'\r\n'
+ b'------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6\r\n'
+ b'Content-Disposition: form-data; name="Upload"\r\n'
+ b'\r\n'
+ b'Submit Query\r\n'
+ # Flash apps omit the trailing \r\n on the last line:
+ b'------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6--'
+ )
self.getPage('/flashupload', headers, 'POST', body)
self.assertBody('Upload: Submit Query, Filename: .project, '
'Filedata: %r' % filedata)
diff --git a/cherrypy/test/test_request_obj.py b/cherrypy/test/test_request_obj.py
index 232440c9..6b93e13d 100644
--- a/cherrypy/test/test_request_obj.py
+++ b/cherrypy/test/test_request_obj.py
@@ -10,7 +10,7 @@ import six
from six.moves.http_client import IncompleteRead
import cherrypy
-from cherrypy._cpcompat import ntob, ntou
+from cherrypy._cpcompat import ntou
from cherrypy.lib import httputil
from cherrypy.test import helper
@@ -728,14 +728,14 @@ class RequestObjectTests(helper.CPWebCase):
self.getPage('/headers/ifmatch',
[('If-Match', ntou('=?utf-8?q?%s?=') % c)])
# The body should be utf-8 encoded.
- self.assertBody(ntob('\xe2\x84\xabngstr\xc3\xb6m'))
+ self.assertBody(b'\xe2\x84\xabngstr\xc3\xb6m')
# But the Etag header should be RFC-2047 encoded (binary)
self.assertHeader('ETag', ntou('=?utf-8?b?4oSrbmdzdHLDtm0=?='))
# Test a *LONG* RFC-2047-encoded request and response header value
self.getPage('/headers/ifmatch',
[('If-Match', ntou('=?utf-8?q?%s?=') % (c * 10))])
- self.assertBody(ntob('\xe2\x84\xabngstr\xc3\xb6m') * 10)
+ self.assertBody(b'\xe2\x84\xabngstr\xc3\xb6m' * 10)
# Note: this is different output for Python3, but it decodes fine.
etag = self.assertHeader(
'ETag',
@@ -771,7 +771,7 @@ class RequestObjectTests(helper.CPWebCase):
self.assertBody('')
elif m == 'TRACE':
# Some HTTP servers (like modpy) have their own TRACE support
- self.assertEqual(self.body[:5], ntob('TRACE'))
+ self.assertEqual(self.body[:5], b'TRACE')
else:
self.assertBody(m)
@@ -791,7 +791,7 @@ class RequestObjectTests(helper.CPWebCase):
# Request a PATCH method with a file body but no Content-Type.
# See https://github.com/cherrypy/cherrypy/issues/790.
- b = ntob('one thing on top of another')
+ b = b'one thing on top of another'
self.persistent = True
try:
conn = self.HTTP_CONN
@@ -831,7 +831,7 @@ class RequestObjectTests(helper.CPWebCase):
# Request a PUT method with a file body but no Content-Type.
# See https://github.com/cherrypy/cherrypy/issues/790.
- b = ntob('one thing on top of another')
+ b = b'one thing on top of another'
self.persistent = True
try:
conn = self.HTTP_CONN
@@ -929,4 +929,4 @@ class RequestObjectTests(helper.CPWebCase):
for x in range(20):
self.getPage('/threadlocal/')
results.append(self.body)
- self.assertEqual(results, [ntob('None')] * 20)
+ self.assertEqual(results, [b'None'] * 20)
diff --git a/cherrypy/test/test_tools.py b/cherrypy/test/test_tools.py
index 4e7b83f1..a73a3898 100644
--- a/cherrypy/test/test_tools.py
+++ b/cherrypy/test/test_tools.py
@@ -14,7 +14,7 @@ from six.moves.http_client import IncompleteRead
import cherrypy
from cherrypy import tools
-from cherrypy._cpcompat import ntob, ntou
+from cherrypy._cpcompat import ntou
from cherrypy.test import helper, _test_decorators
@@ -75,15 +75,15 @@ class ToolTests(helper.CPWebCase):
def nadsat(self):
def nadsat_it_up(body):
for chunk in body:
- chunk = chunk.replace(ntob('good'), ntob('horrorshow'))
- chunk = chunk.replace(ntob('piece'), ntob('lomtick'))
+ chunk = chunk.replace(b'good', b'horrorshow')
+ chunk = chunk.replace(b'piece', b'lomtick')
yield chunk
cherrypy.response.body = nadsat_it_up(cherrypy.response.body)
nadsat.priority = 0
def cleanup(self):
# This runs after the request has been completely written out.
- cherrypy.response.body = [ntob('razdrez')]
+ cherrypy.response.body = [b'razdrez']
id = cherrypy.request.params.get('id')
if id:
self.ended[id] = True
@@ -139,8 +139,8 @@ class ToolTests(helper.CPWebCase):
def tarfile(self):
actual = cherrypy.request.config.get('tools.streamer.arg')
assert actual == 'arg value'
- cherrypy.response.output.write(ntob('I am '))
- cherrypy.response.output.write(ntob('a tarfile'))
+ cherrypy.response.output.write(b'I am ')
+ cherrypy.response.output.write(b'a tarfile')
@cherrypy.expose
def euro(self):
@@ -226,7 +226,7 @@ class ToolTests(helper.CPWebCase):
# Declare Tools in detached config
'/demo': {
'tools.numerify.on': True,
- 'tools.numerify.map': {ntob('pie'): ntob('3.14159')},
+ 'tools.numerify.map': {b'pie': b'3.14159'},
},
'/demo/restricted': {
'request.show_tracebacks': False,
diff --git a/cherrypy/test/test_wsgi_ns.py b/cherrypy/test/test_wsgi_ns.py
index 2a5fedd4..3545724c 100644
--- a/cherrypy/test/test_wsgi_ns.py
+++ b/cherrypy/test/test_wsgi_ns.py
@@ -1,5 +1,4 @@
import cherrypy
-from cherrypy._cpcompat import ntob
from cherrypy.test import helper
@@ -76,8 +75,8 @@ class WSGI_Namespace_Test(helper.CPWebCase):
return 'HellO WoRlD!'
root_conf = {'wsgi.pipeline': [('replace', Replacer)],
- 'wsgi.replace.map': {ntob('L'): ntob('X'),
- ntob('l'): ntob('r')},
+ 'wsgi.replace.map': {b'L': b'X',
+ b'l': b'r'},
}
app = cherrypy.Application(Root())
diff --git a/cherrypy/test/test_wsgiapps.py b/cherrypy/test/test_wsgiapps.py
index fa7f25f7..1b3bf28f 100644
--- a/cherrypy/test/test_wsgiapps.py
+++ b/cherrypy/test/test_wsgiapps.py
@@ -27,7 +27,7 @@ class WSGIGraftTests(helper.CPWebCase):
response_headers = [('Content-type', 'text/plain')]
start_response(status, response_headers)
return [
- ntob('Hello'), ntob(''), ntob(' '), ntob(''), ntob('world')
+ b'Hello', b'', b' ', b'', b'world',
]
class WSGIResponse(object):