Skip to content

Commit 7c6473f

Browse files
author
Robert Denham
committed
add optional for un-encrypted files
1 parent 46f0249 commit 7c6473f

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

filesender/download.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,53 @@
1-
from typing import Iterable, TypedDict
1+
from typing import Iterable, Optional, TypedDict
22

33
from bs4 import BeautifulSoup
44

55

66
class DownloadFile(TypedDict):
77
client_entropy: str
88
encrypted: str
9-
encrypted_size: int
9+
encrypted_size: Optional[int]
1010
fileaead: str
1111
fileiv: str
1212
id: int
1313
key_salt: str
14-
key_version: int
14+
key_version: Optional[int]
1515
mime: str
1616
#: filename
1717
name: str
1818
password_encoding: str
19-
password_hash_iterations: int
20-
password_version: int
19+
password_hash_iterations: Optional[int]
20+
password_version: Optional[int]
2121
size: int
2222
transferid: int
2323

24+
def _opt_int(value: str) -> Optional[int]:
25+
return int(value) if value else None
26+
2427
def files_from_page(content: bytes) -> Iterable[DownloadFile]:
2528
"""
2629
Yields dictionaries describing the files listed on a FileSender web page
2730
2831
Params:
29-
content: The HTML content of the FileSender download page
32+
content: The HTML content of the FileSender download page
3033
"""
3134
for file in BeautifulSoup(content, "html.parser").find_all(
3235
class_="file"
3336
):
3437
yield {
3538
"client_entropy": file.attrs[f"data-client-entropy"],
3639
"encrypted": file.attrs["data-encrypted"],
37-
"encrypted_size": int(file.attrs["data-encrypted-size"]),
40+
"encrypted_size": _opt_int(file.attrs["data-encrypted-size"]),
3841
"fileaead": file.attrs["data-fileaead"],
3942
"fileiv": file.attrs["data-fileiv"],
4043
"id": int(file.attrs["data-id"]),
4144
"key_salt": file.attrs["data-key-salt"],
42-
"key_version": int(file.attrs["data-key-version"]),
45+
"key_version": _opt_int(file.attrs["data-key-version"]),
4346
"mime": file.attrs["data-mime"],
4447
"name": file.attrs["data-name"],
4548
"password_encoding": file.attrs["data-password-encoding"],
46-
"password_hash_iterations": int(file.attrs["data-password-hash-iterations"]),
47-
"password_version": int(file.attrs["data-password-version"]),
49+
"password_hash_iterations": _opt_int(file.attrs["data-password-hash-iterations"]),
50+
"password_version": _opt_int(file.attrs["data-password-version"]),
4851
"size": int(file.attrs["data-size"]),
4952
"transferid": int(file.attrs["data-transferid"]),
5053
}

0 commit comments

Comments
 (0)