- val_str = self.params[key][0]
- try:
- return int(val_str)
- except ValueError as e:
- raise BadFormatException(f'Bad ?{key}= value: {val_str}') from e
-
-
-class PostvarsParser:
- """Postvars wrapper for validating and retrieving form data."""
-
- def __init__(self, postvars: dict[str, list[str]]) -> None:
- self.postvars = postvars
-
- def get_str(self, key: str) -> str:
- """Retrieve string value of key from self.postvars."""
- all_str = self.get_all_str(key)
- if 0 == len(all_str):
- raise BadFormatException(f'missing value for key: {key}')
- return all_str[0]
-
- def get_int(self, key: str) -> int:
- """Retrieve int value of key from self.postvars."""
- val = self.get_str(key)