Skip to content

Commit 54eb413

Browse files
[pre-commit.ci lite] apply automatic fixes
1 parent 449af6d commit 54eb413

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

src/flask_wtf/csrf.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
import hmac
33
import logging
44
import os
5-
from typing import Any, Callable, Optional, Union, TypeVar
5+
from typing import Any
6+
from typing import Callable
7+
from typing import Optional
8+
from typing import TypeVar
9+
from typing import Union
610
from urllib.parse import urlparse
711

8-
from flask import Blueprint, Flask
12+
from flask import Blueprint
913
from flask import current_app
14+
from flask import Flask
1015
from flask import g
1116
from flask import request
1217
from flask import session
@@ -20,10 +25,12 @@
2025
__all__ = ("generate_csrf", "validate_csrf", "CSRFProtect")
2126
logger = logging.getLogger(__name__)
2227

23-
F = TypeVar('F', bound=Callable[..., object])
28+
F = TypeVar("F", bound=Callable[..., object])
2429

2530

26-
def generate_csrf(secret_key: Optional[str] = None, token_key: Optional[str] = None) -> str:
31+
def generate_csrf(
32+
secret_key: Optional[str] = None, token_key: Optional[str] = None
33+
) -> str:
2734
"""Generate a CSRF token. The token is cached for a request, so multiple
2835
calls to this function will generate the same token.
2936
@@ -66,7 +73,12 @@ def generate_csrf(secret_key: Optional[str] = None, token_key: Optional[str] = N
6673
return g.get(field_name)
6774

6875

69-
def validate_csrf(data: str, secret_key: Optional[str] = None, time_limit: Optional[int] = None, token_key: Optional[str] = None) -> None:
76+
def validate_csrf(
77+
data: str,
78+
secret_key: Optional[str] = None,
79+
time_limit: Optional[int] = None,
80+
token_key: Optional[str] = None,
81+
) -> None:
7082
"""Check if the given data is a valid CSRF token. This compares the given
7183
signed token to the one stored in the session.
7284
@@ -119,7 +131,11 @@ def validate_csrf(data: str, secret_key: Optional[str] = None, time_limit: Optio
119131

120132

121133
def _get_config(
122-
value: Any, config_name: str, default: Any = None, required: bool = True, message: str = "CSRF is not configured."
134+
value: Any,
135+
config_name: str,
136+
default: Any = None,
137+
required: bool = True,
138+
message: str = "CSRF is not configured.",
123139
) -> Any:
124140
"""Find config value based on provided value, Flask config, and default
125141
value.

src/flask_wtf/file.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from collections import abc
2-
from typing import Any, Optional, Union
2+
from typing import Any
3+
from typing import Optional
4+
from typing import Union
35

46
from werkzeug.datastructures import FileStorage
7+
from wtforms import Field
58
from wtforms import FileField as _FileField
9+
from wtforms import Form
610
from wtforms import MultipleFileField as _MultipleFileField
7-
from wtforms import Form, Field
811
from wtforms.validators import DataRequired
912
from wtforms.validators import StopValidation
1013
from wtforms.validators import ValidationError
@@ -72,7 +75,9 @@ class FileAllowed:
7275
You can also use the synonym ``file_allowed``.
7376
"""
7477

75-
def __init__(self, upload_set: Union[list[str], Any], message: Optional[str] = None) -> None:
78+
def __init__(
79+
self, upload_set: Union[list[str], Any], message: Optional[str] = None
80+
) -> None:
7681
self.upload_set = upload_set
7782
self.message = message
7883

@@ -118,7 +123,9 @@ class FileSize:
118123
You can also use the synonym ``file_size``.
119124
"""
120125

121-
def __init__(self, max_size: int, min_size: int = 0, message: Optional[str] = None) -> None:
126+
def __init__(
127+
self, max_size: int, min_size: int = 0, message: Optional[str] = None
128+
) -> None:
122129
self.min_size = min_size
123130
self.max_size = max_size
124131
self.message = message

src/flask_wtf/form.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from typing import Any, Generator, Optional, TypeVar, Union
1+
from collections.abc import Generator
2+
from typing import Any
3+
from typing import Optional
4+
from typing import TypeVar
5+
from typing import Union
6+
27
from flask import current_app
38
from flask import request
49
from flask import session
@@ -21,8 +26,9 @@
2126
SUBMIT_METHODS = {"POST", "PUT", "PATCH", "DELETE"}
2227
_Auto = object()
2328

24-
_AutoType = TypeVar('_AutoType', bound=object)
25-
T = TypeVar('T', bound='FlaskForm')
29+
_AutoType = TypeVar("_AutoType", bound=object)
30+
T = TypeVar("T", bound="FlaskForm")
31+
2632

2733
class FlaskForm(Form):
2834
"""Flask-specific subclass of WTForms :class:`~wtforms.form.Form`.
@@ -52,7 +58,11 @@ def csrf_field_name(self) -> str:
5258
def csrf_time_limit(self) -> int:
5359
return current_app.config.get("WTF_CSRF_TIME_LIMIT", 3600)
5460

55-
def wrap_formdata(self, form: 'FlaskForm', formdata: Union[_AutoType, CombinedMultiDict, ImmutableMultiDict, None]) -> Optional[Union[CombinedMultiDict, ImmutableMultiDict]]:
61+
def wrap_formdata(
62+
self,
63+
form: "FlaskForm",
64+
formdata: Union[_AutoType, CombinedMultiDict, ImmutableMultiDict, None],
65+
) -> Optional[Union[CombinedMultiDict, ImmutableMultiDict]]:
5666
if formdata is _Auto:
5767
if _is_submitted():
5868
if request.files:
@@ -66,7 +76,7 @@ def wrap_formdata(self, form: 'FlaskForm', formdata: Union[_AutoType, CombinedMu
6676

6777
return formdata
6878

69-
def get_translations(self, form: 'FlaskForm') -> Optional[Any]:
79+
def get_translations(self, form: "FlaskForm") -> Optional[Any]:
7080
if not current_app.config.get("WTF_I18N_ENABLED", True):
7181
return super().get_translations(form)
7282

@@ -82,7 +92,9 @@ def is_submitted(self) -> bool:
8292

8393
return _is_submitted()
8494

85-
def validate_on_submit(self, extra_validators: Optional[dict[str, Any]] = None) -> bool:
95+
def validate_on_submit(
96+
self, extra_validators: Optional[dict[str, Any]] = None
97+
) -> bool:
8698
"""Call :meth:`validate` only if the form is submitted.
8799
This is a shortcut for ``form.is_submitted() and form.validate()``.
88100
"""

0 commit comments

Comments
 (0)