summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2018-03-25 07:58:14 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2018-04-05 12:25:54 (GMT)
commit239f39c0974de551c1898415a7faef1178a1ea19 (patch)
tree26260b7822d05416956e18c22543e35db247901c
parent7df3a6f5e0b152207274617cdd037077aca46fc2 (diff)
downloaddjango-mellon-239f39c0974de551c1898415a7faef1178a1ea19.zip
django-mellon-239f39c0974de551c1898415a7faef1178a1ea19.tar.gz
django-mellon-239f39c0974de551c1898415a7faef1178a1ea19.tar.bz2
python3: add detection of xml encoding
-rw-r--r--mellon/utils.py11
-rw-r--r--mellon/views.py3
2 files changed, 13 insertions, 1 deletions
diff --git a/mellon/utils.py b/mellon/utils.py
index 830f711..30f5970 100644
--- a/mellon/utils.py
+++ b/mellon/utils.py
@@ -3,6 +3,7 @@ import datetime
import importlib
from functools import wraps
import isodate
+from xml.parsers import expat
from django.contrib import auth
from django.core.urlresolvers import reverse
@@ -246,3 +247,13 @@ def login(request, user):
break
else:
auth.login(request, user)
+
+
+def get_xml_encoding(content):
+ xml_encoding = 'utf-8'
+ def xmlDeclHandler(version, encoding, standalone):
+ xml_encoding = encoding
+ parser = expat.ParserCreate()
+ parser.XmlDeclHandler = xmlDeclHandler
+ parser.Parse(content, True)
+ return xml_encoding
diff --git a/mellon/views.py b/mellon/views.py
index a7778d7..f77b8ff 100644
--- a/mellon/views.py
+++ b/mellon/views.py
@@ -272,8 +272,9 @@ class LoginView(ProfileMixin, LogMixin, View):
return self.sso_failure(request, login, idp_message, status_codes)
self.log.info('Got SAML Artifact Response', extra={'saml_response': result.content})
+ result.encoding = utils.get_xml_encoding(result.content)
try:
- login.processResponseMsg(result.content)
+ login.processResponseMsg(result.text)
login.acceptSso()
except lasso.ProfileMissingResponseError:
# artifact is invalid, idp returned no response