From 3ac661cd1fdee619ec25befd20005c7a9cb4bb1e Mon Sep 17 00:00:00 2001 From: tcely Date: Wed, 25 Dec 2024 00:43:44 -0500 Subject: [PATCH] Pulled `glob_quote` from another branch --- tubesync/sync/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tubesync/sync/utils.py b/tubesync/sync/utils.py index 3e29fe3f..e1ab6142 100644 --- a/tubesync/sync/utils.py +++ b/tubesync/sync/utils.py @@ -93,6 +93,20 @@ def resize_image_to_height(image, width, height): return image +def glob_quote(filestr): + _glob_specials = { + '?': '[?]', + '*': '[*]', + '[': '[[]', + ']': '[]]', # probably not needed, but it won't hurt + } + + if not isinstance(filestr, str): + raise TypeError(f'filestr must be a str, got "{type(filestr)}"') + + return filestr.translate(str.maketrans(_glob_specials)) + + def file_is_editable(filepath): ''' Checks that a file exists and the file is in an allowed predefined tuple of