|
14 | 14 | from urllib.parse import unquote_plus
|
15 | 15 | from urllib.parse import urlparse
|
16 | 16 | from http.cookies import SimpleCookie
|
17 |
| -from typing import Iterable |
18 | 17 |
|
19 | 18 | from saml2 import SAMLError, xmldsig
|
20 | 19 | from saml2.config import IdPConfig
|
@@ -743,12 +742,15 @@ def _handle_authn_response(self, context, internal_response):
|
743 | 742 | if self.KEY_CO_ATTRIBUTES in co_config:
|
744 | 743 | attributes = internal_response.attributes
|
745 | 744 | for attribute, value in co_config[self.KEY_CO_ATTRIBUTES].items():
|
746 |
| - attributes[attribute] = ( |
747 |
| - value # keep the value as is |
748 |
| - if isinstance(value, Iterable) # if it is already a list |
749 |
| - and not isinstance(value, str) # and not a string |
750 |
| - else [value] # otherwise wrap in a list |
751 |
| - ) |
| 745 | + # This should be refactored when Python 3.4 support is |
| 746 | + # no longer required to use isinstance(value, Iterable). |
| 747 | + try: |
| 748 | + if iter(value) and not isinstance(value, str): |
| 749 | + attributes[attribute] = value |
| 750 | + else: |
| 751 | + attributes[attribute] = [value] |
| 752 | + except TypeError: |
| 753 | + attributes[attribute] = [value] |
752 | 754 |
|
753 | 755 | # Handle the authentication response.
|
754 | 756 | return super()._handle_authn_response(context, internal_response, idp)
|
|
0 commit comments