import string


def handle_input_text(text, window):
    """
    Handles input to be acceptable for generation.

    Parameters:
        - text: str
            The text for handle.

        - window: int
            How many windows in the chain.
            Should be same as a `window` parameter of
            the chain, else generation will not work.

    Returns:
        `None` if text is not acceptable else `str`.
        len(string) == window.
        The returned string will contain `window` count
        words from the end of the text.

    Example:
        Input: handle_input_text("A big white fox!?.", 3)
        Output: "big white fox"
    """
    text = text.strip()

    if not text:
        return None

    # we don't want any punctuation symbols at the end
    # of the text because we looking for the start
    # of a sentence, not the end.
    # `text.translate(None, string.punctuation)` shouldn't used here
    # because it removes all punctuation symbols.
    while (text[-1] in string.punctuation):
        text = text[:-1]

    text = text.split()

    if (len(text) < window):
        return None
    else:
        # get `window` number of words from the end of the text.
        return " ".join(text[len(text) - window:])