From 3a5c15d648b52ee2a26291f2d025fb81774af0dd Mon Sep 17 00:00:00 2001 From: Enno Richter Date: Thu, 17 Oct 2024 10:26:39 +0200 Subject: [PATCH] httpserve: apply ruff fixes & mv to bin --- scripts/httpserve.py => bin/httpserve | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) rename scripts/httpserve.py => bin/httpserve (99%) mode change 100644 => 100755 diff --git a/scripts/httpserve.py b/bin/httpserve old mode 100644 new mode 100755 similarity index 99% rename from scripts/httpserve.py rename to bin/httpserve index 79d1e4bb..660a9211 --- a/scripts/httpserve.py +++ b/bin/httpserve @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # source: https://github.com/Tallguy297/SimpleHTTPServerWithUpload/blob/master/SimpleHTTPServerWithUpload.py """Simple HTTP Server With Upload. @@ -39,13 +40,13 @@ def fbytes(B): if B < KB: return "{0} {1}".format(B, "Bytes" if 0 == B > 1 else "Byte") elif KB <= B < MB: - return "{0:.2f} KB".format(B / KB) + return f"{B / KB:.2f} KB" elif MB <= B < GB: - return "{0:.2f} MB".format(B / MB) + return f"{B / MB:.2f} MB" elif GB <= B < TB: - return "{0:.2f} GB".format(B / GB) + return f"{B / GB:.2f} GB" elif TB <= B: - return "{0:.2f} TB".format(B / TB) + return f"{B / TB:.2f} TB" class SimpleHTTPRequestHandler(http.server.BaseHTTPRequestHandler): @@ -133,7 +134,7 @@ def deal_post_data(self): remainbytes -= len(line) try: out = open(fn, "wb") - except IOError: + except OSError: return ( False, "

Can't create file to write.
Do you have permission to write?", @@ -187,7 +188,7 @@ def send_head(self): # newline translations, making the actual size of the content # transmitted *less* than the content-length! f = open(path, "rb") - except IOError: + except OSError: self.send_error(404, "File not found") return None self.send_response(200) @@ -206,7 +207,7 @@ def list_directory(self, path): """ try: list = os.listdir(path) - except os.error: + except OSError: self.send_error(404, "No permission to list directory") return None enc = sys.getfilesystemencoding()