Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/flask_wtf/recaptcha/fields.py: 73%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

11 statements  

1from wtforms.fields import Field 

2 

3from . import widgets 

4from .validators import Recaptcha 

5 

6__all__ = ["RecaptchaField"] 

7 

8 

9class RecaptchaField(Field): 

10 """reCAPTCHA field using :class:`.Recaptcha` as its default validator. 

11 

12 The default validator skips verification when ``current_app.testing`` is 

13 ``True``, so tests don't need a real reCAPTCHA token. 

14 

15 When using a nonce-based Content Security Policy, pass ``nonce`` to 

16 populate the ``nonce`` attribute of the generated ``<script>`` tag. A 

17 zero-argument callable is accepted so the value can be resolved at 

18 render time, e.g. ``nonce=lambda: g.csp_nonce``. 

19 """ 

20 

21 widget = widgets.RecaptchaWidget() 

22 

23 # error message if recaptcha validation fails 

24 recaptcha_error = None 

25 

26 def __init__(self, label="", validators=None, nonce=None, **kwargs): 

27 validators = validators or [Recaptcha()] 

28 self.nonce = nonce 

29 super().__init__(label, validators, **kwargs)