OXIESEC PANEL
- Current Dir:
/
/
opt
/
alt
/
python311
/
lib
/
python3.11
/
site-packages
/
validators
Server IP: 2a02:4780:11:1594:0:ef5:22d7:a
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
01/09/2025 02:18:04 AM
rwxr-xr-x
📄
__init__.py
1.86 KB
05/14/2024 03:18:23 PM
rw-r--r--
📁
__pycache__
-
05/14/2024 03:18:23 PM
rwxr-xr-x
📄
_extremes.py
1.01 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
_tld.txt
9.4 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
between.py
2.39 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
btc_address.py
1.62 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
card.py
5.63 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
country.py
14.57 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
cron.py
2.23 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
domain.py
2.4 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
email.py
2.72 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
encoding.py
1.34 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
finance.py
3.22 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
hashes.py
3.21 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
hostname.py
4.05 KB
05/14/2024 03:18:23 PM
rw-r--r--
📁
i18n
-
05/14/2024 03:18:23 PM
rwxr-xr-x
📄
iban.py
1.05 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
ip_address.py
4.34 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
length.py
1.45 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
mac_address.py
865 bytes
05/14/2024 03:18:23 PM
rw-r--r--
📄
py.typed
0 bytes
05/14/2024 03:18:23 PM
rw-r--r--
📄
slug.py
750 bytes
05/14/2024 03:18:23 PM
rw-r--r--
📄
uri.py
1.78 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
url.py
7.23 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
utils.py
3.1 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
uuid.py
1.04 KB
05/14/2024 03:18:23 PM
rw-r--r--
Editing: between.py
Close
"""Between.""" # standard from datetime import datetime from typing import TypeVar, Union # local from ._extremes import AbsMax, AbsMin from .utils import validator PossibleValueTypes = TypeVar("PossibleValueTypes", int, float, str, datetime, None) @validator def between( value: PossibleValueTypes, /, *, min_val: Union[PossibleValueTypes, AbsMin, None] = None, max_val: Union[PossibleValueTypes, AbsMax, None] = None, ): """Validate that a number is between minimum and/or maximum value. This will work with any comparable type, such as floats, decimals and dates not just integers. This validator is originally based on [WTForms-NumberRange-Validator][1]. [1]: https://github.com/wtforms/wtforms/blob/master/src/wtforms/validators.py#L166-L220 Examples: >>> from datetime import datetime >>> between(5, min_val=2) # Output: True >>> between(13.2, min_val=13, max_val=14) # Output: True >>> between(500, max_val=400) # Output: ValidationError(func=between, args=...) >>> between( ... datetime(2000, 11, 11), ... min_val=datetime(1999, 11, 11) ... ) # Output: True Args: value: Value which is to be compared. min_val: The minimum required value of the number. If not provided, minimum value will not be checked. max_val: The maximum value of the number. If not provided, maximum value will not be checked. Returns: (Literal[True]): If `value` is in between the given conditions. (ValidationError): If `value` is not in between the given conditions. Raises: (ValueError): If `min_val` is greater than `max_val`. (TypeError): If there's a type mismatch during comparison. Note: - `PossibleValueTypes` = `TypeVar("PossibleValueTypes", int, float, str, datetime)` - If neither `min_val` nor `max_val` is provided, result will always be `True`. """ if value is None: return False if max_val is None: max_val = AbsMax() if min_val is None: min_val = AbsMin() try: if min_val > max_val: raise ValueError("`min_val` cannot be greater than `max_val`") except TypeError as err: raise TypeError("Comparison type mismatch") from err return min_val <= value <= max_val