-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logging module and download module; download progress bar
- Loading branch information
1 parent
8e1ccdc
commit 100541a
Showing
4 changed files
with
150 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Iterable, TypedDict | ||
|
||
from bs4 import BeautifulSoup | ||
|
||
|
||
class DownloadFile(TypedDict): | ||
client_entropy: str | ||
encrypted: str | ||
encrypted_size: int | ||
fileaead: str | ||
fileiv: str | ||
id: int | ||
key_salt: str | ||
key_version: int | ||
mime: str | ||
#: filename | ||
name: str | ||
password_encoding: str | ||
password_hash_iterations: int | ||
password_version: int | ||
size: int | ||
transferid: int | ||
|
||
def files_from_page(content: bytes) -> Iterable[DownloadFile]: | ||
""" | ||
Yields dictionaries describing the files listed on a FileSender web page | ||
Params: | ||
content: The HTML content of the FileSender download page | ||
""" | ||
for file in BeautifulSoup(content, "html.parser").find_all( | ||
class_="file" | ||
): | ||
yield { | ||
"client_entropy": file.attrs[f"data-client-entropy"], | ||
"encrypted": file.attrs["data-encrypted"], | ||
"encrypted_size": int(file.attrs["data-encrypted-size"]), | ||
"fileaead": file.attrs["data-fileaead"], | ||
"fileiv": file.attrs["data-fileiv"], | ||
"id": int(file.attrs["data-id"]), | ||
"key_salt": file.attrs["data-key-salt"], | ||
"key_version": int(file.attrs["data-key-version"]), | ||
"mime": file.attrs["data-mime"], | ||
"name": file.attrs["data-name"], | ||
"password_encoding": file.attrs["data-password-encoding"], | ||
"password_hash_iterations": int(file.attrs["data-password-hash-iterations"]), | ||
"password_version": int(file.attrs["data-password-version"]), | ||
"size": int(file.attrs["data-size"]), | ||
"transferid": int(file.attrs["data-transferid"]), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from click import ParamType, Context, Parameter | ||
from enum import Enum | ||
|
||
class LogLevel(Enum): | ||
NOTSET = 0 | ||
DEBUG = 10 | ||
VERBOSE = 15 | ||
INFO = 20 | ||
WARNING = 30 | ||
ERROR = 40 | ||
CRITICAL = 50 | ||
|
||
class LogParam(ParamType): | ||
name = "LogParam" | ||
|
||
def convert(self, value: int | str, param: Parameter | None, ctx: Context | None) -> int: | ||
if isinstance(value, int): | ||
return value | ||
|
||
# Convert string representation to int | ||
if not hasattr(LogLevel, value): | ||
self.fail(f"{value!r} is not a valid log level", param, ctx) | ||
|
||
return LogLevel[value].value | ||
|
||
def get_metavar(self, param: Parameter) -> str | None: | ||
# Print out the choices | ||
return "|".join(LogLevel._member_map_) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters