From cc1864286dbad56966aaf6243ed80723ba795863 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Fri, 11 Nov 2022 20:24:49 -0600 Subject: [PATCH 1/3] Add gzip check to compress method Addresses @zariiii9003 from https://github.com/hardbyte/python-can/pull/1385#issuecomment-1297372655 --- can/io/logger.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/can/io/logger.py b/can/io/logger.py index 09312101b..ac7000339 100644 --- a/can/io/logger.py +++ b/can/io/logger.py @@ -61,6 +61,8 @@ class Logger(MessageWriter): # pylint: disable=abstract-method ".txt": Printer, } + incompatible_gzip = [".blf", ".db"] + @staticmethod def __new__( # type: ignore cls: Any, filename: Optional[StringPathLike], *args: Any, **kwargs: Any @@ -105,6 +107,10 @@ def compress( File will automatically recompress upon close. """ real_suffix = pathlib.Path(filename).suffixes[-2].lower() + if real_suffix in Logger.incompatible_gzip: + raise ValueError( + f"The file type {real_suffix} is currently incompatible with gzip." + ) if kwargs.get("append", False): mode = "ab" if real_suffix == ".blf" else "at" else: From 3dc602819a48f529911cd09f731cf154f8318baf Mon Sep 17 00:00:00 2001 From: Jack Cook Date: Sun, 13 Nov 2022 12:15:47 -0600 Subject: [PATCH 2/3] Update can/io/logger.py Co-authored-by: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> --- can/io/logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/io/logger.py b/can/io/logger.py index ac7000339..b4112f5e8 100644 --- a/can/io/logger.py +++ b/can/io/logger.py @@ -107,7 +107,7 @@ def compress( File will automatically recompress upon close. """ real_suffix = pathlib.Path(filename).suffixes[-2].lower() - if real_suffix in Logger.incompatible_gzip: + if real_suffix in (".blf", ".db"): raise ValueError( f"The file type {real_suffix} is currently incompatible with gzip." ) From 93677ea653cf29885044cdb1d5f847e25695e243 Mon Sep 17 00:00:00 2001 From: Jack Cook Date: Sun, 13 Nov 2022 12:16:17 -0600 Subject: [PATCH 3/3] Update logger.py --- can/io/logger.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/can/io/logger.py b/can/io/logger.py index b4112f5e8..a254fb146 100644 --- a/can/io/logger.py +++ b/can/io/logger.py @@ -61,8 +61,6 @@ class Logger(MessageWriter): # pylint: disable=abstract-method ".txt": Printer, } - incompatible_gzip = [".blf", ".db"] - @staticmethod def __new__( # type: ignore cls: Any, filename: Optional[StringPathLike], *args: Any, **kwargs: Any