From 13bf8e2e4782f056c4412b6798fc9b5cdc446304 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 24 Jul 2021 12:24:24 -0700 Subject: [PATCH] Improve Windows reserved name check by adding to pathclass. --- voussoirkit/downloady.py | 5 +++-- voussoirkit/pathclass.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/voussoirkit/downloady.py b/voussoirkit/downloady.py index 818738e..3a39130 100644 --- a/voussoirkit/downloady.py +++ b/voussoirkit/downloady.py @@ -27,9 +27,10 @@ CHUNKSIZE = 4 * bytestring.KIBIBYTE TIMEOUT = 60 TEMP_EXTENSION = '.downloadytemp' -SPECIAL_FILENAMES = [os.devnull] if os.name == 'nt': - SPECIAL_FILENAMES.append('con') + SPECIAL_FILENAMES = pathclass.WINDOWS_RESERVED_NAMES +else: + SPECIAL_FILENAMES = [os.devnull] SPECIAL_FILENAMES = [os.path.normcase(x) for x in SPECIAL_FILENAMES] class DownloadyException(Exception): diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 9a96200..789c230 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -4,7 +4,16 @@ import re from voussoirkit import winglob -WINDOWS_BADCHARS = {'\\', '/', ':', '*', '?', '<', '>', '|', '"'} +WINDOWS_GLOBAL_BADCHARS = {'*', '?', '<', '>', '|', '"'} +WINDOWS_BASENAME_BADCHARS = {'\\', '/', ':', '*', '?', '<', '>', '|', '"'} +WINDOWS_RESERVED_NAMES = { + 'AUX', + 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', + 'CON', + 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9', + 'NUL', + 'PRN', +} class PathclassException(Exception): pass