Escape a string to protect certain characters.
(s, protectables=PROTECTABLES)
| 231 | |
| 232 | |
| 233 | def protect_filename(s, protectables=PROTECTABLES): |
| 234 | """Escape a string to protect certain characters.""" |
| 235 | if set(s) & set(protectables): |
| 236 | if sys.platform == "win32": |
| 237 | return '"' + s + '"' |
| 238 | else: |
| 239 | return "".join(("\\" + c if c in protectables else c) for c in s) |
| 240 | else: |
| 241 | return s |
| 242 | |
| 243 | |
| 244 | def expand_user(path:str) -> Tuple[str, bool, str]: |