31 def appropriate_for(cls, file_content: str) -> "EscapeLeadingWhitespace":
32 MIXED = "m"
33 common_whitespace = None
34
35 for line in file_content.splitlines():
36 whitespace = "".join(c for c in line if c.isspace())
37 if not whitespace:
38 continue
39 elif all(c == " " for c in whitespace):
40 whitespace = " "
41 elif all(c == "\t" for c in whitespace):
42 whitespace = "\t"
43 else:
44 whitespace = MIXED
45
46 if common_whitespace is None:
47 common_whitespace = whitespace
48 elif common_whitespace != whitespace:
49 common_whitespace = MIXED
50 break
51
52 if common_whitespace == " ":
53 return cls.ONLY_ON_TAB
54 elif common_whitespace == "\t":
55 return cls.ONLY_ON_SPACE
56 else:
57 return cls.ALWAYS