diff options
| author | Cody Logan <cody@lokken.dev> | 2023-10-13 10:11:20 -0700 |
|---|---|---|
| committer | Cody Logan <cody@lokken.dev> | 2023-10-13 10:11:20 -0700 |
| commit | 8b70abecb543099528ecc8c3b1edfe0330d3d223 (patch) | |
| tree | 939de9ab71d283489406838af4d14ef10ec1528d /src/wikiget/validations.py | |
| parent | 5dc9b79bd68d2f7cf0dcf1adfaffd8e07b27c6ba (diff) | |
| download | wikiget-8b70abecb543099528ecc8c3b1edfe0330d3d223.tar.gz wikiget-8b70abecb543099528ecc8c3b1edfe0330d3d223.zip | |
Refactor code and improve docstrings
Diffstat (limited to 'src/wikiget/validations.py')
| -rw-r--r-- | src/wikiget/validations.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/wikiget/validations.py b/src/wikiget/validations.py index 8ebd996..1610417 100644 --- a/src/wikiget/validations.py +++ b/src/wikiget/validations.py @@ -23,11 +23,14 @@ from wikiget import BLOCKSIZE def valid_file(search_string): """ - 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, defined as a string + ending with a '.' and at least one character, beginning with 'File:' or 'Image:', + the standard file prefixes in MediaWiki. + :param search_string: string to validate + :type search_string: str :returns: a regex Match object if there's a match or None otherwise + :rtype: re.Match """ # second group could also restrict to file extensions with three or more # letters with ([^/\r\n\t\f\v]+\.\w{3,}) @@ -37,12 +40,15 @@ def valid_file(search_string): def valid_site(search_string): """ - 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. Eventually, it should be possible to support - any MediaWiki site, regardless of domain name. + 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. Eventually, it should be possible to support any MediaWiki site, regardless + of domain name. + :param search_string: string to validate + :type search_string: str :returns: a regex Match object if there's a match or None otherwise + :rtype: re.Match """ site_regex = re.compile(r"wiki[mp]edia\.org$", re.I) return site_regex.search(search_string) @@ -50,10 +56,12 @@ def valid_site(search_string): def verify_hash(filename): """ - 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. + :param filename: name of the file to calculate a hash for + :type filename: str :return: hash digest + :rtype: str """ hasher = hashlib.sha1() # noqa: S324 with open(filename, "rb") as dl: |
