def update_file_ext(filename, ext='<STR_LIT>', sep='<STR_LIT:.>'):
path, filename = os.path.split(filename)<EOL>if ext and ext[<NUM_LIT:0>] == sep:<EOL><INDENT>ext = ext[<NUM_LIT:1>:]<EOL><DEDENT>return os.path.join(path, sep.join(filename.split(sep)[:-<NUM_LIT:1> if filename.count(sep) > <NUM_LIT:1> else <NUM_LIT:1>] + [ext]))<EOL>
r"""Force the file or path str to end with the indicated extension

    Note: a dot (".") is assumed to delimit the extension

    >>> from __future__ import unicode_literals
    >>> update_file_ext('/home/hobs/extremofile', 'bac')
    '/home/hobs/extremofile.bac'
    >>> update_file_ext('/home/hobs/piano.file/', 'music')
    '/home/hobs/piano.file/.music'
    >>> update_file_ext('/home/ninja.hobs/Anglofile', '.uk')
    '/home/ninja.hobs/Anglofile.uk'
    >>> update_file_ext('/home/ninja-corsi/audio', 'file', sep='-')
    '/home/ninja-corsi/audio-file'