summary refs log tree commit diff
path: root/synapse/rest/client/v1/register.py
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2016-03-09 11:26:30 +0000
committerMark Haines <mjark@negativecurvature.net>2016-03-09 11:26:30 +0000
commitb7b899cae617eafc3f7bb9fcf648bb0899ec146a (patch)
treeb8a25b359abf412a692a6f391d142c5cfa9a98bb /synapse/rest/client/v1/register.py
parentEnsure integer is an integer (diff)
parentAdd a parse_json_object function (diff)
downloadsynapse-b7b899cae617eafc3f7bb9fcf648bb0899ec146a.tar.xz
Merge pull request #628 from matrix-org/markjh/parse_json
Add a parse_json_object function

to deduplicate all the copy+pasted _parse_json functions. Also document
the parse_.* functions.
Diffstat (limited to 'synapse/rest/client/v1/register.py')
-rw-r--r--synapse/rest/client/v1/register.py14
1 files changed, 2 insertions, 12 deletions
diff --git a/synapse/rest/client/v1/register.py b/synapse/rest/client/v1/register.py
index 040a7a7ffa..c6a2ef2ccc 100644
--- a/synapse/rest/client/v1/register.py
+++ b/synapse/rest/client/v1/register.py
@@ -20,12 +20,12 @@ from synapse.api.errors import SynapseError, Codes
 from synapse.api.constants import LoginType
 from .base import ClientV1RestServlet, client_path_patterns
 import synapse.util.stringutils as stringutils
+from synapse.http.servlet import parse_json_object_from_request
 
 from synapse.util.async import run_on_reactor
 
 from hashlib import sha1
 import hmac
-import simplejson as json
 import logging
 
 logger = logging.getLogger(__name__)
@@ -98,7 +98,7 @@ class RegisterRestServlet(ClientV1RestServlet):
 
     @defer.inlineCallbacks
     def on_POST(self, request):
-        register_json = _parse_json(request)
+        register_json = parse_json_object_from_request(request)
 
         session = (register_json["session"]
                    if "session" in register_json else None)
@@ -355,15 +355,5 @@ class RegisterRestServlet(ClientV1RestServlet):
             )
 
 
-def _parse_json(request):
-    try:
-        content = json.loads(request.content.read())
-        if type(content) != dict:
-            raise SynapseError(400, "Content must be a JSON object.")
-        return content
-    except ValueError:
-        raise SynapseError(400, "Content not JSON.")
-
-
 def register_servlets(hs, http_server):
     RegisterRestServlet(hs).register(http_server)