Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/wtforms/utils.py: 60%
25 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:32 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:32 +0000
1import re
4# https://docs.python.org/3/library/datetime.html#technical-detail (see NOTE #9)
5_DATETIME_STRIP_ZERO_PADDING_FORMATS_RE = re.compile(
6 "%-["
7 "d" # day of month
8 "m" # month
9 "H" # hour (24-hour)
10 "I" # hour (12-hour)
11 "M" # minutes
12 "S" # seconds
13 "U" # week of year (Sunday first day of week)
14 "W" # week of year (Monday first day of week)
15 "V" # week of year (ISO 8601)
16 "]",
17 re.MULTILINE,
18)
21def clean_datetime_format_for_strptime(formats):
22 """
23 Remove dashes used to disable zero-padding with strftime formats (for
24 compatibility with strptime).
25 """
26 return [
27 re.sub(
28 _DATETIME_STRIP_ZERO_PADDING_FORMATS_RE,
29 lambda m: m[0].replace("-", ""),
30 format,
31 )
32 for format in formats
33 ]
36class UnsetValue:
37 """
38 An unset value.
40 This is used in situations where a blank value like `None` is acceptable
41 usually as the default value of a class variable or function parameter
42 (iow, usually when `None` is a valid value.)
43 """
45 def __str__(self):
46 return "<unset value>"
48 def __repr__(self):
49 return "<unset value>"
51 def __bool__(self):
52 return False
54 def __nonzero__(self):
55 return False
58unset_value = UnsetValue()
61class WebobInputWrapper:
62 """
63 Wrap a webob MultiDict for use as passing as `formdata` to Field.
65 Since for consistency, we have decided in WTForms to support as input a
66 small subset of the API provided in common between cgi.FieldStorage,
67 Django's QueryDict, and Werkzeug's MultiDict, we need to wrap Webob, the
68 only supported framework whose multidict does not fit this API, but is
69 nevertheless used by a lot of frameworks.
71 While we could write a full wrapper to support all the methods, this will
72 undoubtedly result in bugs due to some subtle differences between the
73 various wrappers. So we will keep it simple.
74 """
76 def __init__(self, multidict):
77 self._wrapped = multidict
79 def __iter__(self):
80 return iter(self._wrapped)
82 def __len__(self):
83 return len(self._wrapped)
85 def __contains__(self, name):
86 return name in self._wrapped
88 def getlist(self, name):
89 return self._wrapped.getall(name)