Calculate the next occurrence of a repeatable reminder

def next_occurrence(reminder):
    """
    Calculate the next occurrence of a repeatable reminder
    """
    now = datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)
    now_dow = now.weekday()

    # Start/end dow starting from tomorrow
    start_dow = now_dow + 1
    end_dow = start_dow + 7

    # Modded range from tomorrow until 1 week from now. Normalizes
    # wraparound values that span into next week
    dow_iter = imap(lambda x: x % 7, xrange(start_dow, end_dow))

    # Filter out any days that aren't in the schedule
    dow_iter = ifilter(lambda x: x in reminder['repeat'], dow_iter)

    # Get the first one. That's the next day of week
    try:
        next_dow = next(dow_iter)
    except StopIteration:  # How?
        logger.exception("Somehow, we didn't get a next day of week?")
        _scheduled.discard(reminder['_id'])
        return

    # Get the real day delta. Take the next day of the week. if that day of
    # the week is before the current day of the week, add a week. Normalize
    # this value by subtracting the starting point. Example:
    # Now = 3, Next = 1, Delta = (1 + 7) - 3 = 5
    day_delta = next_dow
    if next_dow <= now_dow:
        day_delta += 7
    day_delta -= now_dow

    # Update the record
    return reminder['when'] + datetime.timedelta(days=day_delta), day_delta