aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/gcode.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2021-10-31 13:39:01 -0400
committerKevin O'Connor <kevin@koconnor.net>2021-10-31 13:51:52 -0400
commitd6c3aaad8af18e792ce7cfad720138dc26c782bd (patch)
treeb13b847068e21545833c981be6cb5bb679d87a06 /klippy/gcode.py
parent85d0ef974cfcc18606c5c95c3bf4c76cc18cc22e (diff)
downloadkutter-d6c3aaad8af18e792ce7cfad720138dc26c782bd.tar.gz
kutter-d6c3aaad8af18e792ce7cfad720138dc26c782bd.tar.xz
kutter-d6c3aaad8af18e792ce7cfad720138dc26c782bd.zip
gcode: Use regular str() types for g-code commands on Python2
Avoid using unicode() types on Python2 as it can lead to subtle errors. Also, accept utf8 on gcode input (instead of just ascii). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/gcode.py')
-rw-r--r--klippy/gcode.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/klippy/gcode.py b/klippy/gcode.py
index 17bf17e4..e1769e47 100644
--- a/klippy/gcode.py
+++ b/klippy/gcode.py
@@ -381,13 +381,13 @@ class GCodeIO:
def _process_data(self, eventtime):
# Read input, separate by newline, and add to pending_commands
try:
- data = os.read(self.fd, 4096)
- except os.error:
+ data = str(os.read(self.fd, 4096).decode('utf8'))
+ except os.error, UnicodeDecodeError:
logging.exception("Read g-code")
return
self.input_log.append((eventtime, data))
self.bytes_read += len(data)
- lines = data.decode().split('\n')
+ lines = data.split('\n')
lines[0] = self.partial_input + lines[0]
self.partial_input = lines.pop()
pending_commands = self.pending_commands