This repository was archived by the owner on Mar 2, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 1
1
import os
2
+ import unicodedata
2
3
4
+ _windows_device_files = {
5
+ "CON" ,
6
+ "PRN" ,
7
+ "AUX" ,
8
+ "NUL" ,
9
+ * (f"COM{ i } " for i in range (10 )),
10
+ * (f"LPT{ i } " for i in range (10 )),
11
+ }
12
+
13
+
14
+ def secure_filename (filename : str ) -> str :
15
+ """Convert your filename to be safe for the os.
16
+
17
+ Function from werkzeug. Changed to allow space in the file name.
18
+ """
19
+ filename = unicodedata .normalize ("NFKD" , filename )
20
+ filename = filename .encode ("ascii" , "ignore" ).decode ("ascii" )
21
+ for sep in os .sep , os .path .altsep :
22
+ if sep :
23
+ filename = filename .replace (sep , "_" )
24
+ filename = filename .strip ("._" )
25
+ # on nt a couple of special files are present in each folder. We
26
+ # have to ensure that the target file is not such a filename. In
27
+ # this case we prepend an underline
28
+ if (
29
+ os .name == "nt"
30
+ and filename
31
+ and filename .split ("." )[0 ].upper () in _windows_device_files
32
+ ):
33
+ filename = f"_{ filename } "
34
+
35
+ return filename
3
36
4
37
def pathify (path1 , path2 ):
5
38
"""
Original file line number Diff line number Diff line change 22
22
url_for ,
23
23
)
24
24
from lxml .html .clean import clean_html
25
- from werkzeug .utils import safe_join , secure_filename
25
+ from werkzeug .utils import safe_join
26
26
from wikmd import knowledge_graph
27
27
from wikmd .cache import Cache
28
28
from wikmd .config import WikmdConfig
29
29
from wikmd .git_manager import WikiRepoManager
30
30
from wikmd .image_manager import ImageManager
31
31
from wikmd .plugins .load_plugins import PluginLoader
32
32
from wikmd .search import Search , Watchdog
33
- from wikmd .utils import pathify
33
+ from wikmd .utils import pathify , secure_filename
34
34
from wikmd .web_dependencies import get_web_deps
35
35
36
36
SESSIONS = []
You can’t perform that action at this time.
0 commit comments