Skip to content

Commit

Permalink
Merge pull request #108 from lionick/add_doseq_upstream
Browse files Browse the repository at this point in the history
Support multiple values for a key param
  • Loading branch information
rohe authored Sep 15, 2024
2 parents 0c48026 + 4b325b4 commit 313777e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/idpyoidc/message/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ def set_defaults(self):
for key, val in self.c_default.items():
self._dict.setdefault(key, val)

def to_urlencoded(self):
def to_urlencoded(self, doseq=False):
"""
Creates a string using the application/x-www-form-urlencoded format
:doseq: If set to true, key=value pairs separated by '&' are generated for each element of the value sequence for the key.
:return: A string of the application/x-www-form-urlencoded format
"""

Expand Down Expand Up @@ -135,15 +136,15 @@ def to_urlencoded(self):
params.append((key, str(val)))

try:
return urlencode(params)
return urlencode(params, doseq=doseq)
except UnicodeEncodeError:
_val = []
for k, v in params:
try:
_val.append((k, v.encode("utf-8")))
except TypeError:
_val.append((k, v))
return urlencode(_val)
return urlencode(_val, doseq=doseq)

def serialize(self, method="urlencoded", **kwargs):
"""
Expand Down

0 comments on commit 313777e

Please sign in to comment.