def clean_text(text):
    """
    Return a text suitable for SPDX license identifier detection cleaned
    from certain leading and trailing punctuations and normalized for spaces.
    """
    text = ' '.join(text.split())
    punctuation_spaces = '!"#$%&\'*,-./:;<=>?@[\\]^_`{|}~\t\r\n '
    leading_punctuation_spaces = punctuation_spaces + ')+'
    trailng_punctuation_spaces = punctuation_spaces + '('
    return text.lstrip(leading_punctuation_spaces).rstrip(
        trailng_punctuation_spaces)
