add sort param support in CDX API class (#156)

see https://nla.github.io/outbackcdx/api.html#operation/query

sort takes string input which must be one of the follwoing:
- default
- closest
- reverse

This commit shall help in closing issue at https://github.com/akamhy/waybackpy/issues/155
This commit is contained in:
Akash Mahanty
2022-02-17 12:17:23 +05:30
committed by GitHub
parent f63c6adf79
commit 3a44a710d3
3 changed files with 38 additions and 0 deletions

View File

@@ -151,3 +151,24 @@ def check_match_type(match_type: Optional[str], url: str) -> bool:
raise WaybackError(exc_message)
return True
def check_sort(sort: Optional[str]) -> bool:
"""
Check that the sort argument passed by the end-user is valid.
If not valid then raise WaybackError.
"""
legal_sort = ["default", "closest", "reverse"]
if not sort:
return True
if sort not in legal_sort:
exc_message = (
f"{sort} is not an allowed argument for sort.\n"
"Use one from 'default', 'closest' or 'reverse'"
)
raise WaybackError(exc_message)
return True