From 34613210850f5110988447d753abdb8b21d087d2 Mon Sep 17 00:00:00 2001 From: Damien LaRocque Date: Sun, 30 Oct 2022 00:21:04 -0300 Subject: [PATCH 1/2] [ros_introspection] Use str instead of unicode in replace_contents --- ros_introspection/src/ros_introspection/source_code_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros_introspection/src/ros_introspection/source_code_file.py b/ros_introspection/src/ros_introspection/source_code_file.py index 41c063d..22f1ec5 100644 --- a/ros_introspection/src/ros_introspection/source_code_file.py +++ b/ros_introspection/src/ros_introspection/source_code_file.py @@ -42,7 +42,7 @@ def get_contents(self): def replace_contents(self, contents): self.changed_contents = contents try: - self.lines = map(unicode.strip, unicode(contents).split('\n')) + self.lines = map(str.strip, str(contents).split('\n')) except NameError: # Python3 Case self.lines = list(map(str.strip, contents.split('\n'))) From 22e84e04cdd6dfc5374820e7232d22dbd1574a45 Mon Sep 17 00:00:00 2001 From: Damien LaRocque Date: Mon, 23 Jan 2023 17:52:57 -0500 Subject: [PATCH 2/2] Catch UnicodeDecodeErrors when parsing source code files --- ros_introspection/src/ros_introspection/source_code_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros_introspection/src/ros_introspection/source_code_file.py b/ros_introspection/src/ros_introspection/source_code_file.py index 22f1ec5..c397fc7 100644 --- a/ros_introspection/src/ros_introspection/source_code_file.py +++ b/ros_introspection/src/ros_introspection/source_code_file.py @@ -43,7 +43,7 @@ def replace_contents(self, contents): self.changed_contents = contents try: self.lines = map(str.strip, str(contents).split('\n')) - except NameError: + except (NameError, UnicodeDecodeError): # Python3 Case self.lines = list(map(str.strip, contents.split('\n')))