def get_grid_selection(grid, cursor=True):
    """
    Returns grid's currently selected rows and cols,
    falling back to cursor row and col, as ([row, ], [col, ]).
    """
    rows, cols = [], []
    if grid.GetSelectedCols():
        cols += sorted(grid.GetSelectedCols())
        rows += range(grid.GetNumberRows())
    if grid.GetSelectedRows():
        rows += sorted(grid.GetSelectedRows())
        cols += range(grid.GetNumberCols())
    if grid.GetSelectionBlockTopLeft():
        end = grid.GetSelectionBlockBottomRight()
        for i, (r, c) in enumerate(grid.GetSelectionBlockTopLeft()):
            r2, c2 = end[i]
            rows += range(r, r2 + 1)
            cols += range(c, c2 + 1)
    if grid.GetSelectedCells():
        rows += [r for r, c in grid.GetSelectedCells()]
        cols += [c for r, c in grid.GetSelectedCells()]
    if not rows and not cols and cursor:
        if grid.GridCursorRow >= 0 and grid.GridCursorCol >= 0:
            rows, cols = [grid.GridCursorRow], [grid.GridCursorCol]
    rows, cols = (sorted(set(y for y in x if y >= 0)) for x in (rows, cols))
    return rows, cols