Skip to content

Commit d1c62d7

Browse files
committed
Add google analytics
1 parent 4520e90 commit d1c62d7

File tree

11 files changed

+270
-0
lines changed

11 files changed

+270
-0
lines changed

docs/_static/google-analytics.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
window.dataLayer = window.dataLayer || [];
2+
function gtag(){dataLayer.push(arguments);}
3+
gtag('js', new Date());
4+
gtag('config', 'G-778965FXHK');

docs/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@
1111
html_theme = "sphinx_rtd_theme"
1212
html_static_path = ["_static"]
1313
html_css_files = ["style.css"]
14+
html_js_files = [
15+
(
16+
"https://www.googletagmanager.com/gtag/js?id=G-778965FXHK",
17+
{"async": "async"},
18+
),
19+
("google-analytics.js", {}),
20+
]
21+
html_extra_path = ["_static/google-analytics.js"]
1422
html_theme_options = {"navigation_depth": 4}

docs/options/special_validator.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Special Validator
2+
=================
3+
4+
Special validators are validators that are used to combine or mutate the normal validators.
5+
They are used to create complex validation logic by combining multiple validators or inverting the result of a validator.
6+
7+
Overview
8+
--------
9+
10+
11+
Example
12+
13+
14+
.. code-block:: python
15+
16+
from flask_inputfilter import InputFilter
17+
from flask_inputfilter.Validator import NotValidator, IsIntegerValidator
18+
19+
class NotIntegerInputFilter(InputFilter):
20+
def __init__(self):
21+
super().__init__()
22+
self.add('value', validators=[
23+
NotValidator(validator=IsIntegerValidator())
24+
])
25+
26+
Available Special Validators
27+
----------------------------
28+
29+
The following special validators are available:
30+
31+
- `AndValidator`_
32+
- `IfValidator`_
33+
- `NotValidator`_
34+
- `OrValidator`_
35+
- `XorValidator`_
36+
37+
Detailed Description
38+
--------------------
39+
40+
NotValidator
41+
~~~~~~~~~~~~
42+
**Description:**
43+
44+
Inverts the result of another validator. The validation passes if the inner validator fails, and vice versa.
45+
46+
**Parameters:**
47+
48+
- **validator** (*BaseValidator*): The validator whose outcome is to be inverted.
49+
- **error_message** (*Optional[str]*): Custom error message if the inverted validation does not behave as expected.
50+
51+
**Expected Behavior:**
52+
53+
Executes the inner validator on the input. If the inner validator does not raise a ``ValidationError``, then the NotValidator raises one instead.
54+
55+
**Example Usage:**
56+
57+
.. code-block:: python
58+
59+
from flask_inputfilter import InputFilter
60+
from flask_inputfilter.Validator import NotValidator, IsIntegerValidator
61+
62+
class NotIntegerInputFilter(InputFilter):
63+
def __init__(self):
64+
super().__init__()
65+
self.add('value', validators=[
66+
NotValidator(validator=IsIntegerValidator())
67+
])
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import re
2+
from typing import Any, Optional
3+
4+
from flask_inputfilter.Exception import ValidationError
5+
from flask_inputfilter.Validator import BaseValidator
6+
7+
8+
class IsHtmlValidator(BaseValidator):
9+
"""
10+
Validator that checks if a value contains valid HTML.
11+
"""
12+
13+
def __init__(self, error_message: Optional[str] = None) -> None:
14+
self.error_message = (
15+
error_message or "Value does not contain valid HTML."
16+
)
17+
18+
def validate(self, value: Any) -> None:
19+
if not isinstance(value, str):
20+
raise ValidationError("Value must be a string.")
21+
22+
if not re.search(r"<\s*\w+.*?>", value):
23+
raise ValidationError(self.error_message)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import Any, Optional
2+
3+
from flask_inputfilter.Exception import ValidationError
4+
from flask_inputfilter.Validator import BaseValidator
5+
6+
7+
class IsLowercaseValidator(BaseValidator):
8+
"""
9+
Validator that checks if a value is entirely lowercase.
10+
"""
11+
12+
def __init__(self, error_message: Optional[str] = None) -> None:
13+
self.error_message = (
14+
error_message or "Value is not entirely lowercase."
15+
)
16+
17+
def validate(self, value: Any) -> None:
18+
if not isinstance(value, str):
19+
raise ValidationError("Value must be a string.")
20+
if not value.islower():
21+
raise ValidationError(self.error_message)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import re
2+
from typing import Any, Optional
3+
4+
from flask_inputfilter.Enum import RegexEnum
5+
from flask_inputfilter.Exception import ValidationError
6+
from flask_inputfilter.Validator import BaseValidator
7+
8+
MAC_ADDRESS_PATTERN = re.compile(RegexEnum.MAC_ADDRESS.value)
9+
10+
11+
class IsMacAddressValidator(BaseValidator):
12+
"""
13+
Validator that checks if a value is a valid MAC address.
14+
"""
15+
16+
def __init__(self, error_message: Optional[str] = None) -> None:
17+
self.error_message = (
18+
error_message or "Value is not a valid MAC address."
19+
)
20+
21+
def validate(self, value: Any) -> None:
22+
if not isinstance(value, str):
23+
raise ValidationError("Value must be a string.")
24+
25+
if not MAC_ADDRESS_PATTERN.match(value):
26+
raise ValidationError(self.error_message)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import re
2+
from typing import Any, Optional
3+
4+
from flask_inputfilter.Enum import RegexEnum
5+
from flask_inputfilter.Exception import ValidationError
6+
from flask_inputfilter.Validator import BaseValidator
7+
8+
MIME_TYPE_PATTERN = re.compile(RegexEnum.MIME_TYPE.value, re.IGNORECASE)
9+
10+
11+
class IsMimeTypeValidator(BaseValidator):
12+
"""
13+
Validator that checks if a value is a valid MIME type.
14+
"""
15+
16+
def __init__(self, error_message: Optional[str] = None) -> None:
17+
self.error_message = error_message or "Value is not a valid MIME type."
18+
19+
def validate(self, value: Any) -> None:
20+
if not isinstance(value, str):
21+
raise ValidationError("Value must be a string.")
22+
23+
if not MIME_TYPE_PATTERN.match(value):
24+
raise ValidationError(self.error_message)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import Any, Optional
2+
3+
from flask_inputfilter.Exception import ValidationError
4+
from flask_inputfilter.Validator import BaseValidator
5+
6+
7+
class IsPortValidator(BaseValidator):
8+
"""
9+
Validator that checks if a value is a valid network port (1-65535).
10+
"""
11+
12+
def __init__(self, error_message: Optional[str] = None) -> None:
13+
self.error_message = (
14+
error_message or "Value is not a valid port number."
15+
)
16+
17+
def validate(self, value: Any) -> None:
18+
if not isinstance(value, int):
19+
raise ValidationError("Value must be an integer.")
20+
21+
if not (1 <= value <= 65535):
22+
raise ValidationError(self.error_message)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import re
2+
from typing import Any, Optional
3+
4+
from flask_inputfilter.Enum import RegexEnum
5+
from flask_inputfilter.Exception import ValidationError
6+
from flask_inputfilter.Validator import BaseValidator
7+
8+
RGB_COLOR_PATTERN = re.compile(RegexEnum.RGB_COLOR.value)
9+
10+
11+
class IsRgbColorValidator(BaseValidator):
12+
"""
13+
Validator that checks if a value is a valid RGB color string (e.g., 'rgb(255, 0, 0)').
14+
"""
15+
16+
def __init__(self, error_message: Optional[str] = None) -> None:
17+
self.error_message = error_message or "Value is not a valid RGB color."
18+
19+
def validate(self, value: Any) -> None:
20+
if not isinstance(value, str):
21+
raise ValidationError("Value must be a string.")
22+
23+
match = RGB_COLOR_PATTERN.match(value)
24+
25+
if not match:
26+
raise ValidationError(self.error_message)
27+
28+
r, g, b = map(int, match.groups())
29+
if not (0 <= r <= 255 and 0 <= g <= 255 and 0 <= b <= 255):
30+
raise ValidationError(self.error_message)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import Any, Optional
2+
3+
from flask_inputfilter.Exception import ValidationError
4+
from flask_inputfilter.Validator import BaseValidator
5+
6+
7+
class IsUppercaseValidator(BaseValidator):
8+
"""
9+
Validator that checks if a value is entirely uppercase.
10+
"""
11+
12+
def __init__(self, error_message: Optional[str] = None) -> None:
13+
self.error_message = (
14+
error_message or "Value is not entirely uppercase."
15+
)
16+
17+
def validate(self, value: Any) -> None:
18+
if not isinstance(value, str):
19+
raise ValidationError("Value must be a string.")
20+
21+
if not value.isupper():
22+
raise ValidationError(self.error_message)

0 commit comments

Comments
 (0)