From 1bc3e0a678bd1b27264226c523841b60d7236a45 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 9 Jun 2017 23:32:49 -0400 Subject: [PATCH] klippy: Use newer "except XYZError as e" python syntax Use the newer syntax for python exceptions. Signed-off-by: Kevin O'Connor --- klippy/console.py | 2 +- klippy/gcode.py | 14 +++++++------- klippy/homing.py | 2 +- klippy/klippy.py | 8 ++++---- klippy/mcu.py | 2 +- klippy/serialhdl.py | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/klippy/console.py b/klippy/console.py index 4d68b8de..1645a0be 100755 --- a/klippy/console.py +++ b/klippy/console.py @@ -78,7 +78,7 @@ class KeyboardReader: return None try: msg = self.ser.msgparser.create_command(line) - except msgproto.error, e: + except msgproto.error as e: self.output("Error: %s" % (str(e),)) return None return msg diff --git a/klippy/gcode.py b/klippy/gcode.py index 6709e26f..c6f7248b 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -107,7 +107,7 @@ class GCodeParser: handler = self.gcode_handlers.get(cmd, self.cmd_default) try: handler(params) - except error, e: + except error as e: self.respond_error(str(e)) except: logging.exception("Exception in command handler") @@ -224,7 +224,7 @@ class GCodeParser: print_time = self.toolhead.get_last_move_time() try: heater.set_temp(print_time, temp) - except heater.error, e: + except heater.error as e: self.respond_error(str(e)) return if wait: @@ -264,7 +264,7 @@ class GCodeParser: self.process_commands(deactivate_gcode.split('\n'), need_ack=False) try: self.toolhead.set_extruder(e) - except homing.EndstopError, e: + except homing.EndstopError as e: self.respond_error(str(e)) return self.extruder = e @@ -296,12 +296,12 @@ class GCodeParser: if speed <= 0.: raise ValueError() self.speed = speed - except ValueError, e: + except ValueError as e: self.last_position = self.toolhead.get_position() raise error("Unable to parse move '%s'" % (params['#original'],)) try: self.toolhead.move(self.last_position, self.speed) - except homing.EndstopError, e: + except homing.EndstopError as e: self.respond_error(str(e)) self.last_position = self.toolhead.get_position() def cmd_G4(self, params): @@ -327,7 +327,7 @@ class GCodeParser: homing_state.set_no_verify_retract() try: self.toolhead.home(homing_state) - except homing.EndstopError, e: + except homing.EndstopError as e: self.toolhead.motor_off() self.respond_error(str(e)) return @@ -424,7 +424,7 @@ class GCodeParser: return try: res = self.toolhead.query_endstops() - except self.printer.mcu.error, e: + except self.printer.mcu.error as e: self.respond_error(str(e)) return self.respond(" ".join(["%s:%s" % (name, ["open", "TRIGGERED"][not not t]) diff --git a/klippy/homing.py b/klippy/homing.py index 1e06f0b9..7d4cfb5b 100644 --- a/klippy/homing.py +++ b/klippy/homing.py @@ -43,7 +43,7 @@ class Homing: for s, es, last_pos in endstops: try: es.home_wait() - except es.error, e: + except es.error as e: raise EndstopError("Failed to home stepper %s: %s" % ( s.name, str(e))) post_home_pos = s.mcu_stepper.get_mcu_position() diff --git a/klippy/klippy.py b/klippy/klippy.py index ba5d1762..0cfd79e9 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -61,7 +61,7 @@ class ConfigWrapper: (self.section.lower(), option.lower())] = 1 try: v = parser(self.section, option) - except self.error, e: + except self.error as e: raise except: raise self.error("Unable to parse option '%s' in section '%s'" % ( @@ -199,15 +199,15 @@ class Printer: self.mcu.connect() self.gcode.set_printer_ready(True) self.state_message = message_ready - except ConfigParser.Error, e: + except ConfigParser.Error as e: logging.exception("Config error") self.state_message = "%s%s" % (str(e), message_restart) self.reactor.update_timer(self.stats_timer, self.reactor.NEVER) - except msgproto.error, e: + except msgproto.error as e: logging.exception("Protocol error") self.state_message = "%s%s" % (str(e), message_protocol_error) self.reactor.update_timer(self.stats_timer, self.reactor.NEVER) - except mcu.error, e: + except mcu.error as e: logging.exception("MCU error during connect") self.state_message = "%s%s" % (str(e), message_mcu_connect_error) self.reactor.update_timer(self.stats_timer, self.reactor.NEVER) diff --git a/klippy/mcu.py b/klippy/mcu.py index 5d63af72..e22f6bb6 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -457,7 +457,7 @@ class MCU: self._emergency_stop_cmd = self.lookup_command("emergency_stop") try: self._reset_cmd = self.lookup_command("reset") - except self.serial.msgparser.error, e: + except self.serial.msgparser.error as e: pass self.register_msg(self.handle_shutdown, 'shutdown') self.register_msg(self.handle_shutdown, 'is_shutdown') diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py index d6179a4b..8b99cf25 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -69,7 +69,7 @@ class SerialReader: self.serialport, self.baud, timeout=0) else: self.ser = open(self.serialport, 'rb+') - except (OSError, serial.SerialException), e: + except (OSError, serial.SerialException) as e: logging.warn("Unable to open port: %s" % (e,)) self.reactor.pause(starttime + 5.) continue