Skip to content

Commit 1a62039

Browse files
committed
capitalize CSRFProtect
1 parent b16ba41 commit 1a62039

File tree

7 files changed

+40
-16
lines changed

7 files changed

+40
-16
lines changed

docs/api.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ CSRF Protection
3131

3232
.. module:: flask_wtf.csrf
3333

34-
.. autoclass:: CsrfProtect
34+
.. autoclass:: CSRFProtect
3535
:members:
3636

37+
.. autoclass:: CsrfProtect(...)
38+
3739
.. autoclass:: CSRFError
3840
:members:
3941

docs/changelog.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ In development
3333

3434
- Provide ``WTF_CSRF_FIELD_NAME`` to configure the name of the CSRF token.
3535
(`#271`_)
36-
- ``CsrfError`` is renamed to ``CSRFError``. (`#271`_)
3736
- ``validate_csrf`` raises ``wtforms.ValidationError`` with specific messages
3837
instead of returning ``True`` or ``False``. This breaks anything that was
3938
calling the method directly. (`#239`_, `#271`_)
4039

4140
- CSRF errors are logged as well as raised. (`#239`_)
4241

42+
- ``CsrfProtect`` is renamed to ``CSRFProtect``. A deprecation warning is issued
43+
when using the old name. ``CsrfError`` is renamed to ``CSRFError`` without
44+
deprecation. (`#271`_)
45+
4346
.. _`#200`: https://github.com/lepture/flask-wtf/issues/200
4447
.. _`#209`: https://github.com/lepture/flask-wtf/pull/209
4548
.. _`#216`: https://github.com/lepture/flask-wtf/issues/216

docs/csrf.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
CSRF Protection
66
===============
77

8-
Any view using :class:`flask_wtf.FlaskForm` to process the request is already
8+
Any view using :class:`~flask_wtf.FlaskForm` to process the request is already
99
getting CSRF protection. If you have views that don't use ``FlaskForm`` or make
1010
AJAX requests, use the provided CSRF extension to protect those requests as
1111
well.
@@ -14,15 +14,15 @@ Setup
1414
-----
1515

1616
To enable CSRF protection globally for a Flask app, register the
17-
:class:`CsrfProtect` extension. ::
17+
:class:`CSRFProtect` extension. ::
1818

19-
from flask_wtf.csrf import CsrfProtect
19+
from flask_wtf.csrf import CSRFProtect
2020

21-
csrf = CsrfProtect(app)
21+
csrf = CSRFProtect(app)
2222

2323
Like other Flask extensions, you can apply it lazily::
2424

25-
csrf = CsrfProtect()
25+
csrf = CSRFProtect()
2626

2727
def create_app():
2828
app = Flask(__name__)
@@ -82,7 +82,7 @@ By default this returns a response with the failure reason and a 400 code.
8282
You can customize the error response using Flask's
8383
:meth:`~flask.Flask.errorhandler`. ::
8484

85-
from flask_wtf.csrf import CsrfError
85+
from flask_wtf.csrf import CSRFError
8686

8787
@app.errorhandler(CsrfError)
8888
def handle_csrf_error(e):
@@ -106,7 +106,7 @@ You can exclude all the views of a blueprint. ::
106106

107107
You can disable CSRF protection in all views by default, by setting
108108
``WTF_CSRF_CHECK_DEFAULT`` to ``False``, and selectively call
109-
``csrf.protect()`` only when you need. This also enables you to do some
109+
:meth:`~flask_wtf.csrf.CSRFProtect.protect` only when you need. This also enables you to do some
110110
pre-processing on the requests before checking for the CSRF token. ::
111111

112112
@app.before_request

flask_wtf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# flake8: noqa
1313
from __future__ import absolute_import
1414

15-
from .csrf import CsrfProtect
15+
from .csrf import CSRFProtect, CsrfProtect
1616
from .form import FlaskForm, Form
1717
from .recaptcha import *
1818

flask_wtf/csrf.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from ._compat import FlaskWTFDeprecationWarning, string_types, urlparse
1515

16-
__all__ = ('generate_csrf', 'validate_csrf', 'CsrfProtect')
16+
__all__ = ('generate_csrf', 'validate_csrf', 'CSRFProtect')
1717
logger = logging.getLogger(__name__)
1818

1919

@@ -147,7 +147,7 @@ def validate_csrf_token(self, form, field):
147147
raise
148148

149149

150-
class CsrfProtect(object):
150+
class CSRFProtect(object):
151151
"""Enable CSRF protection globally for a Flask app.
152152
153153
::
@@ -324,6 +324,20 @@ def handler(reason):
324324
return view
325325

326326

327+
class CsrfProtect(CSRFProtect):
328+
"""
329+
.. deprecated:: 0.14
330+
Renamed to :class:`~flask_wtf.csrf.CSRFProtect`.
331+
"""
332+
333+
def __init__(self, app=None):
334+
warnings.warn(FlaskWTFDeprecationWarning(
335+
'"flask_wtf.CsrfProtect" has been renamed to "CSRFProtect" '
336+
'and will be removed in 1.0.'
337+
), stacklevel=2)
338+
super(CsrfProtect, self).__init__(app=app)
339+
340+
327341
class CSRFError(BadRequest):
328342
"""Raise if the client sends invalid CSRF data with the request.
329343

tests/test_csrf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
from wtforms import ValidationError
88

99
from flask_wtf._compat import FlaskWTFDeprecationWarning
10-
from flask_wtf.csrf import CSRFError, CsrfProtect, generate_csrf, validate_csrf
10+
from flask_wtf.csrf import CSRFError, CSRFProtect, generate_csrf, validate_csrf
1111
from .base import MyForm, TestCase
1212

1313

1414
class TestCSRF(TestCase):
1515
def setUp(self):
1616
app = self.create_app()
1717
app.config['WTF_CSRF_SECRET_KEY'] = "a poorly kept secret."
18-
csrf = CsrfProtect(app)
18+
csrf = CSRFProtect(app)
1919
self.csrf = csrf
2020

2121
@csrf.exempt

tests/test_form.py renamed to tests/test_deprecated.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from wtforms.compat import with_metaclass
55
from wtforms.form import FormMeta
66

7-
from flask_wtf import FlaskForm, Form
7+
from flask_wtf import CsrfProtect, FlaskForm, Form
88
from flask_wtf._compat import FlaskWTFDeprecationWarning
99

1010

11-
class TestForm(TestCase):
11+
class TestDeprecated(TestCase):
1212
def test_deprecated_form(self):
1313
with warnings.catch_warnings():
1414
warnings.simplefilter('error', FlaskWTFDeprecationWarning)
@@ -38,3 +38,8 @@ class F(FlaskForm):
3838
with warnings.catch_warnings():
3939
warnings.simplefilter('error', FlaskWTFDeprecationWarning)
4040
self.assertRaises(FlaskWTFDeprecationWarning, F, csrf_enabled=False)
41+
42+
def test_deprecated_csrfprotect(self):
43+
with warnings.catch_warnings():
44+
warnings.simplefilter('error', FlaskWTFDeprecationWarning)
45+
self.assertRaises(FlaskWTFDeprecationWarning, CsrfProtect)

0 commit comments

Comments
 (0)