Skip to content

Commit de4adac

Browse files
committed
fix black & flake8
1 parent f6162ae commit de4adac

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

pyproxy/monitoring/routes.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def blocked():
9696
Response: JSON object with 'blocked_sites' and 'blocked_url' lists.
9797
9898
POST:
99-
Adds a new domain or URL to the blocked lists based on 'type' and 'value' from JSON input.
99+
Adds a new domain or URL to the blocked lists based on
100+
'type' and 'value' from JSON input.
100101
Request JSON:
101102
{
102103
"type": "domain" | "url",
@@ -108,7 +109,8 @@ def blocked():
108109
409: Value already blocked.
109110
110111
DELETE:
111-
Removes a domain or URL from the blocked lists based on 'type' and 'value' from JSON input.
112+
Removes a domain or URL from the blocked lists based on
113+
'type' and 'value' from JSON input.
112114
Request JSON:
113115
{
114116
"type": "domain" | "url",
@@ -124,9 +126,13 @@ def blocked():
124126
blocked_sites_content = ""
125127
blocked_url_content = ""
126128

127-
with open(proxy_server.filter_config.blocked_sites, "r", encoding="utf-8") as f:
129+
with open(
130+
proxy_server.filter_config.blocked_sites, "r", encoding="utf-8"
131+
) as f:
128132
blocked_sites_content = [line.strip() for line in f if line.strip()]
129-
with open(proxy_server.filter_config.blocked_url, "r", encoding="utf-8") as f:
133+
with open(
134+
proxy_server.filter_config.blocked_url, "r", encoding="utf-8"
135+
) as f:
130136
blocked_url_content = [line.strip() for line in f if line.strip()]
131137

132138
blocked_data = {
@@ -161,7 +167,10 @@ def blocked():
161167
elif request.method == "DELETE":
162168
data = request.get_json()
163169
if not data or "type" not in data or "value" not in data:
164-
return jsonify({"error": "Missing 'type' or 'value' in request body"}), 400
170+
return (
171+
jsonify({"error": "Missing 'type' or 'value' in request body"}),
172+
400,
173+
)
165174

166175
block_type = data["type"]
167176
value = data["value"].strip()
@@ -171,21 +180,32 @@ def blocked():
171180
elif block_type == "url":
172181
filepath = proxy_server.filter_config.blocked_url
173182
else:
174-
return jsonify({"error": "Invalid type, must be 'domain' or 'url'"}), 400
183+
return (
184+
jsonify({"error": "Invalid type, must be 'domain' or 'url'"}),
185+
400,
186+
)
175187

176188
try:
177189
with open(filepath, "r", encoding="utf-8") as f:
178190
lines = [line.strip() for line in f if line.strip()]
179191

180192
if value not in lines:
181-
return jsonify({"error": f"{value} not found in {block_type} list"}), 404
193+
return (
194+
jsonify({"error": f"{value} not found in {block_type} list"}),
195+
404,
196+
)
182197

183198
lines = [line for line in lines if line != value]
184199

185200
with open(filepath, "w", encoding="utf-8") as f:
186201
for line in lines:
187202
f.write(line + "\n")
188203

189-
return jsonify({"message": f"{block_type} '{value}' removed successfully"}), 200
204+
return (
205+
jsonify(
206+
{"message": f"{block_type} '{value}' removed successfully"}
207+
),
208+
200,
209+
)
190210
except Exception as e:
191211
return jsonify({"error": f"Server error: {str(e)}"}), 500

0 commit comments

Comments
 (0)