changeset 8164:c59e914c4887

py3: use exception .args instead of .message Args seems slightly more fragile and *could* introduce problems for trivial use if args is empty. But .message is gone.
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 03 Feb 2020 16:08:50 +0100
parents 24e1099e4f29
children b4095011433d
files kallithea/controllers/admin/my_account.py kallithea/controllers/admin/users.py kallithea/controllers/api/api.py kallithea/lib/rcmail/response.py kallithea/lib/vcs/backends/hg/repository.py kallithea/model/ssh_key.py
diffstat 6 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/my_account.py	Fri Jan 31 18:48:15 2020 +0100
+++ b/kallithea/controllers/admin/my_account.py	Mon Feb 03 16:08:50 2020 +0100
@@ -279,8 +279,8 @@
             Session().commit()
             SshKeyModel().write_authorized_keys()
             h.flash(_("SSH key %s successfully added") % new_ssh_key.fingerprint, category='success')
-        except SshKeyModelException as errors:
-            h.flash(errors.message, category='error')
+        except SshKeyModelException as e:
+            h.flash(e.args[0], category='error')
         raise HTTPFound(location=url('my_account_ssh_keys'))
 
     @IfSshEnabled
@@ -291,6 +291,6 @@
             Session().commit()
             SshKeyModel().write_authorized_keys()
             h.flash(_("SSH key successfully deleted"), category='success')
-        except SshKeyModelException as errors:
-            h.flash(errors.message, category='error')
+        except SshKeyModelException as e:
+            h.flash(e.args[0], category='error')
         raise HTTPFound(location=url('my_account_ssh_keys'))
--- a/kallithea/controllers/admin/users.py	Fri Jan 31 18:48:15 2020 +0100
+++ b/kallithea/controllers/admin/users.py	Mon Feb 03 16:08:50 2020 +0100
@@ -452,8 +452,8 @@
             Session().commit()
             SshKeyModel().write_authorized_keys()
             h.flash(_("SSH key %s successfully added") % new_ssh_key.fingerprint, category='success')
-        except SshKeyModelException as errors:
-            h.flash(errors.message, category='error')
+        except SshKeyModelException as e:
+            h.flash(e.args[0], category='error')
         raise HTTPFound(location=url('edit_user_ssh_keys', id=c.user.user_id))
 
     @IfSshEnabled
@@ -466,6 +466,6 @@
             Session().commit()
             SshKeyModel().write_authorized_keys()
             h.flash(_("SSH key successfully deleted"), category='success')
-        except SshKeyModelException as errors:
-            h.flash(errors.message, category='error')
+        except SshKeyModelException as e:
+            h.flash(e.args[0], category='error')
         raise HTTPFound(location=url('edit_user_ssh_keys', id=c.user.user_id))
--- a/kallithea/controllers/api/api.py	Fri Jan 31 18:48:15 2020 +0100
+++ b/kallithea/controllers/api/api.py	Mon Feb 03 16:08:50 2020 +0100
@@ -2339,7 +2339,7 @@
                                                  branch_name,
                                                  reverse, max_revisions)]
         except EmptyRepositoryError as e:
-            raise JSONRPCError(e.message)
+            raise JSONRPCError('Repository is empty')
 
     # permission check inside
     def get_changeset(self, repoid, raw_id, with_reviews=Optional(False)):
--- a/kallithea/lib/rcmail/response.py	Fri Jan 31 18:48:15 2020 +0100
+++ b/kallithea/lib/rcmail/response.py	Mon Feb 03 16:08:50 2020 +0100
@@ -339,10 +339,10 @@
 
     try:
         out = MIMEPart(ctype, **params)
-    except TypeError as exc:  # pragma: no cover
+    except TypeError as e:  # pragma: no cover
         raise EncodingError("Content-Type malformed, not allowed: %r; "
-                            "%r (Python ERROR: %s" %
-                            (ctype, params, exc.message))
+                            "%r (Python ERROR: %s)" %
+                            (ctype, params, e.args[0]))
 
     for k in mail.keys():
         if k in ADDRESS_HEADERS_WHITELIST:
--- a/kallithea/lib/vcs/backends/hg/repository.py	Fri Jan 31 18:48:15 2020 +0100
+++ b/kallithea/lib/vcs/backends/hg/repository.py	Mon Feb 03 16:08:50 2020 +0100
@@ -184,7 +184,7 @@
         try:
             mercurial.tags.tag(self._repo, safe_bytes(name), changeset._ctx.node(), safe_bytes(message), local, safe_bytes(user), date)
         except mercurial.error.Abort as e:
-            raise RepositoryError(e.message)
+            raise RepositoryError(e.args[0])
 
         # Reinitialize tags
         self.tags = self._get_tags()
@@ -215,7 +215,7 @@
             mercurial.tags.tag(self._repo, safe_bytes(name), mercurial.commands.nullid, safe_bytes(message), local, safe_bytes(user), date)
             self.tags = self._get_tags()
         except mercurial.error.Abort as e:
-            raise RepositoryError(e.message)
+            raise RepositoryError(e.args[0])
 
     @LazyProperty
     def bookmarks(self):
--- a/kallithea/model/ssh_key.py	Fri Jan 31 18:48:15 2020 +0100
+++ b/kallithea/model/ssh_key.py	Mon Feb 03 16:08:50 2020 +0100
@@ -54,7 +54,7 @@
         try:
             keytype, pub, comment = ssh.parse_pub_key(public_key)
         except ssh.SshKeyParseError as e:
-            raise SshKeyModelException(_('SSH key %r is invalid: %s') % (public_key, e.message))
+            raise SshKeyModelException(_('SSH key %r is invalid: %s') % (public_key, e.args[0]))
         if not description.strip():
             description = comment.strip()