diff options
author | Helmut Grohne <helmut@subdivi.de> | 2023-06-17 19:35:21 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2023-06-18 22:44:01 +0200 |
commit | 4d52eaa4801df3f3169df8e58758bcccf22dc4de (patch) | |
tree | b8740a88e380a750d9d2607bb39cbc759a8d7175 /test.py | |
parent | 682ce67b73453809237532a7ce2feee07f2900d5 (diff) | |
download | wsgitools-4d52eaa4801df3f3169df8e58758bcccf22dc4de.tar.gz |
drop support for Python 2.x
Diffstat (limited to 'test.py')
-rwxr-xr-x | test.py | 21 |
1 files changed, 9 insertions, 12 deletions
@@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import base64 import unittest @@ -11,7 +11,7 @@ import sys from wsgitools.internal import bytes2str, str2bytes -class Request(object): +class Request: def __init__(self, case): """ @type case: unittest.TestCase @@ -77,7 +77,7 @@ class Request(object): iterator.close() return res -class Result(object): +class Result: def __init__(self, case): """ @type case: unittest.TestCase @@ -202,7 +202,7 @@ class AuthDigestMiddlewareTest(unittest.TestCase): nonce = nonce.split('"')[1] req = self.req.copy() token = md5(str2bytes("bar:foo:%s" % password)).hexdigest() - other = md5(str2bytes("GET:")).hexdigest() + other = md5(b"GET:").hexdigest() resp = md5(str2bytes("%s:%s:%s" % (token, nonce, other))).hexdigest() req.setheader('Authorization', 'Digest algorithm=md5,nonce="%s",' \ 'uri=,username=bar,response="%s"' % (nonce, resp)) @@ -221,8 +221,8 @@ class AuthDigestMiddlewareTest(unittest.TestCase): res.getheader("WWW-Authenticate").split()))) nonce = nonce.split('"')[1] req = self.req.copy() - token = md5(str2bytes("bar:foo:baz")).hexdigest() - other = md5(str2bytes("GET:")).hexdigest() + token = md5(b"bar:foo:baz").hexdigest() + other = md5(b"GET:").hexdigest() resp = "%s:%s:1:qux:auth:%s" % (token, nonce, other) resp = md5(str2bytes(resp)).hexdigest() req.setheader('Authorization', 'Digest algorithm=md5,nonce="%s",' \ @@ -259,7 +259,7 @@ class NoWriteCallableMiddlewareTest(unittest.TestCase): self.assertEqual(res.writtendata, []) self.assertEqual(b"".join(res.returneddata), b"firstsecond") -class StupidIO(object): +class StupidIO: """file-like without tell method, so StaticFile is not able to determine the content-length.""" def __init__(self, content): @@ -317,7 +317,7 @@ class CachingMiddlewareTest(unittest.TestCase): if "maxage0" in environ["SCRIPT_NAME"]: headers.append(("Cache-Control", "max-age=0")) start_response("200 Found", headers) - return [str2bytes("%d" % count)] + return [b"%d" % count] def testCache(self): res = Request(self)(self.cached) @@ -385,10 +385,7 @@ class RequestLogWSGIFilterTest(unittest.TestCase): def testSimple(self): app = applications.StaticContent("200 Found", [("Content-Type", "text/plain")], b"nothing") - if isinstance("x", bytes): - log = io.BytesIO() - else: - log = io.StringIO() + log = io.StringIO() logfilter = filters.RequestLogWSGIFilter.creator(log) app = filters.WSGIFilterMiddleware(app, logfilter) req = Request(self) |