Skip to content

Commit 1846d82

Browse files
committed
Fix py3 problems with strings and encoding
1 parent 5508328 commit 1846d82

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/onelogin/saml2/auth.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
from onelogin.saml2.authn_request import OneLogin_Saml2_Authn_Request
2525

2626

27+
try:
28+
basestring
29+
except NameError:
30+
basestring = str
31+
32+
2733
class OneLogin_Saml2_Auth(object):
2834
"""
2935
@@ -569,7 +575,7 @@ def get_last_response_xml(self, pretty_print_if_possible=False):
569575
if isinstance(self.__last_response, basestring):
570576
response = self.__last_response
571577
else:
572-
response = etree.tostring(self.__last_response, pretty_print=pretty_print_if_possible)
578+
response = etree.tostring(self.__last_response, encoding='unicode', pretty_print=pretty_print_if_possible)
573579
return response
574580

575581
def get_last_request_xml(self):

src/onelogin/saml2/logout_request.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
"""
1111

12+
from onelogin.saml2 import compat
1213
from onelogin.saml2.constants import OneLogin_Saml2_Constants
1314
from onelogin.saml2.utils import OneLogin_Saml2_Utils, OneLogin_Saml2_Error, OneLogin_Saml2_ValidationError
1415
from onelogin.saml2.xml_templates import OneLogin_Saml2_Templates
@@ -95,7 +96,7 @@ def __init__(self, settings, request=None, name_id=None, session_index=None, nq=
9596
logout_request = OneLogin_Saml2_Utils.decode_base64_and_inflate(request, ignore_zip=True)
9697
self.id = self.get_id(logout_request)
9798

98-
self.__logout_request = logout_request
99+
self.__logout_request = compat.to_string(logout_request)
99100

100101
def get_request(self, deflate=True):
101102
"""

src/onelogin/saml2/logout_response.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
"""
1111

12+
from onelogin.saml2 import compat
1213
from onelogin.saml2.utils import OneLogin_Saml2_Utils, OneLogin_Saml2_ValidationError
1314
from onelogin.saml2.xml_templates import OneLogin_Saml2_Templates
1415
from onelogin.saml2.xml_utils import OneLogin_Saml2_XML
@@ -36,7 +37,7 @@ def __init__(self, settings, response=None):
3637
self.__error = None
3738

3839
if response is not None:
39-
self.__logout_response = OneLogin_Saml2_Utils.decode_base64_and_inflate(response)
40+
self.__logout_response = compat.to_string(OneLogin_Saml2_Utils.decode_base64_and_inflate(response))
4041
self.document = OneLogin_Saml2_XML.to_etree(self.__logout_response)
4142

4243
def get_issuer(self):

tests/src/OneLogin/saml2_tests/response_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ def testGetXMLDocument(self):
7171
xml = self.file_contents(join(self.data_path, 'responses', 'signed_message_response.xml.base64'))
7272
response = OneLogin_Saml2_Response(settings, xml)
7373
prety_xml = self.file_contents(join(self.data_path, 'responses', 'pretty_signed_message_response.xml'))
74-
self.assertEqual(etree.tostring(response.get_xml_document(), pretty_print=True), prety_xml)
74+
self.assertEqual(etree.tostring(response.get_xml_document(), encoding='unicode', pretty_print=True), prety_xml)
7575

7676
xml_2 = self.file_contents(join(self.data_path, 'responses', 'valid_encrypted_assertion.xml.base64'))
7777
response_2 = OneLogin_Saml2_Response(settings, xml_2)
7878
decrypted = self.file_contents(join(self.data_path, 'responses', 'decrypted_valid_encrypted_assertion.xml'))
79-
self.assertEqual(etree.tostring(response_2.get_xml_document()), decrypted)
79+
self.assertEqual(etree.tostring(response_2.get_xml_document(), encoding='unicode'), decrypted)
8080

8181
def testReturnNameId(self):
8282
"""

0 commit comments

Comments
 (0)