Skip to content

Commit

Permalink
Merge pull request #43 from andreashug/py3fix
Browse files Browse the repository at this point in the history
Fix py3 problems with strings and encoding
  • Loading branch information
pitbulk authored Jan 15, 2017
2 parents 5508328 + 1846d82 commit 578c493
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/onelogin/saml2/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
from onelogin.saml2.authn_request import OneLogin_Saml2_Authn_Request


try:
basestring
except NameError:
basestring = str


class OneLogin_Saml2_Auth(object):
"""
Expand Down Expand Up @@ -569,7 +575,7 @@ def get_last_response_xml(self, pretty_print_if_possible=False):
if isinstance(self.__last_response, basestring):
response = self.__last_response
else:
response = etree.tostring(self.__last_response, pretty_print=pretty_print_if_possible)
response = etree.tostring(self.__last_response, encoding='unicode', pretty_print=pretty_print_if_possible)
return response

def get_last_request_xml(self):
Expand Down
3 changes: 2 additions & 1 deletion src/onelogin/saml2/logout_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

from onelogin.saml2 import compat
from onelogin.saml2.constants import OneLogin_Saml2_Constants
from onelogin.saml2.utils import OneLogin_Saml2_Utils, OneLogin_Saml2_Error, OneLogin_Saml2_ValidationError
from onelogin.saml2.xml_templates import OneLogin_Saml2_Templates
Expand Down Expand Up @@ -95,7 +96,7 @@ def __init__(self, settings, request=None, name_id=None, session_index=None, nq=
logout_request = OneLogin_Saml2_Utils.decode_base64_and_inflate(request, ignore_zip=True)
self.id = self.get_id(logout_request)

self.__logout_request = logout_request
self.__logout_request = compat.to_string(logout_request)

def get_request(self, deflate=True):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/onelogin/saml2/logout_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

from onelogin.saml2 import compat
from onelogin.saml2.utils import OneLogin_Saml2_Utils, OneLogin_Saml2_ValidationError
from onelogin.saml2.xml_templates import OneLogin_Saml2_Templates
from onelogin.saml2.xml_utils import OneLogin_Saml2_XML
Expand Down Expand Up @@ -36,7 +37,7 @@ def __init__(self, settings, response=None):
self.__error = None

if response is not None:
self.__logout_response = OneLogin_Saml2_Utils.decode_base64_and_inflate(response)
self.__logout_response = compat.to_string(OneLogin_Saml2_Utils.decode_base64_and_inflate(response))
self.document = OneLogin_Saml2_XML.to_etree(self.__logout_response)

def get_issuer(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/src/OneLogin/saml2_tests/response_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def testGetXMLDocument(self):
xml = self.file_contents(join(self.data_path, 'responses', 'signed_message_response.xml.base64'))
response = OneLogin_Saml2_Response(settings, xml)
prety_xml = self.file_contents(join(self.data_path, 'responses', 'pretty_signed_message_response.xml'))
self.assertEqual(etree.tostring(response.get_xml_document(), pretty_print=True), prety_xml)
self.assertEqual(etree.tostring(response.get_xml_document(), encoding='unicode', pretty_print=True), prety_xml)

xml_2 = self.file_contents(join(self.data_path, 'responses', 'valid_encrypted_assertion.xml.base64'))
response_2 = OneLogin_Saml2_Response(settings, xml_2)
decrypted = self.file_contents(join(self.data_path, 'responses', 'decrypted_valid_encrypted_assertion.xml'))
self.assertEqual(etree.tostring(response_2.get_xml_document()), decrypted)
self.assertEqual(etree.tostring(response_2.get_xml_document(), encoding='unicode'), decrypted)

def testReturnNameId(self):
"""
Expand Down

0 comments on commit 578c493

Please sign in to comment.