def parse_list_query(query, length):
    """Parses the SEP2 query string parameters associated with list resources.

    There is some defensive code here to avoid errors on negative numbers.

    :param query: The request QUERY PARAMS dictionary
    :param length: Length of the list
    :return: (start index 0 based, limit) - xrange style
    """
    params = {a[0]: a[1] for a in map(lambda x: x.split('='), query.split("&"))} if len(query) > 0 else {}
    start = max(0, int(params.get('s', '0')))
    limit = max(0, min(length, start + int(params.get('l', '255'))))
    return start, limit