Skip to content

Commit

Permalink
string interpolation where possible for appending strings
Browse files Browse the repository at this point in the history
  • Loading branch information
alephnot0 committed Dec 4, 2019
1 parent 1e7a23b commit 3afec78
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions cheroot/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
ASTERISK = b'*'
FORWARD_SLASH = b'/'
QUOTED_SLASH = b'%2F'
QUOTED_SLASH_REGEX = re.compile(b'(?i)%s' % (QUOTED_SLASH))
QUOTED_SLASH_REGEX = re.compile(b''.join([b'(?i)', QUOTED_SLASH]))


comma_separated_headers = [
Expand Down Expand Up @@ -467,8 +467,8 @@ def _fetch(self):
chunk_size = line.pop(0)
chunk_size = int(chunk_size, 16)
except ValueError:
raise ValueError('Bad chunked transfer size: %s'
% (repr(chunk_size)))
raise ValueError('Bad chunked transfer size: {}'
.format(repr(chunk_size)))

if chunk_size <= 0:
self.closed = True
Expand Down Expand Up @@ -1500,7 +1500,7 @@ class HTTPServer:
timeout = 10
"""The timeout in seconds for accepted connections (default 10)."""

version = 'Cheroot/%s' % (__version__)
version = 'Cheroot/{}'.format(__version__)
"""A version string for the HTTPServer."""

software = None
Expand Down Expand Up @@ -1806,7 +1806,7 @@ def error_log(self, msg='', level=20, traceback=False):
traceback (bool): add traceback to output or not
"""
# Override this in subclasses as desired
sys.stderr.write('%s\n' % (msg))
sys.stderr.write('{}\n'.format(msg))
sys.stderr.flush()
if traceback:
tblines = traceback_.format_exc()
Expand Down
7 changes: 4 additions & 3 deletions cheroot/test/test_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,8 @@ def test_Chunked_Encoding(test_client):

# Try a chunked request that exceeds server.max_request_body_size.
# Note that the delimiters and trailer are included.
body = b''.join([b'3e3\r\n', (b'x' * 995), b'\r\n0\r\n\r\n'])
body = '{}{}{}'.format('3e3\r\n', 'x' * 995, '\r\n0\r\n\r\n')
.encode('ascii')
conn.putrequest('POST', '/upload', skip_host=True)
conn.putheader('Host', conn.host)
conn.putheader('Transfer-Encoding', 'chunked')
Expand Down Expand Up @@ -971,8 +972,8 @@ def test_No_CRLF(test_client, invalid_terminator):
# Initialize a persistent HTTP connection
conn = test_client.get_connection()

# (b'%s' % b'') is not supported in Python 3.4, so just use +
conn.send(b''.join([b'GET /hello HTTP/1.1', invalid_terminator]))
conn.send('GET /hello HTTP/1.1{}'.format(invalid_terminator)
.encode('ascii'))
response = conn.response_class(conn.sock, method='GET')
response.begin()
actual_resp_body = response.read()
Expand Down
8 changes: 4 additions & 4 deletions cheroot/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_ssl_adapters(
)

resp = requests.get(
'https://%s:%s/' % (interface, port),
'https://{}:{}/'.format(interface, port),
verify=tls_ca_certificate_pem_path,
)

Expand Down Expand Up @@ -274,7 +274,7 @@ def test_tls_client_auth(

make_https_request = functools.partial(
requests.get,
'https://%s:%s/' % (interface, port),
'https://{}:{}/'.format(interface, port),

# Server TLS certificate verification:
verify=tls_ca_certificate_pem_path,
Expand Down Expand Up @@ -482,7 +482,7 @@ def test_http_over_https_error(
expect_fallback_response_over_plain_http = False
if expect_fallback_response_over_plain_http:
resp = requests.get(
'http://%s:%s/' % (fqdn, port),
'http://{}:{}/'.format(fqdn, port),
)
assert resp.status_code == 400
assert resp.text == (
Expand All @@ -493,7 +493,7 @@ def test_http_over_https_error(

with pytest.raises(requests.exceptions.ConnectionError) as ssl_err:
requests.get( # FIXME: make stdlib ssl behave like PyOpenSSL
'http://%s:%s/' % (fqdn, port),
'http://{}:{}/'.format(fqdn, port),
)

if IS_LINUX:
Expand Down
4 changes: 2 additions & 2 deletions cheroot/workers/threadpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def start(self):
for i in range(self.min):
self._threads.append(WorkerThread(self.server))
for worker in self._threads:
worker.setName('CP Server %s' % (worker.getName()))
worker.setName('CP Server {}'.format(worker.getName()))
worker.start()
for worker in self._threads:
while not worker.ready:
Expand Down Expand Up @@ -223,7 +223,7 @@ def grow(self, amount):

def _spawn_worker(self):
worker = WorkerThread(self.server)
worker.setName('CP Server %s' % (worker.getName()))
worker.setName('CP Server {}'.format(worker.getName()))
worker.start()
return worker

Expand Down

0 comments on commit 3afec78

Please sign in to comment.