diff options
| author | Cody Logan <cody@lokken.dev> | 2023-11-08 12:00:45 -0800 |
|---|---|---|
| committer | Cody Logan <cody@lokken.dev> | 2023-11-08 12:00:45 -0800 |
| commit | ecaa8a2d019cef5a83a8dc0ed1d4ad5c9fc81a72 (patch) | |
| tree | 571b803162477b01ff4df5776cfe7972cc216c40 /src/wikiget | |
| parent | e8da17d8c6b7fd879e196ae425b8e62c78e579fe (diff) | |
| download | wikiget-ecaa8a2d019cef5a83a8dc0ed1d4ad5c9fc81a72.tar.gz wikiget-ecaa8a2d019cef5a83a8dc0ed1d4ad5c9fc81a72.zip | |
Add and refine docstrings in tests folder.
Diffstat (limited to 'src/wikiget')
| -rw-r--r-- | src/wikiget/validations.py | 23 | ||||
| -rw-r--r-- | src/wikiget/wikiget.py | 9 |
2 files changed, 21 insertions, 11 deletions
diff --git a/src/wikiget/validations.py b/src/wikiget/validations.py index ee73b87..18c1f86 100644 --- a/src/wikiget/validations.py +++ b/src/wikiget/validations.py @@ -25,10 +25,11 @@ from wikiget import BLOCKSIZE def valid_file(search_string: str) -> re.Match | None: - """ - Determines if the given string contains a valid file name, defined as a string - ending with a '.' and at least one character, beginning with 'File:' or 'Image:', - the standard file prefixes in MediaWiki. + """Determines if the given string contains a valid file name + + A valid file name is a string that begins with 'File:' or 'Image:' (the standard + file prefixes in MediaWiki), includes a period, and has at least one character + following the period, like 'File:Example.jpg' or 'Image:Example.svg'. :param search_string: string to validate :type search_string: str @@ -42,10 +43,10 @@ def valid_file(search_string: str) -> re.Match | None: def valid_site(search_string: str) -> re.Match | None: - """ - Determines if the given string contains a valid site name, defined as a string - ending with 'wikipedia.org' or 'wikimedia.org'. This covers all subdomains of those - domains. + """Determines if the given string contains a valid site name + + A valid site name is a string ending with 'wikipedia.org' or 'wikimedia.org'. This + covers all subdomains of those domains. Currently unused since any site is accepted as input, and we rely on the user to ensure the site has a compatible API. @@ -60,8 +61,10 @@ def valid_site(search_string: str) -> re.Match | None: def verify_hash(filename: str) -> str: - """ - Calculates the SHA1 hash of the given file for comparison with a known value. + """Calculates 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 + the file hash. :param filename: name of the file to calculate a hash for :type filename: str diff --git a/src/wikiget/wikiget.py b/src/wikiget/wikiget.py index 06dc458..ca211af 100644 --- a/src/wikiget/wikiget.py +++ b/src/wikiget/wikiget.py @@ -27,6 +27,13 @@ from wikiget.logging import configure_logging def parse_args(argv: list[str]) -> argparse.Namespace: + """Parse the given argument list. + + :param argv: a list of arguments in string form + :type argv: list[str] + :return: a Namespace containing the arguments and their values + :rtype: argparse.Namespace + """ parser = argparse.ArgumentParser( description=""" A tool for downloading files from MediaWiki sites using the file name or @@ -120,7 +127,7 @@ def parse_args(argv: list[str]) -> argparse.Namespace: def cli() -> None: - # setup our environment + """Set up the command-line environment and start the download process.""" args = parse_args(sys.argv[1:]) configure_logging(verbosity=args.verbose, logfile=args.logfile, quiet=args.quiet) |
