Cleans up series name.

    By removing any . and _ characters, along with any trailing hyphens.

    Is basically equivalent to replacing all _ and . with a
    space, but handles decimal numbers in string, for example:

    >>> _clean_series_name("an.example.1.0.test")
    'an example 1.0 test'
    >>> _clean_series_name("an_example_1.0_test")
    'an example 1.0 test'

def clean_series_name(seriesname):
    """Cleans up series name.

    By removing any . and _ characters, along with any trailing hyphens.

    Is basically equivalent to replacing all _ and . with a
    space, but handles decimal numbers in string, for example:

    >>> _clean_series_name("an.example.1.0.test")
    'an example 1.0 test'
    >>> _clean_series_name("an_example_1.0_test")
    'an example 1.0 test'
    """
    if not seriesname:
        return seriesname
    # TODO(xxxx): Could this be made to clean "Hawaii.Five-0.2010" into
    # "Hawaii Five-0 2010"?
    seriesname = re.sub(r'(\D)[.](\D)', '\\1 \\2', seriesname)
    seriesname = re.sub(r'(\D)[.]', '\\1 ', seriesname)
    seriesname = re.sub(r'[.](\D)', ' \\1', seriesname)
    seriesname = seriesname.replace('_', ' ')
    seriesname = re.sub('-$', '', seriesname)
    return _replace_series_name(seriesname.strip(),
                                cfg.CONF.input_series_replacements)