Update to new style exception catching
authorMagnus Hagander <magnus@hagander.net>
Sat, 19 Jan 2019 18:34:14 +0000 (19:34 +0100)
committerMagnus Hagander <magnus@hagander.net>
Sat, 26 Jan 2019 15:19:26 +0000 (16:19 +0100)
pgweb/account/forms.py
pgweb/account/oauthclient.py
pgweb/account/recaptcha.py
pgweb/core/management/commands/fetch_rss_feeds.py
pgweb/downloads/views.py
pgweb/mailqueue/admin.py
pgweb/security/models.py
tools/search/crawler/lib/archives.py
tools/search/crawler/lib/basecrawler.py
tools/search/crawler/lib/threadwrapper.py
tools/varnishqueue/varnish_queue.py

index 712b51421b8e1b05b9295ada78ff163751ce22f3..ff3c2eb413d0f5e1424919f2afd4bb496e3a55b7 100644 (file)
@@ -30,7 +30,7 @@ class PgwebAuthenticationForm(AuthenticationForm):
     def clean(self):
         try:
             return super(PgwebAuthenticationForm, self).clean()
-        except ValueError, e:
+        except ValueError as e:
             if e.message.startswith('Unknown password hashing algorithm'):
                 # This is *probably* a user trying to log in with an account that has not
                 # been set up properly yet. It could be an actually unsupported hashing
index a287081dd95397d28d5c89c7fe1ac4cd6a52622c..808d284bcb1821da1b32f9e31fb548efddf8f989 100644 (file)
@@ -41,7 +41,7 @@ def _login_oauth(request, provider, authurl, tokenurl, scope, authdatafunc):
         try:
             (email, firstname, lastname) = authdatafunc(oa)
             email = email.lower()
-        except KeyError, e:
+        except KeyError as e:
             log.warning("Oauth signing using {0} was missing data: {1}".format(provider, e))
             return HttpResponse('OAuth login was missing critical data. To log in, you need to allow access to email, first name and last name!')
 
@@ -196,8 +196,8 @@ def login_oauth(request, provider):
     if hasattr(m, fn):
         try:
             return getattr(m, fn)(request)
-        except OAuthException, e:
+        except OAuthException as e:
             return HttpResponse(e)
-        except Exception, e:
+        except Exception as e:
             log.error('Excpetion during OAuth: %s' % e)
             return HttpResponse('An unhandled exception occurred during the authentication process')
index f21df56a287044df45e45ae3ae5a530d77acd412..51dbfe40f1f3100e0b73c9071f08563c1a01a655 100644 (file)
@@ -61,7 +61,7 @@ class ReCaptchaField(forms.CharField):
                 'Content-type': 'application/x-www-form-urlencoded',
             })
             c.sock.settimeout(10)
-        except Exception, e:
+        except Exception as e:
             # Error to connect at TCP level
             log.error('Failed to connect to google recaptcha API: %s' % e)
             raise ValidationError('Failed in API call to google recaptcha')
index 39bfc9c7cf636a0801a9c56d63fa64842342f274..afe5a65bd2a9331ea8135b692fc51b2924beb0cb 100644 (file)
@@ -50,5 +50,5 @@ class Command(BaseCommand):
 
                     if fetchedsomething:
                             importfeed.purge_related()
-                except Exception, e:
-                    print "Failed to load %s: %s" % (importfeed, e)
+                except Exception as e:
+                    print("Failed to load %s: %s" % (importfeed, e))
index deb29593e2288270992a226219658ff95b72bb92..943c866c9c10a38fa038f06c2babfbed23a01880 100644 (file)
@@ -38,7 +38,7 @@ def ftpbrowser(request, subpath):
         f = open(settings.FTP_PICKLE, "rb")
         allnodes = pickle.load(f)
         f.close()
-    except Exception, e:
+    except Exception as e:
         return HttpServerError(request, "Failed to load ftp site information: %s" % e)
 
     # An incoming subpath may either be canonical, or have one or more elements
index b99a3b63b5112f96dcabe8e7fb3d1265d01fa028..46a6aa1f12f1f6c02a38088f112243d365e3e64d 100644 (file)
@@ -25,7 +25,7 @@ class QueuedMailAdmin(admin.ModelAdmin):
                 if b:
                     return b
             return "Could not find body"
-        except Exception, e:
+        except Exception as e:
             return "Failed to get body: %s" % e
 
     parsed_content.short_description = 'Parsed mail'
index cde84ba0c2e165a15824a3b5f0f42eb71197d599..6d88282cb5bdbc482d6cf2357a3209c13ae87a45 100644 (file)
@@ -46,7 +46,7 @@ def other_vectors_validator(val):
                 ))
     except ValidationError:
         raise
-    except Exception, e:
+    except Exception as e:
         raise ValidationError("Failed to parse vectors: %s" % e)
 
 
index ab1a5f249187a170c22a0349f66b190cab5688ec..1e42a8bac2c427a45ff6d2439cae85afc89de8f0 100644 (file)
@@ -116,7 +116,7 @@ class MultiListCrawler(object):
             try:
                 if not self.crawl_single_message(listid, listname, year, month, currentmsg):
                     break
-            except Exception, e:
+            except Exception as e:
                 log("Exception when crawling %s/%s/%s/%s - %s" % (
                     listname, year, month, currentmsg, e))
                 # Continue on to try the next message
index 7bd3c4d3d199e100f09931b39c342a666141743a..aeae20b8d9005539bc1b2964827d1e3c212faad6 100644 (file)
@@ -85,7 +85,7 @@ class BaseSiteCrawler(object):
             (url, relprio, internal) = self.queue.get()
             try:
                 self.crawl_page(url, relprio, internal)
-            except Exception, e:
+            except Exception as e:
                 log("Exception crawling '%s': %s" % (url, e))
             self.queue.task_done()
 
@@ -127,7 +127,7 @@ class BaseSiteCrawler(object):
         pagedata = lossy_unicode(pagedata)
         try:
             self.page = self.parse_html(pagedata)
-        except Exception, e:
+        except Exception as e:
             log("Failed to parse HTML for %s" % url)
             log(e)
             return
@@ -213,7 +213,7 @@ class BaseSiteCrawler(object):
             else:
                 # print "Url %s returned status %s" % (url, resp.status)
                 pass
-        except Exception, e:
+        except Exception as e:
             log("Exception when loading url %s: %s" % (url, e))
         return (2, None, None)
 
index 87c702652fb2cabbb355ec6c39f0fc78977f527c..e305dffc88a9ed1d065eee1f963e4deb5e3f9774 100644 (file)
@@ -15,9 +15,9 @@ def threadwrapper(func, *args):
     # forcibly terminate the child.
     try:
         p.join()
-    except KeyboardInterrupt, e:
+    except KeyboardInterrupt as e:
         print "Keyboard interrupt, terminating child process!"
         p.terminate()
-    except Exception, e:
+    except Exception as e:
         print "Exception %s, terminating child process!" % e
         p.terminate()
index 310967592b376f2dbda08d7b5f73e4a784abcd38..707493982b0f824b8d895595121e1e69dfdcd732 100755 (executable)
@@ -26,7 +26,7 @@ def do_purge(consumername, headers):
             return True
         logging.warning("Varnish purge on %s returned status %s (%s)" % (consumername, resp.status, resp.reason))
         return False
-    except Exception, ex:
+    except Exception as ex:
         logging.error("Exception purging on %s: %s" % (consumername, ex))
         return False
     return True