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

LeanderCS / flask-inputfilter / #72

18 Jan 2025 10:38PM UTC coverage: 98.065% (-1.2%) from 99.252%
#72

push

coveralls-python

web-flow
Merge pull request #21 from LeanderCS/17

17 | Add new filters and validators

156 of 173 new or added lines in 11 files covered. (90.17%)

1216 of 1240 relevant lines covered (98.06%)

0.98 hits per line

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

93.75
/flask_inputfilter/Filter/ToNormalizedUnicodeFilter.py
1
import unicodedata
1✔
2
from typing import Any, Union
1✔
3

4
from typing_extensions import Literal
1✔
5

6
from ..Enum import UnicodeFormEnum
1✔
7
from .BaseFilter import BaseFilter
1✔
8

9

10
class ToNormalizedUnicodeFilter(BaseFilter):
1✔
11
    """
12
    Filter that normalizes a string to a specified Unicode form.
13
    """
14

15
    def __init__(
1✔
16
        self,
17
        form: Union[
18
            UnicodeFormEnum, Literal["NFC", "NFD", "NFKC", "NFKD"]
19
        ] = UnicodeFormEnum.NFC,
20
    ) -> None:
21
        if not isinstance(form, UnicodeFormEnum):
1✔
NEW
22
            form = UnicodeFormEnum(form)
×
23

24
        self.form = form
1✔
25

26
    def apply(self, value: Any) -> Union[str, Any]:
1✔
27
        if not isinstance(value, str):
1✔
28
            return value
1✔
29

30
        value = unicodedata.normalize(self.form.value, value)
1✔
31

32
        value_without_accents = "".join(
1✔
33
            char
34
            for char in unicodedata.normalize(UnicodeFormEnum.NFD.value, value)
35
            if unicodedata.category(char) != "Mn"
36
        )
37

38
        return unicodedata.normalize(self.form.value, value_without_accents)
1✔
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