Clean up other Python files (#11379)

* Address issues found by ruff check.

* Make mypy happy; remove some Python 2 compat code.

* Also declare port1.
This commit is contained in:
Felix Fontein
2026-01-05 17:59:58 +01:00
committed by GitHub
parent 75234597bc
commit b3dc06a7dd
16 changed files with 52 additions and 47 deletions

View File

@@ -9,13 +9,8 @@ import os
import posixpath
import sys
try:
from http.server import SimpleHTTPRequestHandler, HTTPServer
from urllib.parse import unquote
except ImportError:
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
from urllib import unquote
from http.server import SimpleHTTPRequestHandler, HTTPServer
from urllib.parse import unquote
# Argument parsing
@@ -23,8 +18,8 @@ if len(sys.argv) != 4:
print(f"Syntax: {sys.argv[0]} <bind> <port> <path>")
sys.exit(-1)
HOST, PORT, PATH = sys.argv[1:4]
PORT = int(PORT)
HOST, PORT_str, PATH = sys.argv[1:4]
PORT = int(PORT_str)
# The HTTP request handler
@@ -40,7 +35,7 @@ class Handler(SimpleHTTPRequestHandler):
trailing_slash = path.rstrip().endswith("/")
try:
path = unquote(path, errors="surrogatepass")
except (UnicodeDecodeError, TypeError) as exc:
except (UnicodeDecodeError, TypeError):
path = unquote(path)
path = posixpath.normpath(path)
words = path.split("/")