Normalizes template text by correcting \r\n, tabs and BOM chars.
(text)
| 965 | return f"<{self.__class__.__name__} {self.filename}>" |
| 966 | |
| 967 | def normalize_text(text): |
| 968 | """Normalizes template text by correcting \r\n, tabs and BOM chars.""" |
| 969 | text = text.replace("\r\n", "\n").replace("\r", "\n").expandtabs() |
| 970 | if not text.endswith("\n"): |
| 971 | text += "\n" |
| 972 | |
| 973 | # ignore BOM chars at the beginning of template |
| 974 | BOM = "\xef\xbb\xbf" |
| 975 | if isinstance(text, str) and text.startswith(BOM): |
| 976 | text = text[len(BOM) :] |
| 977 | |
| 978 | # support fort \$ for backward-compatibility |
| 979 | text = text.replace(r"\$", "$$") |
| 980 | return text |
| 981 | |
| 982 | normalize_text = staticmethod(normalize_text) |
| 983 |
no outgoing calls
no test coverage detected