def get_offset_and_limit(data, max_limit=None, default_offset=0, default_limit=20):
    """从数据中获取偏移量和每页数量。get offset and limit from data.

    Examples::

        offset, limit = get_offset_and_limit(request.data, max_limit=100)

    :type data: dict
    :type max_limit: int
    :type default_offset: int
    :type default_limit: int
    :rtype: (int, int)
    """
    offset = int(data.get("offset", default_offset))
    limit = int(data.get("limit", default_limit))
    if offset < 0 or limit < offset:
        raise ValueError("偏移量或每页数量低于限制，请重新选择")
    if max_limit and limit > max_limit:
        raise ValueError("每页数量不能多于 {} 个，请重新选择".format(max_limit))
    return offset, limit