diff --git a/pytest_localserver/http.py b/pytest_localserver/http.py index 0a14839..df250a3 100644 --- a/pytest_localserver/http.py +++ b/pytest_localserver/http.py @@ -25,7 +25,7 @@ def __init__(self, host='127.0.0.1', port=0, application=None, **kwargs): self._server = make_server(host, port, self.app, **kwargs) self.server_address = self._server.server_address - super(WSGIServer, self).__init__( + super().__init__( name=self.__class__, target=self._server.serve_forever) @@ -54,7 +54,7 @@ def __bool__(self): def _encode_chunk(chunk, charset): if isinstance(chunk, str): chunk = chunk.encode(charset) - return '{0:x}'.format(len(chunk)).encode(charset) + b'\r\n' + chunk + b'\r\n' + return '{:x}'.format(len(chunk)).encode(charset) + b'\r\n' + chunk + b'\r\n' class ContentServer(WSGIServer): @@ -79,7 +79,7 @@ class ContentServer(WSGIServer): """ def __init__(self, host='127.0.0.1', port=0, ssl_context=None): - super(ContentServer, self).__init__(host, port, self, ssl_context=ssl_context) + super().__init__(host, port, self, ssl_context=ssl_context) self.content, self.code = ('', 204) # HTTP 204: No Content self.headers = {} self.show_post_vars = False diff --git a/pytest_localserver/https.py b/pytest_localserver/https.py index 1c2d6b2..a31cee2 100644 --- a/pytest_localserver/https.py +++ b/pytest_localserver/https.py @@ -120,7 +120,7 @@ def __init__(self, host='localhost', port=0, :param cert: location of file containing server certificate. """ - super(SecureContentServer, self).__init__(host, port, ssl_context=(key, cert)) + super().__init__(host, port, ssl_context=(key, cert)) if __name__ == '__main__': # pragma: no cover diff --git a/pytest_localserver/plugin.py b/pytest_localserver/plugin.py index 7686a90..5577d4c 100644 --- a/pytest_localserver/plugin.py +++ b/pytest_localserver/plugin.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf8 -*- # # Copyright (C) 2011 Sebastian Rahlf # diff --git a/pytest_localserver/smtp.py b/pytest_localserver/smtp.py index 3beb9f5..e5a97a9 100644 --- a/pytest_localserver/smtp.py +++ b/pytest_localserver/smtp.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf8 -*- # # Copyright (C) 2011 Sebastian Rahlf # with some ideas from http://code.activestate.com/recipes/440690/ diff --git a/runtests.py b/runtests.py index 701574f..c5586a1 100644 --- a/runtests.py +++ b/runtests.py @@ -2663,7 +2663,7 @@ import zlib import imp -class DictImporter(object): +class DictImporter: def __init__(self, sources): self.sources = sources @@ -2686,7 +2686,7 @@ def load_module(self, fullname): co = compile(s, fullname, 'exec') module = sys.modules.setdefault(fullname, ModuleType(fullname)) - module.__file__ = "%s/%s" % (__file__, fullname) + module.__file__ = "{}/{}".format(__file__, fullname) module.__loader__ = self if is_pkg: module.__path__ = [fullname] @@ -2701,15 +2701,10 @@ def get_source(self, name): return res if __name__ == "__main__": - if sys.version_info >= (3, 0): - exec("def do_exec(co, loc): exec(co, loc)\n") - import pickle - sources = sources.encode("ascii") # ensure bytes - sources = pickle.loads(zlib.decompress(base64.decodebytes(sources))) - else: - import cPickle as pickle - exec("def do_exec(co, loc): exec co in loc\n") - sources = pickle.loads(zlib.decompress(base64.decodestring(sources))) + exec("def do_exec(co, loc): exec(co, loc)\n") + import pickle + sources = sources.encode("ascii") # ensure bytes + sources = pickle.loads(zlib.decompress(base64.decodebytes(sources))) importer = DictImporter(sources) sys.meta_path.insert(0, importer) diff --git a/tests/test_http.py b/tests/test_http.py index 4bb1018..f9e1bce 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -228,7 +228,7 @@ def _format_chunk(chunk): if len(r) <= 40: return r else: - return r[:13] + '...' + r[-14:] + ' (length {0})'.format(len(chunk)) + return r[:13] + '...' + r[-14:] + ' (length {})'.format(len(chunk)) def _compare_chunks(expected, actual):