aboutsummaryrefslogtreecommitdiff
path: root/src/wikiget/validations.py
diff options
context:
space:
mode:
authorCody Logan <cody@lokken.dev>2023-11-15 10:36:18 -0800
committerGitHub <noreply@github.com>2023-11-15 10:36:18 -0800
commitbf3a7db6cf83fa7d224d84c47b40cfe32603019c (patch)
treeffeb394c3da9e4a2dcbc6a92caa956d5c83441eb /src/wikiget/validations.py
parent55a5311ee4da639a65bd60622315f3fff6936c9a (diff)
downloadwikiget-bf3a7db6cf83fa7d224d84c47b40cfe32603019c.tar.gz
wikiget-bf3a7db6cf83fa7d224d84c47b40cfe32603019c.zip
Convert File.dest from a string to a Path (#14)
Diffstat (limited to 'src/wikiget/validations.py')
-rw-r--r--src/wikiget/validations.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/wikiget/validations.py b/src/wikiget/validations.py
index c7cc2dd..7c2b5ae 100644
--- a/src/wikiget/validations.py
+++ b/src/wikiget/validations.py
@@ -19,10 +19,13 @@ from __future__ import annotations
import hashlib
import re
-from pathlib import Path
+from typing import TYPE_CHECKING
from wikiget import BLOCKSIZE
+if TYPE_CHECKING:
+ from pathlib import Path
+
def valid_file(search_string: str) -> re.Match | None:
"""Determine if the given string contains a valid file name.
@@ -60,7 +63,7 @@ def valid_site(search_string: str) -> re.Match | None:
return site_regex.search(search_string)
-def verify_hash(filename: str) -> str:
+def verify_hash(file: Path) -> str:
"""Calculate the SHA1 hash of the given file for comparison with a known value.
Despite being insecure, SHA1 is used since that's what the MediaWiki API returns for
@@ -72,7 +75,7 @@ def verify_hash(filename: str) -> str:
:rtype: str
"""
hasher = hashlib.sha1() # noqa: S324
- with Path(filename).open("rb") as dl:
+ with file.open("rb") as dl:
buf = dl.read(BLOCKSIZE)
while len(buf) > 0:
hasher.update(buf)