Beispiel #1
0
def test_replace_chars_windows_override():
    all_chars = "".join(chr(i) for i in range(32)) + "\x7f\"*:/<>?\\|"
    assert replace_chars(all_chars) == "_"
    assert replace_chars(all_chars, "posix") == "_\x7f\"*:_<>?\\|"
    assert replace_chars(all_chars, "unix") == "_\x7f\"*:_<>?\\|"
    assert replace_chars(all_chars, "windows") == "_"
    assert replace_chars(all_chars, "win32") == "_"
Beispiel #2
0
 def filename(self, filename: str, charmap: Optional[str] = None) -> str:
     return self._format(filename, lambda s: replace_chars(s, charmap), {})
Beispiel #3
0
 def path(self, filename, charmap=None):
     # type: (str, Optional[str]) -> str
     return self._format(filename, lambda s: replace_chars(s, charmap), {})
Beispiel #4
0
def test_replace_chars_unprintable(char: int):
    assert replace_chars(f"foo{chr(char)}{chr(char)}bar"
                         ) == "foo_bar", "Replaces unprintable characters"
Beispiel #5
0
def test_replace_chars_replacement():
    assert replace_chars("\x00", None, "+") == "+"
Beispiel #6
0
def test_replace_chars_windows_all():
    assert replace_chars("".join(chr(i) for i in range(32)) +
                         "\x7f\"*/:<>?\\|") == "_"
Beispiel #7
0
def test_replace_chars_posix_all():
    assert replace_chars("".join(chr(i) for i in range(32)) + "/") == "_"
Beispiel #8
0
def test_replace_chars_windows(char: str):
    assert replace_chars(
        f"foo{char}{char}bar"
    ) == "foo_bar", "Replaces multiple unsupported characters in a row"
Beispiel #9
0
 def mapper(s):
     return replace_chars(s, charmap)