mirror of
https://github.com/hyugogirubato/KeyDive.git
synced 2026-07-16 02:44:22 +02:00
Skip C native functions
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import re
|
||||
from typing import Union
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def sanitize(path: Union[Path, str]) -> Path:
|
||||
if isinstance(path, str):
|
||||
path = Path(path)
|
||||
paths = [path.name, *[p.name for p in path.parents if p.name]][::-1]
|
||||
for i, p in enumerate(paths):
|
||||
p = p.replace('...', '').strip()
|
||||
p = re.sub(r'[<>:"/|?*\x00-\x1F]', '_', p)
|
||||
paths[i] = p
|
||||
|
||||
return Path().joinpath(*paths)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
path = Path() / 'hello rgtgr/sdg'
|
||||
print(path)
|
||||
path = sanitize(path)
|
||||
print(path)
|
||||
Reference in New Issue
Block a user