<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _make_valid_filename(value):
 """Takes a string and makes it into a valid filename. replaces accented characters with ASCII equivalent, and removes characters that cannot be converted sensibly to ASCII. additional characters that will removed. This will not touch the extension separator: 'T_est.avi' """


    sysname = platform.system()

    # If the filename starts with a . prepend it with an underscore, so it
    # doesn't become hidden.
    # This is done before calling splitext to handle filename of ".", as
    # splitext acts differently in python 2.5 and 2.6 - 2.5 returns ('', '.')
    # and 2.6 returns ('.', ''), so rather than special case '.', this
    # special-cases all files starting with "." equally (since dotfiles have
    # no extension)
    if value.startswith('.'):
        value = cfg.CONF.replacement_character + value

    # Treat extension seperatly
    value, extension = os.path.splitext(value)

    # Remove any null bytes
    value = value.replace('\0', '')

    # Blacklist of characters
    if sysname == 'Darwin':
        # : is technically allowed, but Finder will treat it as / and will
        # generally cause weird behaviour, so treat it as invalid.
        blacklist = r'/:'
    elif sysname in ['Linux', 'FreeBSD']:
        blacklist = r'/'
    else:
        # platform.system docs say it could also return "Windows" or "Java".
        # Failsafe and use Windows sanitisation for Java, as it could be any
        # operating system.
        blacklist = r'\/:*?\"<>|'

    # Append custom blacklisted characters
    blacklist += cfg.CONF.filename_character_blacklist

    # Replace every blacklisted character with a underscore
    value = re.sub('[%s]' % re.escape(blacklist),
                   cfg.CONF.replacement_character, value)

    # Remove any trailing whitespace
    value = value.strip()

    # There are a bunch of filenames that are not allowed on Windows.
    # As with character blacklist, treat non Darwin/Linux platforms as Windows
    if sysname not in ['Darwin', 'Linux']:
        invalid_filenames = ['CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2',
                             'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8',
                             'COM9', 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5',
                             'LPT6', 'LPT7', 'LPT8', 'LPT9']
        if value in invalid_filenames:
            value = cfg.CONF.replacement_character + value

    # Replace accented characters with ASCII equivalent
    value = encodeutils.safe_encode(value, encoding='ascii', errors='ignore')
    extension = encodeutils.safe_encode(extension, encoding='ascii',
                                        errors='ignore')

    # Truncate filenames to valid/sane length.
    # NTFS is limited to 255 characters, HFS+ and EXT3 don't seem to have
    # limits, FAT32 is 254. I doubt anyone will take issue with losing that
    # one possible character, and files over 254 are pointlessly unweidly
    max_len = 254

    if len(value + extension) > max_len:
        if len(extension) > len(value):
            # Truncate extension instead of filename, no extension should be
            # this long..
            new_length = max_len - len(value)
            extension = extension[:new_length]
        else:
            # File name is longer than extension, truncate filename.
            new_length = max_len - len(extension)
            value = value[:new_length]

    return encodeutils.safe_decode(value + extension, incoming='ascii')