summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2017-12-28 16:31:20 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2017-12-30 10:53:31 (GMT)
commit343be40b6f4e942aed4078ab643349e943da8904 (patch)
tree5c2609854c8f8536416a7c5381da96011800f831
parent078fcbd058717f4e0a0153f8a4ca3bf2ed066e1a (diff)
downloaddjango-mellon-343be40b6f4e942aed4078ab643349e943da8904.zip
django-mellon-343be40b6f4e942aed4078ab643349e943da8904.tar.gz
django-mellon-343be40b6f4e942aed4078ab643349e943da8904.tar.bz2
misc: update exception handling for Python 3 (#20925)
-rw-r--r--mellon/adapters.py8
-rw-r--r--mellon/utils.py2
-rw-r--r--mellon/views.py18
3 files changed, 14 insertions, 14 deletions
diff --git a/mellon/adapters.py b/mellon/adapters.py
index 060a54c..bbf56e1 100644
--- a/mellon/adapters.py
+++ b/mellon/adapters.py
@@ -38,7 +38,7 @@ class DefaultAdapter(object):
try:
response = requests.get(idp['METADATA_URL'], verify=verify_ssl_certificate)
response.raise_for_status()
- except requests.exceptions.RequestException, e:
+ except requests.exceptions.RequestException as e:
self.logger.error(
u'retrieval of metadata URL %r failed with error %s for %d-th idp',
idp['METADATA_URL'], e, i)
@@ -86,10 +86,10 @@ class DefaultAdapter(object):
realm=realm, attributes=saml_attributes, idp=idp)[:30]
except ValueError:
self.logger.error(u'invalid username template %r', username_template)
- except (AttributeError, KeyError, IndexError), e:
+ except (AttributeError, KeyError, IndexError) as e:
self.logger.error(
u'invalid reference in username template %r: %s', username_template, e)
- except Exception, e:
+ except Exception as e:
self.logger.exception(u'unknown error when formatting username')
else:
return username
@@ -163,7 +163,7 @@ class DefaultAdapter(object):
value = unicode(tpl).format(realm=realm, attributes=saml_attributes, idp=idp)
except ValueError:
self.logger.warning(u'invalid attribute mapping template %r', tpl)
- except (AttributeError, KeyError, IndexError, ValueError), e:
+ except (AttributeError, KeyError, IndexError, ValueError) as e:
self.logger.warning(
u'invalid reference in attribute mapping template %r: %s', tpl, e)
else:
diff --git a/mellon/utils.py b/mellon/utils.py
index ab092a7..90464c1 100644
--- a/mellon/utils.py
+++ b/mellon/utils.py
@@ -79,7 +79,7 @@ def create_server(request):
for idp in get_idps():
try:
server.addProviderFromBuffer(lasso.PROVIDER_ROLE_IDP, idp['METADATA'])
- except lasso.Error, e:
+ except lasso.Error as e:
logger.error(u'bad metadata in idp %r', idp['ENTITY_ID'])
logger.debug(u'lasso error: %s', e)
continue
diff --git a/mellon/views.py b/mellon/views.py
index e01dc13..2ecb0b3 100644
--- a/mellon/views.py
+++ b/mellon/views.py
@@ -120,7 +120,7 @@ class LoginView(ProfileMixin, LogMixin, View):
lasso.ProfileStatusNotSuccessError,
lasso.ProfileRequestDeniedError):
self.show_message_status_is_not_success(login, 'SAML authentication failed')
- except lasso.Error, e:
+ except lasso.Error as e:
return HttpResponseBadRequest('error processing the authentication response: %r' % e)
else:
if 'RelayState' in request.POST and utils.is_nonnull(request.POST['RelayState']):
@@ -262,7 +262,7 @@ class LoginView(ProfileMixin, LogMixin, View):
headers={'content-type': 'text/xml'},
timeout=app_settings.ARTIFACT_RESOLVE_TIMEOUT,
verify=verify_ssl_certificate)
- except RequestException, e:
+ except RequestException as e:
self.log.warning('unable to reach %r: %s', login.msgUrl, e)
return self.sso_failure(request, login, _('IdP is temporarily down, please try again '
'later.'), status_codes)
@@ -305,7 +305,7 @@ class LoginView(ProfileMixin, LogMixin, View):
args[0] += ' message: %r'
args.append(status.statusMessage)
self.log.warning(*args)
- except lasso.Error, e:
+ except lasso.Error as e:
self.log.exception('unexpected lasso error')
return HttpResponseBadRequest('error processing the authentication response: %r' % e)
else:
@@ -373,7 +373,7 @@ class LoginView(ProfileMixin, LogMixin, View):
escape(request.build_absolute_uri(next_url or '/')))
self.set_next_url(next_url)
login.buildAuthnRequestMsg()
- except lasso.Error, e:
+ except lasso.Error as e:
return HttpResponseBadRequest('error initializing the authentication request: %r' % e)
self.log.debug('sending authn request %r', authn_request.dump())
self.log.debug('to url %r', login.msgUrl)
@@ -397,11 +397,11 @@ class LogoutView(ProfileMixin, LogMixin, View):
self.profile = logout = utils.create_logout(request)
try:
logout.processRequestMsg(request.META['QUERY_STRING'])
- except lasso.Error, e:
+ except lasso.Error as e:
return HttpResponseBadRequest('error processing logout request: %r' % e)
try:
logout.validateRequest()
- except lasso.Error, e:
+ except lasso.Error as e:
self.log.warning('error validating logout request: %r' % e)
issuer = request.session.get('mellon_session', {}).get('issuer')
if issuer == logout.remoteProviderId:
@@ -409,7 +409,7 @@ class LogoutView(ProfileMixin, LogMixin, View):
auth.logout(request)
try:
logout.buildResponseMsg()
- except lasso.Error, e:
+ except lasso.Error as e:
return HttpResponseBadRequest('error processing logout request: %r' % e)
return HttpResponseRedirect(logout.msgUrl)
@@ -431,7 +431,7 @@ class LogoutView(ProfileMixin, LogMixin, View):
self.log.error('unable to find lasso session dump')
logout.initRequest(issuer, lasso.HTTP_METHOD_REDIRECT)
logout.buildRequestMsg()
- except lasso.Error, e:
+ except lasso.Error as e:
self.log.error('unable to initiate a logout request %r', e)
else:
self.log.debug('sending LogoutRequest %r', logout.request.dump())
@@ -460,7 +460,7 @@ class LogoutView(ProfileMixin, LogMixin, View):
self.show_message_status_is_not_success(logout, 'SAML logout failed')
except lasso.LogoutPartialLogoutError:
self.log.warning('partial logout')
- except lasso.Error, e:
+ except lasso.Error as e:
self.log.warning('unable to process a logout response: %s', e)
return HttpResponseRedirect(resolve_url(settings.LOGIN_REDIRECT_URL))
next_url = self.get_next_url(default=resolve_url(settings.LOGIN_REDIRECT_URL))