File: validators.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (25 lines) | stat: -rw-r--r-- 660 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from typing import Any, Optional


def is_integer_between(
    x: int, mn: Optional[int] = None, mx: Optional[int] = None, optional: bool = False
) -> bool:
    if optional and x is None:
        return True
    try:
        if mn is not None and mx is not None:
            return int(x) >= mn and int(x) < mx
        elif mn is not None:
            return int(x) >= mn
        elif mx is not None:
            return int(x) < mx
        else:
            return True
    except ValueError:
        return False


def is_one_of(x: Any, choices: Any, optional: bool = False) -> bool:
    if optional and x is None:
        return True
    return x in choices