Skip to content

Commit

Permalink
pyupgrade 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalresistor committed May 25, 2022
1 parent 7c3739b commit 8f5b473
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/waitress/adjustments.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Adjustments:
# TCP port to listen on
port = _int_marker(8080)

listen = ["{}:{}".format(host, port)]
listen = [f"{host}:{port}"]

# number of threads available for tasks
threads = 4
Expand Down Expand Up @@ -322,7 +322,7 @@ def __init__(self, **kw):
if not isinstance(self.host, _str_marker) or not isinstance(
self.port, _int_marker
):
self.listen = ["{}:{}".format(self.host, self.port)]
self.listen = [f"{self.host}:{self.port}"]

enabled_families = socket.AF_UNSPEC

Expand Down
4 changes: 2 additions & 2 deletions src/waitress/proxy_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def translate_proxy_headers(environ, start_response):
ex.reason,
ex.value,
)
error = BadRequest('Header "{}" malformed.'.format(ex.header))
error = BadRequest(f'Header "{ex.header}" malformed.')
return error.wsgi_response(environ, start_response)

# Clear out the untrusted proxy headers
Expand Down Expand Up @@ -95,7 +95,7 @@ def raise_for_multiple_values():
if "." not in forward_hop and (
":" in forward_hop and forward_hop[-1] != "]"
):
forwarded_for.append("[{}]".format(forward_hop))
forwarded_for.append(f"[{forward_hop}]")
else:
forwarded_for.append(forward_hop)

Expand Down
10 changes: 5 additions & 5 deletions src/waitress/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
def match(obj_name):
matches = RUNNER_PATTERN.match(obj_name)
if not matches:
raise ValueError("Malformed application '{}'".format(obj_name))
raise ValueError(f"Malformed application '{obj_name}'")
return matches.group("module"), matches.group("object")


Expand All @@ -223,7 +223,7 @@ def resolve(module_name, object_name):

def show_help(stream, name, error=None): # pragma: no cover
if error is not None:
print("Error: {}\n".format(error), file=stream)
print(f"Error: {error}\n", file=stream)
print(HELP.format(name), file=stream)


Expand All @@ -239,7 +239,7 @@ def show_exception(stream):
if args:
print("It had these arguments: ", file=stream)
for idx, arg in enumerate(args, start=1):
print("{}. {}\n".format(idx, arg), file=stream)
print(f"{idx}. {arg}\n", file=stream)
else:
print("It had no arguments.", file=stream)

Expand Down Expand Up @@ -282,11 +282,11 @@ def run(argv=sys.argv, _serve=serve):
try:
app = resolve(module, obj_name)
except ImportError:
show_help(sys.stderr, name, "Bad module '{}'".format(module))
show_help(sys.stderr, name, f"Bad module '{module}'")
show_exception(sys.stderr)
return 1
except AttributeError:
show_help(sys.stderr, name, "Bad object name '{}'".format(obj_name))
show_help(sys.stderr, name, f"Bad object name '{obj_name}'")
show_exception(sys.stderr)
return 1
if kw["call"]:
Expand Down
2 changes: 1 addition & 1 deletion src/waitress/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def print_listen(self, format_str): # pragma: nocover
l = list(l)

if ":" in l[0]:
l[0] = "[{}]".format(l[0])
l[0] = f"[{l[0]}]"

self.log_info(format_str.format(*l))

Expand Down
8 changes: 4 additions & 4 deletions src/waitress/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self):

def start_new_thread(self, target, thread_no):
t = threading.Thread(
target=target, name="waitress-{}".format(thread_no), args=(thread_no,)
target=target, name=f"waitress-{thread_no}", args=(thread_no,)
)
t.daemon = True
t.start()
Expand Down Expand Up @@ -266,7 +266,7 @@ def close_on_finish():

self.response_headers = response_headers

first_line = "HTTP/%s %s" % (self.version, self.status)
first_line = f"HTTP/{self.version} {self.status}"
# NB: sorting headers needs to preserve same-named-header order
# as per RFC 2616 section 4.2; thus the key=lambda x: x[0] here;
# rely on stable sort to keep relative position of same-named headers
Expand Down Expand Up @@ -400,11 +400,11 @@ def start_response(status, headers, exc_info=None):
for k, v in headers:
if not k.__class__ is str:
raise AssertionError(
"Header name %r is not a string in %r" % (k, (k, v))
f"Header name {k!r} is not a string in {(k, v)!r}"
)
if not v.__class__ is str:
raise AssertionError(
"Header value %r is not a string in %r" % (v, (k, v))
f"Header value {v!r} is not a string in {(k, v)!r}"
)

if "\n" in v or "\r" in v:
Expand Down
4 changes: 1 addition & 3 deletions src/waitress/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def handle_read(self):
thunk()
except:
nil, t, v, tbinfo = wasyncore.compact_traceback()
self.log_info(
"exception in trigger thunk: (%s:%s %s)" % (t, v, tbinfo)
)
self.log_info(f"exception in trigger thunk: ({t}:{v} {tbinfo})")
self.thunks = []


Expand Down
4 changes: 2 additions & 2 deletions src/waitress/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ def __init__(self, body):
self.body = body

def to_response(self):
status = "%s %s" % (self.code, self.reason)
body = "%s\r\n\r\n%s" % (self.reason, self.body)
status = f"{self.code} {self.reason}"
body = f"{self.reason}\r\n\r\n{self.body}"
tag = "\r\n\r\n(generated by waitress)"
body = (body + tag).encode("utf-8")
headers = [("Content-Type", "text/plain; charset=utf-8")]
Expand Down
2 changes: 1 addition & 1 deletion src/waitress/wasyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def __repr__(self):
status.append("%s:%d" % self.addr)
except TypeError: # pragma: no cover
status.append(repr(self.addr))
return "<%s at %#x>" % (" ".join(status), id(self))
return "<{} at {:#x}>".format(" ".join(status), id(self))

__str__ = __repr__

Expand Down
4 changes: 2 additions & 2 deletions tests/test_wasyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
else:
TESTFN = "@test"

TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid())
TESTFN = f"{TESTFN}_{os.getpid()}_tmp"


class DummyLogger: # pragma: no cover
Expand Down Expand Up @@ -574,7 +574,7 @@ def test_compact_traceback(self):
self.assertEqual(function, "test_compact_traceback")
self.assertEqual(t, real_t)
self.assertEqual(v, real_v)
self.assertEqual(info, "[%s|%s|%s]" % (f, function, line))
self.assertEqual(info, f"[{f}|{function}|{line}]")


class DispatcherTests(unittest.TestCase):
Expand Down

0 comments on commit 8f5b473

Please sign in to comment.