Skip to content

Commit 7675afb

Browse files
committed
Fix python codestyle and typing issues
1 parent 2fb4986 commit 7675afb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/python3
2-
32
import os
43

54
envvars = os.environ.items()
65
print(f'COUNT: {len(envvars)}.')
76
for k, v in envvars:
87
print(f'{k}={v}')
9-

misc-tools/dj_utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def parse_api_response(name: str, response: requests.Response):
4747
# We got a successful HTTP response. It worked. Return the full response
4848
try:
4949
result = json.loads(response.text)
50-
except json.decoder.JSONDecodeError as e:
50+
except json.decoder.JSONDecodeError:
5151
print(response.text)
5252
raise RuntimeError(f'Failed to JSON decode the response for API request {name}')
5353

@@ -79,15 +79,17 @@ def do_api_request(name: str, method: str = 'GET', jsonData: dict = {}):
7979
url = f'{domjudge_webapp_folder_or_api_url}/{name}'
8080
parsed = urlparse(domjudge_webapp_folder_or_api_url)
8181
auth = None
82-
if parsed.username or parsed.password:
82+
if parsed.username and parsed.password:
8383
auth = (parsed.username, parsed.password)
8484

8585
try:
8686
if method == 'GET':
8787
response = requests.get(url, headers=headers, verify=ca_check, auth=auth)
8888
elif method == 'PUT':
8989
response = requests.put(url, headers=headers, verify=ca_check, json=jsonData, auth=auth)
90-
except requests.exceptions.SSLError as e:
90+
else:
91+
raise RuntimeError("Method not supported")
92+
except requests.exceptions.SSLError:
9193
ca_check = not confirm(
9294
"Can not verify certificate, ignore certificate check?", False)
9395
if ca_check:
@@ -99,6 +101,7 @@ def do_api_request(name: str, method: str = 'GET', jsonData: dict = {}):
99101
raise RuntimeError(e)
100102
return parse_api_response(name, response)
101103

104+
102105
def upload_file(name: str, apifilename: str, file: str, data: dict = {}):
103106
'''Upload the given file to the API at the given path with the given name.
104107
@@ -128,7 +131,7 @@ def upload_file(name: str, apifilename: str, file: str, data: dict = {}):
128131
try:
129132
response = requests.post(
130133
url, files=files, headers=headers, data=data, verify=ca_check)
131-
except requests.exceptions.SSLError as e:
134+
except requests.exceptions.SSLError:
132135
ca_check = not confirm(
133136
"Can not verify certificate, ignore certificate check?", False)
134137
if ca_check:

0 commit comments

Comments
 (0)