Skip to content

Commit

Permalink
httpserve: apply ruff fixes & mv to bin
Browse files Browse the repository at this point in the history
  • Loading branch information
elohmeier committed Oct 17, 2024
1 parent 07b2de0 commit 3a5c15d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions scripts/httpserve.py → bin/httpserve
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# source: https://github.com/Tallguy297/SimpleHTTPServerWithUpload/blob/master/SimpleHTTPServerWithUpload.py

"""Simple HTTP Server With Upload.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -133,7 +134,7 @@ def deal_post_data(self):
remainbytes -= len(line)
try:
out = open(fn, "wb")
except IOError:
except OSError:
return (
False,
"<br><br>Can't create file to write.<br>Do you have permission to write?",
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit 3a5c15d

Please sign in to comment.