@@ -253,11 +253,10 @@ def parse_strings_from_args(
253
253
args: the twisted HTTP request.args list.
254
254
name: the name of the query parameter.
255
255
default: value to use if the parameter is absent, defaults to None.
256
- required : whether to raise a 400 SynapseError if the
256
+ required: whether to raise a 400 SynapseError if the
257
257
parameter is absent, defaults to False.
258
- allowed_values (list[bytes|unicode]): List of allowed values for the
259
- string, or None if any value is allowed, defaults to None. Must be
260
- the same type as name, if given.
258
+ allowed_values: List of allowed values for the
259
+ string, or None if any value is allowed, defaults to None.
261
260
encoding: The encoding to decode the string content with.
262
261
263
262
Returns:
@@ -281,12 +280,8 @@ def parse_strings_from_args(
281
280
if required :
282
281
message = "Missing string query parameter %r" % (name ,)
283
282
raise SynapseError (400 , message , errcode = Codes .MISSING_PARAM )
284
- else :
285
283
286
- if isinstance (default , bytes ):
287
- return default .decode (encoding )
288
-
289
- return default
284
+ return default
290
285
291
286
292
287
def parse_string_from_args (
@@ -326,12 +321,15 @@ def parse_string_from_args(
326
321
strings = parse_strings_from_args (
327
322
args ,
328
323
name ,
329
- default = [default ],
324
+ default = [default ] if default is not None else None ,
330
325
required = required ,
331
326
allowed_values = allowed_values ,
332
327
encoding = encoding ,
333
328
)
334
329
330
+ if strings is None :
331
+ return None
332
+
335
333
return strings [0 ]
336
334
337
335
0 commit comments