Skip to content

Commit a1a4601

Browse files
authored
Merge pull request #36 from hramezani/update_syntax
Update syntax to Python 3
2 parents 87fd2cb + 4fcba96 commit a1a4601

File tree

6 files changed

+11
-18
lines changed

6 files changed

+11
-18
lines changed

pytest_localserver/http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, host='127.0.0.1', port=0, application=None, **kwargs):
2525
self._server = make_server(host, port, self.app, **kwargs)
2626
self.server_address = self._server.server_address
2727

28-
super(WSGIServer, self).__init__(
28+
super().__init__(
2929
name=self.__class__,
3030
target=self._server.serve_forever)
3131

@@ -54,7 +54,7 @@ def __bool__(self):
5454
def _encode_chunk(chunk, charset):
5555
if isinstance(chunk, str):
5656
chunk = chunk.encode(charset)
57-
return '{0:x}'.format(len(chunk)).encode(charset) + b'\r\n' + chunk + b'\r\n'
57+
return '{:x}'.format(len(chunk)).encode(charset) + b'\r\n' + chunk + b'\r\n'
5858

5959

6060
class ContentServer(WSGIServer):
@@ -79,7 +79,7 @@ class ContentServer(WSGIServer):
7979
"""
8080

8181
def __init__(self, host='127.0.0.1', port=0, ssl_context=None):
82-
super(ContentServer, self).__init__(host, port, self, ssl_context=ssl_context)
82+
super().__init__(host, port, self, ssl_context=ssl_context)
8383
self.content, self.code = ('', 204) # HTTP 204: No Content
8484
self.headers = {}
8585
self.show_post_vars = False

pytest_localserver/https.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __init__(self, host='localhost', port=0,
120120
:param cert: location of file containing server certificate.
121121
"""
122122

123-
super(SecureContentServer, self).__init__(host, port, ssl_context=(key, cert))
123+
super().__init__(host, port, ssl_context=(key, cert))
124124

125125

126126
if __name__ == '__main__': # pragma: no cover

pytest_localserver/plugin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf8 -*-
32
#
43
# Copyright (C) 2011 Sebastian Rahlf <basti at redtoad dot de>
54
#

pytest_localserver/smtp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf8 -*-
32
#
43
# Copyright (C) 2011 Sebastian Rahlf <basti at redtoad dot de>
54
# with some ideas from http://code.activestate.com/recipes/440690/

runtests.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,7 @@
26632663
import zlib
26642664
import imp
26652665

2666-
class DictImporter(object):
2666+
class DictImporter:
26672667
def __init__(self, sources):
26682668
self.sources = sources
26692669

@@ -2686,7 +2686,7 @@ def load_module(self, fullname):
26862686

26872687
co = compile(s, fullname, 'exec')
26882688
module = sys.modules.setdefault(fullname, ModuleType(fullname))
2689-
module.__file__ = "%s/%s" % (__file__, fullname)
2689+
module.__file__ = "{}/{}".format(__file__, fullname)
26902690
module.__loader__ = self
26912691
if is_pkg:
26922692
module.__path__ = [fullname]
@@ -2701,15 +2701,10 @@ def get_source(self, name):
27012701
return res
27022702

27032703
if __name__ == "__main__":
2704-
if sys.version_info >= (3, 0):
2705-
exec("def do_exec(co, loc): exec(co, loc)\n")
2706-
import pickle
2707-
sources = sources.encode("ascii") # ensure bytes
2708-
sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)))
2709-
else:
2710-
import cPickle as pickle
2711-
exec("def do_exec(co, loc): exec co in loc\n")
2712-
sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
2704+
exec("def do_exec(co, loc): exec(co, loc)\n")
2705+
import pickle
2706+
sources = sources.encode("ascii") # ensure bytes
2707+
sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)))
27132708

27142709
importer = DictImporter(sources)
27152710
sys.meta_path.insert(0, importer)

tests/test_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def _format_chunk(chunk):
228228
if len(r) <= 40:
229229
return r
230230
else:
231-
return r[:13] + '...' + r[-14:] + ' (length {0})'.format(len(chunk))
231+
return r[:13] + '...' + r[-14:] + ' (length {})'.format(len(chunk))
232232

233233

234234
def _compare_chunks(expected, actual):

0 commit comments

Comments
 (0)