summary refs log tree commit diff
path: root/synapse/http/servlet.py
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2016-09-15 13:27:09 +0100
committerGitHub <noreply@github.com>2016-09-15 13:27:09 +0100
commite457034e99d46d32e3d71eddb12cda07d8a0370e (patch)
tree2b3cc4cbf5a17a6de91c6f07e47b038b22186921 /synapse/http/servlet.py
parentMerge pull request #1117 from matrix-org/erikj/fix_state (diff)
parentBy default limit /publicRooms to 100 entries (diff)
downloadsynapse-e457034e99d46d32e3d71eddb12cda07d8a0370e.tar.xz
Merge pull request #1121 from matrix-org/erikj/public_room_paginate
Add pagination support to publicRooms
Diffstat (limited to 'synapse/http/servlet.py')
-rw-r--r--synapse/http/servlet.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py
index e41afeab8e..9346386238 100644
--- a/synapse/http/servlet.py
+++ b/synapse/http/servlet.py
@@ -41,9 +41,13 @@ def parse_integer(request, name, default=None, required=False):
         SynapseError: if the parameter is absent and required, or if the
             parameter is present and not an integer.
     """
-    if name in request.args:
+    return parse_integer_from_args(request.args, name, default, required)
+
+
+def parse_integer_from_args(args, name, default=None, required=False):
+    if name in args:
         try:
-            return int(request.args[name][0])
+            return int(args[name][0])
         except:
             message = "Query parameter %r must be an integer" % (name,)
             raise SynapseError(400, message)
@@ -116,9 +120,15 @@ def parse_string(request, name, default=None, required=False,
             parameter is present, must be one of a list of allowed values and
             is not one of those allowed values.
     """
+    return parse_string_from_args(
+        request.args, name, default, required, allowed_values, param_type,
+    )
 
-    if name in request.args:
-        value = request.args[name][0]
+
+def parse_string_from_args(args, name, default=None, required=False,
+                           allowed_values=None, param_type="string"):
+    if name in args:
+        value = args[name][0]
         if allowed_values is not None and value not in allowed_values:
             message = "Query parameter %r must be one of [%s]" % (
                 name, ", ".join(repr(v) for v in allowed_values)