Parse an int only if it is only ASCII digits and ``-``. This disallows ``+``, ``_``, and non-ASCII digits, which are accepted by ``int`` but are not allowed in HTTP header values. Any leading or trailing whitespace is stripped
(value: str)
| 197 | |
| 198 | |
| 199 | def _plain_int(value: str) -> int: |
| 200 | """Parse an int only if it is only ASCII digits and ``-``. |
| 201 | |
| 202 | This disallows ``+``, ``_``, and non-ASCII digits, which are accepted by ``int`` but |
| 203 | are not allowed in HTTP header values. |
| 204 | |
| 205 | Any leading or trailing whitespace is stripped |
| 206 | """ |
| 207 | value = value.strip() |
| 208 | if _plain_int_re.fullmatch(value) is None: |
| 209 | raise ValueError |
| 210 | |
| 211 | return int(value) |
no outgoing calls
no test coverage detected