(self, value: _HeaderTypes)
| 399 | _INVALID_HEADER_CHAR_RE = re.compile(r"[\x00-\x1f]") |
| 400 | |
| 401 | def _convert_header_value(self, value: _HeaderTypes) -> str: |
| 402 | # Convert the input value to a str. This type check is a bit |
| 403 | # subtle: The bytes case only executes on python 3, and the |
| 404 | # unicode case only executes on python 2, because the other |
| 405 | # cases are covered by the first match for str. |
| 406 | if isinstance(value, str): |
| 407 | retval = value |
| 408 | elif isinstance(value, bytes): |
| 409 | # Non-ascii characters in headers are not well supported, |
| 410 | # but if you pass bytes, use latin1 so they pass through as-is. |
| 411 | retval = value.decode("latin1") |
| 412 | elif isinstance(value, numbers.Integral): |
| 413 | # return immediately since we know the converted value will be safe |
| 414 | return str(value) |
| 415 | elif isinstance(value, datetime.datetime): |
| 416 | return httputil.format_timestamp(value) |
| 417 | else: |
| 418 | raise TypeError("Unsupported header value %r" % value) |
| 419 | # If \n is allowed into the header, it is possible to inject |
| 420 | # additional headers or split the request. |
| 421 | if RequestHandler._INVALID_HEADER_CHAR_RE.search(retval): |
| 422 | raise ValueError("Unsafe header value %r", retval) |
| 423 | return retval |
| 424 | |
| 425 | @overload |
| 426 | def get_argument(self, name: str, default: str, strip: bool = True) -> str: |
no outgoing calls
no test coverage detected