File: validators.pyi

package info (click to toggle)
python-django-stubs 5.2.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,832 kB
  • sloc: python: 5,185; makefile: 15; sh: 8
file content (158 lines) | stat: -rw-r--r-- 5,104 bytes parent folder | download
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from collections.abc import Callable, Collection, Sequence, Sized
from decimal import Decimal
from re import Pattern, RegexFlag
from typing import Any, TypeAlias

from django.core.files.base import File
from django.utils.deconstruct import _Deconstructible
from django.utils.functional import _StrOrPromise

EMPTY_VALUES: Any

_Regex: TypeAlias = str | Pattern[str]

_ValidatorCallable: TypeAlias = Callable[[Any], None]  # noqa: PYI047

class RegexValidator(_Deconstructible):
    regex: _Regex  # Pattern[str] on instance, but may be str on class definition
    message: _StrOrPromise
    code: str
    inverse_match: bool
    flags: int
    def __init__(
        self,
        regex: _Regex | None = None,
        message: _StrOrPromise | None = None,
        code: str | None = None,
        inverse_match: bool | None = None,
        flags: RegexFlag | None = None,
    ) -> None: ...
    def __call__(self, value: Any) -> None: ...

class DomainNameValidator(RegexValidator):
    ul: str
    hostname_re: str
    domain_re: str
    tld_no_fqdn_re: str
    tld_re: str
    ascii_only_hostname_re: str
    ascii_only_domain_re: str
    ascii_only_tld_re: str
    max_length: int

    def __init__(self, *, accept_idna: bool = True, **kwargs: Any) -> None: ...
    def __call__(self, value: Any) -> None: ...

validate_domain_name: DomainNameValidator

class URLValidator(RegexValidator):
    ul: str
    ipv4_re: str
    ipv6_re: str
    hostname_re: str
    domain_re: str
    tld_re: str
    host_re: str
    schemes: Sequence[str]
    unsafe_chars: frozenset[str]
    max_length: int
    def __init__(self, schemes: Sequence[str] | None = None, **kwargs: Any) -> None: ...
    def __call__(self, value: Any) -> None: ...

integer_validator: RegexValidator

def validate_integer(value: float | str | None) -> None: ...

class EmailValidator(_Deconstructible):
    message: _StrOrPromise
    code: str
    domain_re: str
    hostname_re: str
    tld_no_fqdn_re: str
    user_regex: Pattern[str]
    domain_regex: Pattern[str]
    literal_regex: Pattern[str]
    domain_allowlist: Sequence[str]
    def __init__(
        self,
        message: _StrOrPromise | None = None,
        code: str | None = None,
        allowlist: Sequence[str] | None = None,
    ) -> None: ...
    def __call__(self, value: str | None) -> None: ...
    def validate_domain_part(self, domain_part: str) -> bool: ...
    def __eq__(self, other: object) -> bool: ...

validate_email: EmailValidator
slug_re: Pattern[str]
validate_slug: RegexValidator
slug_unicode_re: Pattern[str]
validate_unicode_slug: RegexValidator

def validate_ipv4_address(value: str) -> None: ...
def validate_ipv6_address(value: str) -> None: ...
def validate_ipv46_address(value: str) -> None: ...

_IPValidator: TypeAlias = tuple[list[Callable[[Any], None]], str]
ip_address_validator_map: dict[str, _IPValidator]

def ip_address_validators(protocol: str, unpack_ipv4: bool) -> _IPValidator: ...
def int_list_validator(
    sep: str = ",", message: _StrOrPromise | None = None, code: str = "invalid", allow_negative: bool = False
) -> RegexValidator: ...

validate_comma_separated_integer_list: RegexValidator

class BaseValidator(_Deconstructible):
    message: _StrOrPromise
    code: str
    limit_value: Any
    def __init__(self, limit_value: Any | Callable[[], Any], message: _StrOrPromise | None = None) -> None: ...
    def __call__(self, value: Any) -> None: ...
    def compare(self, a: Any, b: Any) -> bool: ...
    def clean(self, x: Any) -> Any: ...
    def __eq__(self, other: object) -> bool: ...

class MaxValueValidator(BaseValidator): ...
class MinValueValidator(BaseValidator): ...

class StepValueValidator(BaseValidator):
    offset: int | None
    def __init__(
        self, limit_value: Any | Callable[[], Any], message: _StrOrPromise | None = None, offset: int | None = None
    ) -> None: ...

class MinLengthValidator(BaseValidator):
    def clean(self, x: Sized) -> int: ...

class MaxLengthValidator(BaseValidator):
    def clean(self, x: Sized) -> int: ...

class DecimalValidator(_Deconstructible):
    messages: dict[str, str]
    max_digits: int | None
    decimal_places: int | None
    def __init__(self, max_digits: int | None, decimal_places: int | None) -> None: ...
    def __call__(self, value: Decimal) -> None: ...
    def __eq__(self, other: object) -> bool: ...

class FileExtensionValidator(_Deconstructible):
    message: _StrOrPromise
    code: str
    allowed_extensions: Collection[str] | None
    def __init__(
        self,
        allowed_extensions: Collection[str] | None = None,
        message: _StrOrPromise | None = None,
        code: str | None = None,
    ) -> None: ...
    def __call__(self, value: File) -> None: ...

def get_available_image_extensions() -> Sequence[str]: ...
def validate_image_file_extension(value: File) -> None: ...

class ProhibitNullCharactersValidator(_Deconstructible):
    message: _StrOrPromise
    code: str
    def __init__(self, message: _StrOrPromise | None = None, code: str | None = None) -> None: ...
    def __call__(self, value: Any) -> None: ...