Skip to content

Commit da21b27

Browse files
committed
Fix xml issues with python3
Some calls in etree will return bytes where they used to return a string type.
1 parent 153de08 commit da21b27

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/saml2/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,11 @@ def to_string(self, nspair=None):
674674
return ElementTree.tostring(self._to_element_tree(), encoding="UTF-8")
675675

676676
def __str__(self):
677-
return self.to_string()
677+
# Yes this is confusing. http://bugs.python.org/issue10942
678+
x = self.to_string()
679+
if not isinstance(x, six.string_types):
680+
x = x.decode('utf-8')
681+
return x
678682

679683
def keyswv(self):
680684
""" Return the keys of attributes or children that has values

src/saml2/pack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ def make_soap_enveloped_saml_thingy(thingy, header_parts=None):
175175
_child.tag = '{%s}FuddleMuddle' % DUMMY_NAMESPACE
176176
body.append(_child)
177177
_str = ElementTree.tostring(envelope, encoding="UTF-8")
178+
if isinstance(_str, six.binary_type):
179+
_str = _str.decode('utf-8')
178180
logger.debug("SOAP precursor: %s" % _str)
179181
# find an remove the namespace definition
180182
i = _str.find(DUMMY_NAMESPACE)

src/saml2/response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import calendar
66
import logging
7+
import six
78
from saml2.samlp import STATUS_VERSION_MISMATCH
89
from saml2.samlp import STATUS_AUTHN_FAILED
910
from saml2.samlp import STATUS_INVALID_ATTR_NAME_OR_VALUE
@@ -942,6 +943,8 @@ def session_info(self):
942943
"not_on_or_after": nooa, "authn_info": self.authn_info()}
943944

944945
def __str__(self):
946+
if not isinstance(self.xmlstr, six.string_types):
947+
return "%s" % self.xmlstr.decode("utf-8")
945948
return "%s" % self.xmlstr
946949

947950
def verify_attesting_entity(self, address):

0 commit comments

Comments
 (0)