From 66b908552e34b5bd08ef1ef8ac7fff92f3d26823 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 13 Aug 2015 18:37:55 +0530 Subject: [PATCH] Avoid compiling filename sanitization regex during application startup Since the regex module uses an internal cache there should be no significant performance impact when sending files. --- src/calibre/devices/kobo/driver.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 7663c8535d..38bc770c54 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -144,8 +144,6 @@ class KOBO(USBMS): OPT_SHOW_PREVIEWS = 4 OPT_SHOW_RECOMMENDATIONS = 5 OPT_SUPPORT_NEWER_FIRMWARE = 6 - - invalid_filename_chars_re = re.compile(r'[\/\\\?%\*:;\|\"\'><\$!]', re.IGNORECASE | re.UNICODE) def initialize(self): USBMS.initialize(self) @@ -155,7 +153,8 @@ class KOBO(USBMS): return self.normalize_path(self._main_prefix + '.kobo/KoboReader.sqlite') def sanitize_path_components(self, components): - return [self.invalid_filename_chars_re.sub('_', x) for x in components] + invalid_filename_chars_re = re.compile(r'[\/\\\?%\*:;\|\"\'><\$!]', re.IGNORECASE | re.UNICODE) + return [invalid_filename_chars_re.sub('_', x) for x in components] def books(self, oncard=None, end_session=True): from calibre.ebooks.metadata.meta import path_to_ext