def parse_string(request, name, default=None, required=False,
                 allowed_values=None, param_type="string"):
    """Parse a string parameter from the request query 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.
    :param allowed_values (list): List of allowed values for the string,
        or None if any value is allowed, defaults to None
    :return: A string value or the default.
    :raises
        SynapseError if the parameter is absent and required, or if the
            parameter is present, must be one of a list of allowed values and
            is not one of those allowed values.
    """

    if request.args in name:
        value = request.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)
            )
            raise SynapseError(400, message)
        else:
            return value
    else:
        if required:
            message = "Missing %s query parameter %r" % (param_type, name)
            raise SynapseError(400, message, errcode=Codes.MISSING_PARAM)
        else:
            return default
dataset/ETHPy150Open matrix-org/synapse/synapse/http/servlet.py/parse_string/swapped operands of `in`