You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/02/10 22:44:37 UTC

[allura] 06/41: [#8349] python-modernize -n -w --no-diffs -f except .

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8349
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 57c3cf408a1c3691d91a5f31921f1d9f21fafa8f
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Mon Feb 10 12:35:11 2020 -0500

    [#8349] python-modernize -n -w --no-diffs -f except .
---
 Allura/allura/command/show_models.py                | 4 ++--
 Allura/allura/controllers/auth.py                   | 2 +-
 Allura/allura/controllers/repository.py             | 2 +-
 Allura/allura/ext/admin/admin_main.py               | 2 +-
 Allura/allura/lib/import_api.py                     | 2 +-
 Allura/allura/lib/macro.py                          | 2 +-
 Allura/allura/lib/utils.py                          | 2 +-
 Allura/allura/lib/validators.py                     | 4 ++--
 Allura/allura/model/monq_model.py                   | 4 ++--
 Allura/allura/scripts/create_sitemap_files.py       | 2 +-
 Allura/allura/scripts/reindex_projects.py           | 2 +-
 Allura/allura/scripts/reindex_users.py              | 2 +-
 Allura/allura/scripts/trac_export.py                | 2 +-
 Allura/allura/tasks/mail_tasks.py                   | 2 +-
 AlluraTest/alluratest/validation.py                 | 2 +-
 ForgeDiscussion/forgediscussion/controllers/root.py | 4 ++--
 ForgeGit/forgegit/model/git_repo.py                 | 2 +-
 ForgeTracker/forgetracker/import_support.py         | 2 +-
 ForgeTracker/forgetracker/model/ticket.py           | 4 ++--
 scripts/project-import.py                           | 2 +-
 20 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/Allura/allura/command/show_models.py b/Allura/allura/command/show_models.py
index e082f9b..8417bb2 100644
--- a/Allura/allura/command/show_models.py
+++ b/Allura/allura/command/show_models.py
@@ -137,7 +137,7 @@ class ReindexCommand(base.Command):
                     M.artifact_orm_session.clear()
                     try:
                         self._chunked_add_artifacts(ref_ids)
-                    except CompoundError, err:
+                    except CompoundError as err:
                         base.log.exception(
                             'Error indexing artifacts:\n%r', err)
                         base.log.error('%s', err.format_error())
@@ -298,7 +298,7 @@ class EnsureIndexCommand(base.Command):
                         del index_options['unique']
                     collection.ensure_index(idx.index_spec, **index_options)
                     break
-                except DuplicateKeyError, err:
+                except DuplicateKeyError as err:
                     base.log.info('Found dupe key(%s), eliminating dupes', err)
                     self._remove_dupes(collection, idx.index_spec)
         for keys, idx in indexes.iteritems():
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 82ecdf3..002ae8a 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -686,7 +686,7 @@ class PreferencesController(BaseController):
         ap = plugin.AuthenticationProvider.get(request)
         try:
             ap.upload_sshkey(c.user.username, key)
-        except AssertionError, ae:
+        except AssertionError as ae:
             flash('Error uploading key: %s' % ae, 'error')
         flash('Key uploaded')
         redirect('.')
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 7437df3..13fa7af 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -153,7 +153,7 @@ class RepoRootController(BaseController, FeedController):
                     redirect(to_project.url() + mount_point + '/')
                 except exc.HTTPRedirection:
                     raise
-                except Exception, ex:
+                except Exception as ex:
                     flash(str(ex), 'error')
                     redirect(request.referer or '/')
 
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index 622aafd..e593bba 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -641,7 +641,7 @@ class ProjectAdminController(BaseController):
                     if callable(new_url):  # subprojects have a method instead of property
                         new_url = new_url()
                     redirect(new_url)
-        except forge_exc.ForgeError, exc:
+        except forge_exc.ForgeError as exc:
             flash('%s: %s' % (exc.__class__.__name__, exc.args[0]),
                   'error')
         if request.referer is not None and tool is not None and 'delete' in tool[0] and \
diff --git a/Allura/allura/lib/import_api.py b/Allura/allura/lib/import_api.py
index 71080ba..95e214a 100644
--- a/Allura/allura/lib/import_api.py
+++ b/Allura/allura/lib/import_api.py
@@ -52,7 +52,7 @@ class AlluraImportApiClient(object):
                 result = urllib2.urlopen(url, urllib.urlencode(params))
                 resp = result.read()
                 return json.loads(resp)
-            except urllib2.HTTPError, e:
+            except urllib2.HTTPError as e:
                 e.msg += ' ({0})'.format(url)
                 if self.verbose:
                     error_content = e.read()
diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index 911be84..b0c7f46 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -83,7 +83,7 @@ class parse(object):
                          exc_info=True)
                 msg = cgi.escape('[[%s]] (%s)' % (s, repr(ex)))
                 return '\n<div class="error"><pre><code>%s</code></pre></div>' % msg
-        except Exception, ex:
+        except Exception as ex:
             raise
             return '[[Error parsing %s: %s]]' % (s, ex)
 
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 45bee24..cedc50d 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -66,7 +66,7 @@ MARKDOWN_EXTENSIONS = ['.markdown', '.mdown', '.mkdn', '.mkd', '.md']
 def permanent_redirect(url):
     try:
         tg.redirect(url)
-    except exc.HTTPFound, err:
+    except exc.HTTPFound as err:
         raise exc.HTTPMovedPermanently(location=err.location)
 
 
diff --git a/Allura/allura/lib/validators.py b/Allura/allura/lib/validators.py
index 2041dcb..c92535b 100644
--- a/Allura/allura/lib/validators.py
+++ b/Allura/allura/lib/validators.py
@@ -250,7 +250,7 @@ class JsonValidator(fev.FancyValidator):
     def _to_python(self, value, state):
         try:
             json.loads(value)
-        except ValueError, e:
+        except ValueError as e:
             raise fe.Invalid('Invalid JSON: ' + str(e), value, state)
         return value
 
@@ -265,7 +265,7 @@ class JsonConverter(fev.FancyValidator):
     def _to_python(self, value, state):
         try:
             obj = json.loads(value)
-        except ValueError, e:
+        except ValueError as e:
             raise fe.Invalid('Invalid JSON: ' + str(e), value, state)
         if not isinstance(obj, dict):
             raise fe.Invalid('Not a dict (JSON object)', value, state)
diff --git a/Allura/allura/model/monq_model.py b/Allura/allura/model/monq_model.py
index ded8229..b715f33 100644
--- a/Allura/allura/model/monq_model.py
+++ b/Allura/allura/model/monq_model.py
@@ -205,7 +205,7 @@ class MonQTask(MappedClass):
                     sort=cls.sort)
                 if obj is not None:
                     return obj
-            except pymongo.errors.OperationFailure, exc:
+            except pymongo.errors.OperationFailure as exc:
                 if 'No matching object found' not in exc.args[0]:
                     raise
             if waitfunc is None:
@@ -266,7 +266,7 @@ class MonQTask(MappedClass):
                 self.result = func(*self.args, **self.kwargs)
             self.state = 'complete'
             return self.result
-        except Exception, exc:
+        except Exception as exc:
             if asbool(config.get('monq.raise_errors')):
                 raise
             else:
diff --git a/Allura/allura/scripts/create_sitemap_files.py b/Allura/allura/scripts/create_sitemap_files.py
index 2bdbb86..f20645a 100644
--- a/Allura/allura/scripts/create_sitemap_files.py
+++ b/Allura/allura/scripts/create_sitemap_files.py
@@ -117,7 +117,7 @@ class CreateSitemapFiles(ScriptTask):
                         locs.append({'url': url,
                                      'date': p.last_updated.strftime("%Y-%m-%d")})
 
-                except Exception, e:
+                except Exception as e:
                     print "Error creating sitemap for project '%s': %s" %\
                         (p.shortname, e)
                 creds.clear()
diff --git a/Allura/allura/scripts/reindex_projects.py b/Allura/allura/scripts/reindex_projects.py
index f14b973..0e65538 100644
--- a/Allura/allura/scripts/reindex_projects.py
+++ b/Allura/allura/scripts/reindex_projects.py
@@ -62,7 +62,7 @@ class ReindexProjects(ScriptTask):
                         cls._post_add_projects(chunk)
                     else:
                         add_projects(chunk)
-            except CompoundError, err:
+            except CompoundError as err:
                 log.exception('Error indexing projects:\n%r', err)
                 log.error('%s', err.format_error())
             M.main_orm_session.flush()
diff --git a/Allura/allura/scripts/reindex_users.py b/Allura/allura/scripts/reindex_users.py
index 427cd09..ccd40c0 100644
--- a/Allura/allura/scripts/reindex_users.py
+++ b/Allura/allura/scripts/reindex_users.py
@@ -48,7 +48,7 @@ class ReindexUsers(ScriptTask):
                         cls._post_add_users(chunk)
                     else:
                         add_users(chunk)
-            except CompoundError, err:
+            except CompoundError as err:
                 log.exception('Error indexing users:\n%r', err)
                 log.error('%s', err.format_error())
             M.main_orm_session.flush()
diff --git a/Allura/allura/scripts/trac_export.py b/Allura/allura/scripts/trac_export.py
index 19ec460..7ad2277 100644
--- a/Allura/allura/scripts/trac_export.py
+++ b/Allura/allura/scripts/trac_export.py
@@ -252,7 +252,7 @@ class TracExport(object):
         url = self.full_url(self.QUERY_BY_PAGE_URL % self.page, 'csv')
         try:
             f = self.csvopen(url)
-        except urllib2.HTTPError, e:
+        except urllib2.HTTPError as e:
             if 'emulated' in e.msg:
                 body = e.fp.read()
                 if 'beyond the number of pages in the query' in six.ensure_text(body):
diff --git a/Allura/allura/tasks/mail_tasks.py b/Allura/allura/tasks/mail_tasks.py
index eaa730e..f8f1cc0 100644
--- a/Allura/allura/tasks/mail_tasks.py
+++ b/Allura/allura/tasks/mail_tasks.py
@@ -101,7 +101,7 @@ def route_email(
                                 c.app.handle_message(userpart, msg)
                         else:
                             c.app.handle_message(userpart, msg)
-            except exc.MailError, e:
+            except exc.MailError as e:
                 log.error('Error routing email to %s: %s', addr, e)
             except:
                 log.exception('Error routing mail to %s', addr)
diff --git a/AlluraTest/alluratest/validation.py b/AlluraTest/alluratest/validation.py
index e7bcd85..a6bf827 100644
--- a/AlluraTest/alluratest/validation.py
+++ b/AlluraTest/alluratest/validation.py
@@ -117,7 +117,7 @@ def validate_json(json_or_response):
 
     try:
         obj = json.loads(j)
-    except Exception, e:
+    except Exception as e:
         ok_(False, "Couldn't validate JSON: " + str(e) + ':' + j[:100] + '...')
 
     return obj
diff --git a/ForgeDiscussion/forgediscussion/controllers/root.py b/ForgeDiscussion/forgediscussion/controllers/root.py
index 0b7d940..9102ebb 100644
--- a/ForgeDiscussion/forgediscussion/controllers/root.py
+++ b/ForgeDiscussion/forgediscussion/controllers/root.py
@@ -323,7 +323,7 @@ class RootRestController(BaseController, AppRestControllerMixin):
             warnings, doc = import_support.validate_import(
                 doc, username_mapping)
             return dict(warnings=warnings, errors=[])
-        except Exception, e:
+        except Exception as e:
             raise
             log.exception(e)
             return dict(status=False, errors=[repr(e)])
@@ -344,7 +344,7 @@ class RootRestController(BaseController, AppRestControllerMixin):
             warnings = import_support.perform_import(
                 doc, username_mapping, default_username, create_users)
             return dict(warnings=warnings, errors=[])
-        except Exception, e:
+        except Exception as e:
             raise
             log.exception(e)
             return dict(status=False, errors=[str(e)])
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 26f8bae..171c69a 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -166,7 +166,7 @@ class GitImplementation(M.RepositoryImplementation):
             _git = git.Repo(self._repo.full_fs_path, odbt=git.GitCmdObjectDB)
             _git.git = GitLibCmdWrapper(_git.git)
             return _git
-        except (git.exc.NoSuchPathError, git.exc.InvalidGitRepositoryError), err:
+        except (git.exc.NoSuchPathError, git.exc.InvalidGitRepositoryError) as err:
             log.error('Problem looking up repo: %r', err)
             return None
 
diff --git a/ForgeTracker/forgetracker/import_support.py b/ForgeTracker/forgetracker/import_support.py
index c0f5f89..fe789a5 100644
--- a/ForgeTracker/forgetracker/import_support.py
+++ b/ForgeTracker/forgetracker/import_support.py
@@ -366,7 +366,7 @@ option user_map to avoid losing username information. Unknown users: %s''' % unk
             for a_entry in attachments:
                 try:
                     self.make_attachment(a['id'], t._id, a_entry)
-                except Exception, e:
+                except Exception as e:
                     self.warnings.append(
                         'Could not import attachment, skipped: %s' % e)
             log.info('Imported ticket: %d', t.ticket_num)
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index fd4a412..a98ee03 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -685,7 +685,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
             try:
                 session(ticket).flush(ticket)
                 return ticket
-            except OperationFailure, err:
+            except OperationFailure as err:
                 if 'duplicate' in err.args[0]:
                     log.warning('Try to create duplicate ticket %s',
                                 ticket.url())
@@ -1096,7 +1096,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
             try:
                 session(self).flush(self)
                 break
-            except OperationFailure, err:
+            except OperationFailure as err:
                 if 'duplicate' in err.args[0]:
                     log.warning(
                         'Try to create duplicate ticket %s when moving from %s' %
diff --git a/scripts/project-import.py b/scripts/project-import.py
index eedbf1d..c210989 100644
--- a/scripts/project-import.py
+++ b/scripts/project-import.py
@@ -232,7 +232,7 @@ def create_project(p, nbhd, options):
                                             p.admin,
                                             project_name=p.name.name,
                                             private_project=p.private)
-        except Exception, e:
+        except Exception as e:
             log.exception('[%s] %s' % (worker_name, str(e)))
             return 0
     else: