From 2ce17526121833f179d3cd8aeacf5fc9578f61c3 Mon Sep 17 00:00:00 2001 From: Marc Zuo <680830-timippos@users.noreply.gitlab.com> Date: Tue, 7 May 2024 18:19:26 -0400 Subject: [PATCH 1/3] Fix UnicodeEncodeError exception handling (#160) When build_cache() encounters a UnicodeEncodeError, the original code did not escape unprintable chars and caused the cache build to fail. This patch fixes the code so that the culprit is correctly printed in debug mode. --- src/dmenu_extended/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dmenu_extended/main.py b/src/dmenu_extended/main.py index 1d786bd..4c24fb1 100755 --- a/src/dmenu_extended/main.py +++ b/src/dmenu_extended/main.py @@ -786,11 +786,11 @@ def cache_save(self, items, path): for item in items: clean = True for char in item: - if char not in string.printable: + if not str.isprintable(char): clean = False foundError = True if self.debug: - print("Culprit: " + item) + print("Culprit: " + item.encode('unicode_escape').decode("utf-8")) if clean: tmp.append(item) if foundError: @@ -802,7 +802,7 @@ def cache_save(self, items, path): print("Offending items have been excluded from cache") with open(path, "wb") as f: for item in tmp: - f.write(item + "\n") + f.write(item.encode('unicode_escape') + b"\n") return 2 else: if self.debug: From c4ebb27b47029832c00a9168816011a0505d4fff Mon Sep 17 00:00:00 2001 From: Marc Zuo <680830-timippos@users.noreply.gitlab.com> Date: Tue, 7 May 2024 18:31:47 -0400 Subject: [PATCH 2/3] Incrementing version string (1.2.1 -> 1.2.2) --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c85417a..0846f70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "dmenu_extended" -version = "1.2.1" +version = "1.2.2" authors = [ { name="Mark Hedley Jones", email="markhedleyjones@gmail.com" }, ] From 24e8b40979867ef11469bbbe9b589649e9f56486 Mon Sep 17 00:00:00 2001 From: Marc Zuo <680830-timippos@users.noreply.gitlab.com> Date: Fri, 31 May 2024 17:03:28 -0400 Subject: [PATCH 3/3] Reformatted code using pyblack --- src/dmenu_extended/main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/dmenu_extended/main.py b/src/dmenu_extended/main.py index 36d1b0c..45b53a4 100755 --- a/src/dmenu_extended/main.py +++ b/src/dmenu_extended/main.py @@ -790,7 +790,10 @@ def cache_save(self, items, path): clean = False foundError = True if self.debug: - print("Culprit: " + item.encode('unicode_escape').decode("utf-8")) + print( + "Culprit: " + + item.encode("unicode_escape").decode("utf-8") + ) if clean: tmp.append(item) if foundError: @@ -802,7 +805,7 @@ def cache_save(self, items, path): print("Offending items have been excluded from cache") with open(path, "wb") as f: for item in tmp: - f.write(item.encode('unicode_escape') + b"\n") + f.write(item.encode("unicode_escape") + b"\n") return 2 else: if self.debug: