• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LeanderCS / flask-inputfilter / #389

24 May 2025 01:01PM UTC coverage: 93.409% (-0.2%) from 93.644%
#389

Pull #56

coveralls-python

LeanderCS
48 | Remove typing_extensions dep
Pull Request #56: 48 | Update ArrayElementValidator and IsDataclassValidator

64 of 73 new or added lines in 4 files covered. (87.67%)

87 existing lines in 18 files now uncovered.

1885 of 2018 relevant lines covered (93.41%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/flask_inputfilter/validators/is_hexadecimal_validator.py
1
from __future__ import annotations
1✔
2

3
from typing import Any, Optional
1✔
4

5
from flask_inputfilter.exceptions import ValidationError
1✔
6
from flask_inputfilter.validators import BaseValidator
1✔
7

8

9
class IsHexadecimalValidator(BaseValidator):
1✔
10
    """
11
    Checks if a given value is a valid hexadecimal string. The input
12
    must be a string that can be converted to an integer using base
13
    16.
14

15
    **Parameters:**
16

17
    - **error_message** (*Optional[str]*): Custom error message if the value is not a valid hexadecimal string.
18

19
    **Expected Behavior:**
20

21
    Verifies that the input is a string and attempts to convert it to an integer using base 16. Raises a ``ValidationError`` if the conversion fails.
22

23
    **Example Usage:**
24

25
    .. code-block:: python
26

27
        class HexInputFilter(InputFilter):
28
            def __init__(self):
29
                super().__init__()
30
                self.add('hex_value', validators=[
31
                    IsHexadecimalValidator()
32
                ])
33
    """
34

35
    __slots__ = ("error_message",)
1✔
36

37
    def __init__(
1✔
38
        self,
39
        error_message: Optional[str] = None,
40
    ) -> None:
41
        self.error_message = error_message
1✔
42

43
    def validate(self, value: Any) -> None:
1✔
44
        if not isinstance(value, str):
1✔
UNCOV
45
            raise ValidationError("Value must be a string.")
×
46

47
        try:
1✔
48
            int(value, 16)
1✔
49

50
        except ValueError:
1✔
51
            raise ValidationError(
1✔
52
                self.error_message
53
                or f"Value '{value}' is not a valid hexadecimal string."
54
            )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc