diff options
| author | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-10-25 19:09:16 +0900 |
|---|---|---|
| committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-10-25 19:09:38 +0900 |
| commit | 89b5d495c329143f433d1fbe89c962c5ff1f81b4 (patch) | |
| tree | 71ea634529f2457a6d20e079e37905e125c9bfad /pygerrit | |
| parent | 1ce36c40f662b443e199e58a14863d136e435310 (diff) | |
| download | pygerrit-89b5d495c329143f433d1fbe89c962c5ff1f81b4.tar.gz | |
Python 2.6 style exception handling
Handle exceptions with the syntax:
except Exception as e
rather than:
except Exception, e
Change-Id: I883fdc1db541b9d2699712bfd2bd328261635005
Diffstat (limited to 'pygerrit')
| -rw-r--r-- | pygerrit/client.py | 2 | ||||
| -rw-r--r-- | pygerrit/events.py | 14 | ||||
| -rw-r--r-- | pygerrit/ssh.py | 2 | ||||
| -rw-r--r-- | pygerrit/stream.py | 6 |
4 files changed, 12 insertions, 12 deletions
diff --git a/pygerrit/client.py b/pygerrit/client.py index 2015b06..95f4ce0 100644 --- a/pygerrit/client.py +++ b/pygerrit/client.py @@ -74,7 +74,7 @@ class GerritClient(object): # represents a change or if it's the query status indicator. try: data = decoder.decode(line) - except ValueError, err: + except ValueError as err: raise GerritError("Query returned invalid data: %s", err) if "type" in data and data["type"] == "error": raise GerritError("Query error: %s" % data["message"]) diff --git a/pygerrit/events.py b/pygerrit/events.py index 3d5c878..5e97bce 100644 --- a/pygerrit/events.py +++ b/pygerrit/events.py @@ -95,7 +95,7 @@ class PatchsetCreatedEvent(GerritEvent): self.change = Change(json_data["change"]) self.patchset = Patchset(json_data["patchSet"]) self.uploader = Account(json_data["uploader"]) - except KeyError, e: + except KeyError as e: raise GerritError("PatchsetCreatedEvent: %s" % e) @@ -110,7 +110,7 @@ class DraftPublishedEvent(GerritEvent): self.change = Change(json_data["change"]) self.patchset = Patchset(json_data["patchSet"]) self.uploader = Account(json_data["uploader"]) - except KeyError, e: + except KeyError as e: raise GerritError("DraftPublishedEvent: %s" % e) @@ -130,7 +130,7 @@ class CommentAddedEvent(GerritEvent): for approval in json_data["approvals"]: self.approvals.append(Approval(approval)) self.comment = json_data["comment"] - except ValueError, e: + except (KeyError, ValueError) as e: raise GerritError("CommentAddedEvent: %s" % e) @@ -145,7 +145,7 @@ class ChangeMergedEvent(GerritEvent): self.change = Change(json_data["change"]) self.patchset = Patchset(json_data["patchSet"]) self.submitter = Account(json_data["submitter"]) - except KeyError, e: + except KeyError as e: raise GerritError("ChangeMergedEvent: %s" % e) @@ -161,7 +161,7 @@ class ChangeAbandonedEvent(GerritEvent): self.patchset = Patchset.from_json(json_data) self.abandoner = Account(json_data["abandoner"]) self.reason = json_data["reason"] - except KeyError, e: + except KeyError as e: raise GerritError("ChangeAbandonedEvent: %s" % e) @@ -177,7 +177,7 @@ class ChangeRestoredEvent(GerritEvent): self.patchset = Patchset.from_json(json_data) self.restorer = Account(json_data["restorer"]) self.reason = json_data["reason"] - except KeyError, e: + except KeyError as e: raise GerritError("ChangeRestoredEvent: %s" % e) @@ -191,5 +191,5 @@ class RefUpdatedEvent(GerritEvent): try: self.ref_update = RefUpdate(json_data["refUpdate"]) self.submitter = Account.from_json(json_data, "submitter") - except KeyError, e: + except KeyError as e: raise GerritError("RefUpdatedEvent: %s" % e) diff --git a/pygerrit/ssh.py b/pygerrit/ssh.py index 712613c..2a019f5 100644 --- a/pygerrit/ssh.py +++ b/pygerrit/ssh.py @@ -122,6 +122,6 @@ class GerritSSHClient(SSHClient): gerrit_command.append(command) try: stdin, stdout, stderr = self.exec_command(" ".join(gerrit_command)) - except SSHException, err: + except SSHException as err: raise GerritError("Command execution error: %s" % err) return GerritSSHCommandResult(stdin, stdout, stderr) diff --git a/pygerrit/stream.py b/pygerrit/stream.py index 41572ce..3ca324b 100644 --- a/pygerrit/stream.py +++ b/pygerrit/stream.py @@ -71,7 +71,7 @@ class GerritStream(Thread): """ Listen to the stream and send events to the client. """ try: result = self._ssh_client.run_gerrit_command("stream-events") - except GerritError, e: + except GerritError as e: self._error_event(e) poller = poll() @@ -85,7 +85,7 @@ class GerritStream(Thread): line = stdout.readline() json_data = json.loads(line) self._gerrit.put_event(json_data) - except (ValueError, IOError), err: + except (ValueError, IOError) as err: self._error_event(err) - except GerritError, err: + except GerritError as err: logging.error("Failed to put event: %s", err) |
