Skip to content

Commit 900b052

Browse files
committed
Improve variable/func names
Avoid single-letter variable in non-trivial scope.
1 parent ce84d10 commit 900b052

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

sogs/routes/general.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_caps():
3737
return jsonify(res), res_code
3838

3939

40-
def parse_batch_req(r):
40+
def parse_batch_request(req):
4141
"""
4242
Checks a batch request dict for the required fields:
4343
@@ -56,26 +56,26 @@ def parse_batch_req(r):
5656
dict within the request for json bodies, and `body` will be the *bytes* data (i.e. decoded from
5757
base64, when using `b64`) for 'b64' or 'bytes' requests.
5858
"""
59-
if not isinstance(r, dict):
59+
if not isinstance(req, dict):
6060
app.logger.warning("Invalid batch request: batch request is not a dict")
6161
abort(http.BAD_REQUEST)
62-
if 'method' not in r:
62+
if 'method' not in req:
6363
app.logger.warning("Invalid batch request: batch request has no method")
6464
abort(http.BAD_REQUEST)
65-
if 'path' not in r:
65+
if 'path' not in req:
6666
app.logger.warning("Invalid batch request: batch request has no path")
6767
abort(http.BAD_REQUEST)
6868

69-
method, path, headers, json, body = r['method'], r['path'], {}, None, None
69+
method, path, headers, json, body = req['method'], req['path'], {}, None, None
7070

71-
if 'headers' in r:
72-
if not isinstance(r['headers'], dict):
71+
if 'headers' in req:
72+
if not isinstance(req['headers'], dict):
7373
app.logger.warning("Bad batch request: 'headers' must be a dict")
7474
abort(http.BAD_REQUEST)
75-
if any(not isinstance(k, str) or not isinstance(v, str) for k, v in r['headers'].items()):
75+
if any(not isinstance(k, str) or not isinstance(v, str) for k, v in req['headers'].items()):
7676
app.logger.warning("Bad batch request: 'headers' must contain only str/str pairs")
7777
abort(http.BAD_REQUEST)
78-
headers = r['headers']
78+
headers = req['headers']
7979

8080
has_body = method in ('POST', 'PUT')
8181
if not has_body and method not in ('GET', 'DELETE'):
@@ -86,7 +86,7 @@ def parse_batch_req(r):
8686
app.logger.warning(f"Bad batch request: path must start with /, got: [{path}]")
8787
abort(http.BAD_REQUEST)
8888

89-
n_bodies = sum(k in r for k in ('b64', 'json', 'bytes'))
89+
n_bodies = sum(k in req for k in ('b64', 'json', 'bytes'))
9090
if has_body:
9191
if not n_bodies:
9292
app.logger.warning(f"Bad batch request: {method} requires one of json/b64/bytes")
@@ -97,20 +97,20 @@ def parse_batch_req(r):
9797
)
9898
abort(http.BAD_REQUEST)
9999

100-
if 'b64' in r:
100+
if 'b64' in req:
101101
try:
102-
body = utils.decode_base64(r['b64'])
102+
body = utils.decode_base64(req['b64'])
103103
except Exception:
104104
app.logger.warning("Bad batch request: b64 value is not valid base64")
105-
elif 'bytes' in r:
106-
body = r['bytes']
105+
elif 'bytes' in req:
106+
body = req['bytes']
107107
if not isinstance(body, bytes):
108108
body = body.encode()
109109
else:
110-
json = r['json']
110+
json = req['json']
111111

112112
elif n_bodies:
113-
app.logger.warning(f"Bad batch request: {r['method']} cannot have a json/b64/bytes body")
113+
app.logger.warning(f"Bad batch request: {req['method']} cannot have a json/b64/bytes body")
114114
abort(http.BAD_REQUEST)
115115

116116
return method, path, headers, json, body
@@ -138,7 +138,7 @@ def batch(_sequential=False):
138138

139139
# Expand this into a list first (rather than during iteration below) so that we abort everything
140140
# if any subrequest is invalid.
141-
subreqs = [parse_batch_req(r) for r in subreqs]
141+
subreqs = [parse_batch_request(r) for r in subreqs]
142142

143143
response = []
144144
for method, path, headers, json, body in subreqs:

0 commit comments

Comments
 (0)