Skip to content

Update syntax to Python 3 #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pytest_localserver/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pytest_localserver/https.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pytest_localserver/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf8 -*-
#
# Copyright (C) 2011 Sebastian Rahlf <basti at redtoad dot de>
#
Expand Down
1 change: 0 additions & 1 deletion pytest_localserver/smtp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf8 -*-
#
# Copyright (C) 2011 Sebastian Rahlf <basti at redtoad dot de>
# with some ideas from http://code.activestate.com/recipes/440690/
Expand Down
17 changes: 6 additions & 11 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2663,7 +2663,7 @@
import zlib
import imp

class DictImporter(object):
class DictImporter:
def __init__(self, sources):
self.sources = sources

Expand All @@ -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]
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down