Skip to content

Commit 09f19c7

Browse files
author
Roland Hedberg
committed
Made all create_* methods return the same type of response.
1 parent e5a49f2 commit 09f19c7

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/saml2/client_base.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@
3737
import time
3838
from saml2.soap import make_soap_enveloped_saml_thingy
3939

40-
try:
41-
from urlparse import parse_qs
42-
except ImportError:
43-
# Compatibility with Python <= 2.5
44-
from cgi import parse_qs
40+
from urlparse import parse_qs
4541

4642
from saml2.s_utils import signature, UnravelError
4743
from saml2.s_utils import do_attributes
@@ -124,7 +120,8 @@ def __init__(self, config=None, identity_cache=None, state_cache=None,
124120
self.want_assertions_signed = False
125121
self.want_response_signed = False
126122
for foo in ["allow_unsolicited", "authn_requests_signed",
127-
"logout_requests_signed", "want_assertions_signed", "want_response_signed"]:
123+
"logout_requests_signed", "want_assertions_signed",
124+
"want_response_signed"]:
128125
v = self.config.getattr(foo, "sp")
129126
if v is True or v == 'true':
130127
setattr(self, foo, True)
@@ -304,8 +301,8 @@ def create_authn_request(self, destination, vorg="", scoping=None,
304301
except KeyError:
305302
pass
306303

307-
rid = ""
308-
if (sign and self.sec.cert_handler.generate_cert()) or client_crt is not None:
304+
if (sign and self.sec.cert_handler.generate_cert()) or \
305+
client_crt is not None:
309306
with self.lock:
310307
self.sec.cert_handler.update_cert(True, client_crt)
311308
if client_crt is not None:
@@ -442,15 +439,11 @@ def create_assertion_id_request(self, assertion_id_refs, **kwargs):
442439
:param assertion_id_refs:
443440
:return: One ID ref
444441
"""
445-
# id_refs = [AssertionIDRef(text=s) for s in assertion_id_refs]
446-
#
447-
# return self._message(AssertionIDRequest, destination, id, consent,
448-
# extensions, sign, assertion_id_ref=id_refs )
449442

450443
if isinstance(assertion_id_refs, basestring):
451-
return assertion_id_refs
444+
return 0, assertion_id_refs
452445
else:
453-
return assertion_id_refs[0]
446+
return 0, assertion_id_refs[0]
454447

455448
def create_authn_query(self, subject, destination=None, authn_context=None,
456449
session_index="", message_id=0, consent=None,
@@ -509,7 +502,8 @@ def create_name_id_mapping_request(self, name_id_policy,
509502

510503
# ======== response handling ===========
511504

512-
def parse_authn_request_response(self, xmlstr, binding, outstanding=None, outstanding_certs=None):
505+
def parse_authn_request_response(self, xmlstr, binding, outstanding=None,
506+
outstanding_certs=None):
513507
""" Deal with an AuthnResponse
514508
515509
:param xmlstr: The reply as a xml string
@@ -536,7 +530,8 @@ def parse_authn_request_response(self, xmlstr, binding, outstanding=None, outsta
536530
"return_addrs": self.service_urls(),
537531
"entity_id": self.config.entityid,
538532
"attribute_converters": self.config.attribute_converters,
539-
"allow_unknown_attributes": self.config.allow_unknown_attributes,
533+
"allow_unknown_attributes":
534+
self.config.allow_unknown_attributes,
540535
}
541536
try:
542537
resp = self._parse_response(xmlstr, AuthnResponse,
@@ -654,6 +649,10 @@ def create_ecp_authn_request(self, entityid=None, relay_state="",
654649

655650
try:
656651
authn_req = kwargs["authn_req"]
652+
try:
653+
req_id = authn_req.id
654+
except AttributeError:
655+
req_id = 0 # Unknown but since it's SOAP it doesn't matter
657656
except KeyError:
658657
try:
659658
_binding = kwargs["binding"]
@@ -697,7 +696,8 @@ def parse_ecp_authn_response(self, txt, outstanding=None):
697696

698697
return response, _relay_state
699698

700-
def can_handle_ecp_response(self, response):
699+
@staticmethod
700+
def can_handle_ecp_response(response):
701701
try:
702702
accept = response.headers["accept"]
703703
except KeyError:
@@ -715,7 +715,8 @@ def can_handle_ecp_response(self, response):
715715
# IDP discovery
716716
# ----------------------------------------------------------------------
717717

718-
def create_discovery_service_request(self, url, entity_id, **kwargs):
718+
@staticmethod
719+
def create_discovery_service_request(url, entity_id, **kwargs):
719720
"""
720721
Created the HTTP redirect URL needed to send the user to the
721722
discovery service.

0 commit comments

Comments
 (0)