Skip to content

Commit e0c27a1

Browse files
[pre-commit.ci lite] apply automatic fixes
1 parent cd85cea commit e0c27a1

File tree

3 files changed

+55
-16
lines changed

3 files changed

+55
-16
lines changed

src/flask_wtf/csrf.py

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

8-
from flask import Blueprint, Flask
13+
from flask import Blueprint
914
from flask import current_app
15+
from flask import Flask
1016
from flask import g
1117
from flask import request
1218
from flask import session
@@ -20,10 +26,12 @@
2026
__all__ = ("generate_csrf", "validate_csrf", "CSRFProtect")
2127
logger = logging.getLogger(__name__)
2228

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

2531

26-
def generate_csrf(secret_key: Optional[str] = None, token_key: Optional[str] = None) -> str:
32+
def generate_csrf(
33+
secret_key: Optional[str] = None, token_key: Optional[str] = None
34+
) -> str:
2735
"""Generate a CSRF token. The token is cached for a request, so multiple
2836
calls to this function will generate the same token.
2937
@@ -66,7 +74,12 @@ def generate_csrf(secret_key: Optional[str] = None, token_key: Optional[str] = N
6674
return g.get(field_name)
6775

6876

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

120133

121134
def _get_config(
122-
value: Any, config_name: str, default: Any = None, required: bool = True, message: str = "CSRF is not configured."
135+
value: Any,
136+
config_name: str,
137+
default: Any = None,
138+
required: bool = True,
139+
message: str = "CSRF is not configured.",
123140
) -> Any:
124141
"""Find config value based on provided value, Flask config, and default
125142
value.

src/flask_wtf/file.py

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

47
from werkzeug.datastructures import FileStorage
8+
from wtforms import Field
59
from wtforms import FileField as _FileField
10+
from wtforms import Form
611
from wtforms import MultipleFileField as _MultipleFileField
7-
from wtforms import Form, Field
812
from wtforms.validators import DataRequired
913
from wtforms.validators import StopValidation
1014
from wtforms.validators import ValidationError
@@ -72,7 +76,9 @@ class FileAllowed:
7276
You can also use the synonym ``file_allowed``.
7377
"""
7478

75-
def __init__(self, upload_set: Union[List[str], Any], message: Optional[str] = None) -> None:
79+
def __init__(
80+
self, upload_set: Union[List[str], Any], message: Optional[str] = None
81+
) -> None:
7682
self.upload_set = upload_set
7783
self.message = message
7884

@@ -118,7 +124,9 @@ class FileSize:
118124
You can also use the synonym ``file_size``.
119125
"""
120126

121-
def __init__(self, max_size: int, min_size: int = 0, message: Optional[str] = None) -> None:
127+
def __init__(
128+
self, max_size: int, min_size: int = 0, message: Optional[str] = None
129+
) -> None:
122130
self.min_size = min_size
123131
self.max_size = max_size
124132
self.message = message

src/flask_wtf/form.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
from typing import Any, Dict, Generator, Optional, Type, TypeVar, Union
1+
from collections.abc import Generator
2+
from typing import Any
3+
from typing import Dict
4+
from typing import Optional
5+
from typing import Type
6+
from typing import TypeVar
7+
from typing import Union
8+
29
from flask import current_app
310
from flask import request
411
from flask import session
@@ -21,8 +28,9 @@
2128
SUBMIT_METHODS = {"POST", "PUT", "PATCH", "DELETE"}
2229
_Auto = object()
2330

24-
_AutoType = TypeVar('_AutoType', bound=object)
25-
T = TypeVar('T', bound='FlaskForm')
31+
_AutoType = TypeVar("_AutoType", bound=object)
32+
T = TypeVar("T", bound="FlaskForm")
33+
2634

2735
class FlaskForm(Form):
2836
"""Flask-specific subclass of WTForms :class:`~wtforms.form.Form`.
@@ -52,7 +60,11 @@ def csrf_field_name(self) -> str:
5260
def csrf_time_limit(self) -> int:
5361
return current_app.config.get("WTF_CSRF_TIME_LIMIT", 3600)
5462

55-
def wrap_formdata(self, form: 'FlaskForm', formdata: Union[_AutoType, CombinedMultiDict, ImmutableMultiDict, None]) -> Optional[Union[CombinedMultiDict, ImmutableMultiDict]]:
63+
def wrap_formdata(
64+
self,
65+
form: "FlaskForm",
66+
formdata: Union[_AutoType, CombinedMultiDict, ImmutableMultiDict, None],
67+
) -> Optional[Union[CombinedMultiDict, ImmutableMultiDict]]:
5668
if formdata is _Auto:
5769
if _is_submitted():
5870
if request.files:
@@ -66,7 +78,7 @@ def wrap_formdata(self, form: 'FlaskForm', formdata: Union[_AutoType, CombinedMu
6678

6779
return formdata
6880

69-
def get_translations(self, form: 'FlaskForm') -> Optional[Any]:
81+
def get_translations(self, form: "FlaskForm") -> Optional[Any]:
7082
if not current_app.config.get("WTF_I18N_ENABLED", True):
7183
return super().get_translations(form)
7284

@@ -82,7 +94,9 @@ def is_submitted(self) -> bool:
8294

8395
return _is_submitted()
8496

85-
def validate_on_submit(self, extra_validators: Optional[Dict[str, Any]] = None) -> bool:
97+
def validate_on_submit(
98+
self, extra_validators: Optional[Dict[str, Any]] = None
99+
) -> bool:
86100
"""Call :meth:`validate` only if the form is submitted.
87101
This is a shortcut for ``form.is_submitted() and form.validate()``.
88102
"""

0 commit comments

Comments
 (0)