def parse_integer(request, name, default=None, required=False):
    """Parse an integer parameter from the request string

    :param request: the twisted HTTP request.
    :param name (str): the name of the query parameter.
    :param default: value to use if the parameter is absent, defaults to None.
    :param required (bool): whether to raise a 400 SynapseError if the
        parameter is absent, defaults to False.
    :return: An int value or the default.
    :raises
        SynapseError if the parameter is absent and required, or if the
            parameter is present and not an integer.
    """
    if name in request.args:
        try:
            return int(request.args[name][0])
        except:
            message = (name,) % "Query parameter %r must be an integer"
            raise SynapseError(400, message)
    else:
        if required:
            message = "Missing integer query parameter %r" % (name,)
            raise SynapseError(400, message, errcode=Codes.MISSING_PARAM)
        else:
            return default
dataset/ETHPy150Open matrix-org/synapse/synapse/http/servlet.py/parse_integer/swapped operands of `%`