synapse/http/servlet.py
def parse_json_value_from_request(request, allow_empty_body=False):
    """Parse a JSON value from the body of a twisted HTTP request.

    Args:
        request: the twisted HTTP request.
        allow_empty_body (bool): if True, an empty body will be accepted and
            turned into None

    Returns:
        The JSON value.

    Raises:
        SynapseError if the request body couldn't be decoded as JSON.
    """
    try:
        content_bytes = request.content.read()
    except Exception:
        raise SynapseError(400, "Error reading JSON content.")

    if not content_bytes and allow_empty_body:
        return None

    try:
        content = simplejson.loads(content_bytes)
    except Exception as e:
        logger.warn("Unable to parse JSON: %s", e)
        raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)

    return content
Parse a JSON value from the body of a twisted HTTP request.

    Args:
        request: the twisted HTTP request.
        allow_empty_body (bool): if True, an empty body will be accepted and
            turned into None

    Returns:
        The JSON value.

    Raises:
        SynapseError if the request body couldn't be decoded as JSON.
    
Parse a JSON value from the body of a twisted HTTP request.
Args:
request: the twisted HTTP request.
allow_empty_body (bool): if True, an empty body will be accepted and
turned into None

The JSON value.

SynapseError if the request body couldn't be decoded as JSON.
Parse a JSON value from the body of a twisted HTTP request . Args : request : the twisted HTTP request . allow_empty_body ( bool ) : if True an empty body will be accepted and turned into None The JSON value . SynapseError if the request body couldn ' t be decoded as JSON .
def parse_json_value_from_request(request, allow_empty_body=False):
    try:
        content_bytes = request.content.read()
    except Exception:
        raise SynapseError(400, "Error reading JSON content.")
    if not content_bytes and allow_empty_body:
        return None
    try:
        content = simplejson.loads(content_bytes)
    except Exception as e:
        logger.warn("Unable to parse JSON: %s", e)
        raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)
    return content
def parse_json_value_from_request ( request , allow_empty_body = False ) : try : content_bytes = request . content . read ( ) except Exception : raise SynapseError ( 400 , "Error reading JSON content." ) if not content_bytes and allow_empty_body : return None try : content = simplejson . loads ( content_bytes ) except Exception as e : logger . warn ( "Unable to parse JSON: %s" , e ) raise SynapseError ( 400 , "Content not JSON." , errcode = Codes . NOT_JSON ) return content
Parse a JSON value from the body of a twisted HTTP request.
Parse a JSON value from the body of a twisted HTTP request .
"""Parse a JSON value from the body of a twisted HTTP request.

    Args:
        request: the twisted HTTP request.
        allow_empty_body (bool): if True, an empty body will be accepted and
            turned into None

    Returns:
        The JSON value.

    Raises:
        SynapseError if the request body couldn't be decoded as JSON.
    """
request
allow_empty_body