Skip to content
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

Fix flake8 issue WPS336 (explicit str concat) #254

Merged
merged 24 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5c3a47b
modified 3/5 files to conform to flake8 WPS336 style, removing explic…
Dec 3, 2019
ed51081
finished up the other two files, removed explicit string concatenation
Dec 3, 2019
ad6180a
finished up the other two files, removed explicit string concatenation
Dec 3, 2019
f79d837
addressing 3 long lines identified by codeclimate
Dec 3, 2019
b5211c6
addressed tox test failures, where name 'b' was not defined
Dec 3, 2019
a05b2ae
Merge branch 'master' of https://github.com/alephnot0/cheroot
Dec 3, 2019
f77e0cc
PEP-8 style issue, continuation line was under-indented for visual in…
Dec 3, 2019
9fec76f
respond to feedback, use string interpolation
alephnot0 Dec 4, 2019
1e7a23b
encode both operands in ascii rather than b''
alephnot0 Dec 4, 2019
3afec78
string interpolation where possible for appending strings
alephnot0 Dec 4, 2019
eb61549
string interpolation where possible and fix indent with .format... me…
alephnot0 Dec 4, 2019
be7d15d
two instances where lines are too long
alephnot0 Dec 4, 2019
75d389f
two redundant backslashes
alephnot0 Dec 4, 2019
b9652e4
backslash needed for line continuation
alephnot0 Dec 4, 2019
dd7b872
flake8 rules around hanging and visual indents
alephnot0 Dec 4, 2019
a9837da
flake8 rules around hanging and visual indents
alephnot0 Dec 4, 2019
6b29ab1
codeclimate - unaligned for hanging indent
alephnot0 Dec 4, 2019
4785d39
flake8 fixing over indentation
alephnot0 Dec 4, 2019
4951cfc
flake8 fixing over indentation
alephnot0 Dec 4, 2019
b3c4c67
🎨Address str format conserns in `cheroot.server`
webknjaz Dec 27, 2019
27577b7
🎨 Use placeholder names in threadpool str format
webknjaz Dec 27, 2019
e514076
🎨 Use `bytes.join()` in `cheroot.test.test_conn`
webknjaz Dec 27, 2019
e179975
🎨Use named str.format placeholders @ `test_ssl`
webknjaz Dec 27, 2019
360627c
🎨Use named str fmt placeholders @ `cheroot.wsgi`
webknjaz Dec 27, 2019
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
18 changes: 11 additions & 7 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)' + QUOTED_SLASH)
QUOTED_SLASH_REGEX = re.compile(b''.join([b'(?i)', QUOTED_SLASH]))
webknjaz marked this conversation as resolved.
Show resolved Hide resolved


comma_separated_headers = [
Expand Down Expand Up @@ -467,7 +467,8 @@ def _fetch(self):
chunk_size = line.pop(0)
chunk_size = int(chunk_size, 16)
except ValueError:
raise ValueError('Bad chunked transfer size: ' + repr(chunk_size))
raise ValueError('Bad chunked transfer size: {}'
webknjaz marked this conversation as resolved.
Show resolved Hide resolved
.format(repr(chunk_size)))

if chunk_size <= 0:
self.closed = True
Expand Down Expand Up @@ -822,7 +823,9 @@ def read_request_line(self):

# `urlsplit()` above parses "example.com:3128" as path part of URI.
# this is a workaround, which makes it detect netloc correctly
uri_split = urllib.parse.urlsplit(b'//' + uri)
uri_split = urllib.parse.urlsplit(
'//{}'.format(uri)
.encode('ascii'))
webknjaz marked this conversation as resolved.
Show resolved Hide resolved
_scheme, _authority, _path, _qs, _fragment = uri_split
_port = EMPTY
try:
Expand Down Expand Up @@ -1037,8 +1040,9 @@ def read_request_headers(self):
# Don't use simple_response here, because it emits headers
# we don't want. See
# https://github.com/cherrypy/cherrypy/issues/951
msg = self.server.protocol.encode('ascii')
msg += b' 100 Continue\r\n\r\n'
msg = '{} {}'.format(self.server.protocol,
webknjaz marked this conversation as resolved.
Show resolved Hide resolved
'100 Continue\r\n\r\n') \
webknjaz marked this conversation as resolved.
Show resolved Hide resolved
.encode('ascii')
try:
self.conn.wfile.write(msg)
except socket.error as ex:
Expand Down Expand Up @@ -1499,7 +1503,7 @@ class HTTPServer:
timeout = 10
"""The timeout in seconds for accepted connections (default 10)."""

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

software = None
Expand Down Expand Up @@ -1805,7 +1809,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(msg + '\n')
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'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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use proper literals instead of heavy encode/decode methods. It's also a good place for bytes.join(). Same with escaping EOL.

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'GET /hello HTTP/1.1' + invalid_terminator)
conn.send('GET /hello HTTP/1.1{}'.format(invalid_terminator)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We work with bytes so we need to explicitly say that it's bytes.

.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://' + interface + ':' + str(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://' + interface + ':' + str(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://' + fqdn + ':' + str(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://' + fqdn + ':' + str(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 ' + 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 ' + worker.getName())
worker.setName('CP Server {}'.format(worker.getName()))
worker.start()
return worker

Expand Down
4 changes: 2 additions & 2 deletions cheroot/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def get_environ(self):

# Request headers
env.update(
('HTTP_' + bton(k).upper().replace('-', '_'), bton(v))
('HTTP_%s' % (bton(k).upper().replace('-', '_')), bton(v))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use str.format() in this module.

for k, v in req.inheaders.items()
)

Expand Down Expand Up @@ -409,7 +409,7 @@ def __call__(self, environ, start_response):
path = environ['PATH_INFO'] or '/'
for p, app in self.apps:
# The apps list should be sorted by length, descending.
if path.startswith(p + '/') or path == p:
if path.startswith('%s/' % (p)) or path == p:
environ = environ.copy()
environ['SCRIPT_NAME'] = environ.get('SCRIPT_NAME', '') + p
environ['PATH_INFO'] = path[len(p):]
Expand Down