Debian Codegraph @

src/whitenoise/string_utils.py

raw
1 from __future__ import annotations
2
3
4 # Follow Django in treating URLs as UTF-8 encoded (which requires undoing the
5 # implicit ISO-8859-1 decoding applied in Python 3). Strictly speaking, URLs
6 # should only be ASCII anyway, but UTF-8 can be found in the wild.
7 def decode_path_info(path_info):
8 return path_info.encode("iso-8859-1", "replace").decode("utf-8", "replace")
9
10
11 def ensure_leading_trailing_slash(path):
12 path = (path or "").strip("/")
13 return f"/{path}/" if path else "/"