Skip to content

Commit 433a788

Browse files
committed
Refactor create_authn_request loop param
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 614b56d commit 433a788

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/saml2/client_base.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,22 +341,17 @@ def create_authn_request(self, destination, vorg="", scoping=None,
341341
# Allow argument values either as class instances or as dictionaries
342342
# all of these have cardinality 0..1
343343
_msg = AuthnRequest()
344-
for param in ["scoping", "requested_authn_context", "conditions",
345-
"subject"]:
346-
try:
347-
_item = kwargs[param]
348-
except KeyError:
349-
pass
344+
for param in ["scoping", "requested_authn_context", "conditions", "subject"]:
345+
_item = kwargs.pop(param, None)
346+
if not _item:
347+
continue
348+
349+
if isinstance(_item, _msg.child_class(param)):
350+
args[param] = _item
351+
elif isinstance(_item, dict):
352+
args[param] = RequestedAuthnContext(**_item)
350353
else:
351-
del kwargs[param]
352-
# either class instance or argument dictionary
353-
if isinstance(_item, _msg.child_class(param)):
354-
args[param] = _item
355-
elif isinstance(_item, dict):
356-
args[param] = RequestedAuthnContext(**_item)
357-
else:
358-
raise ValueError("%s or wrong type expected %s" % (_item,
359-
param))
354+
raise ValueError("Wrong type for param {name}".format(name=param))
360355

361356
try:
362357
args["name_id_policy"] = kwargs["name_id_policy"]

0 commit comments

Comments
 (0)