def alternative_filename(filename, attempt=None):
filename_parts = filename.rsplit(u'<STR_LIT:.>', <NUM_LIT:2>)<EOL>name = filename_parts[<NUM_LIT:0>]<EOL>ext = '<STR_LIT>'.join(u'<STR_LIT>' % ext for ext in filename_parts[<NUM_LIT:1>:])<EOL>if attempt is None:<EOL><INDENT>choose = random.choice<EOL>extra = u'<STR_LIT>' % '<STR_LIT>'.join(choose(fs_safe_characters) for i in range(<NUM_LIT:8>))<EOL><DEDENT>else:<EOL><INDENT>extra = u'<STR_LIT>' % attempt<EOL><DEDENT>return u'<STR_LIT>' % (name, extra, ext)<EOL>
Generates an alternative version of given filename.

If an number attempt parameter is given, will be used on the alternative
name, a random value will be used otherwise.

:param filename: original filename
:param attempt: optional attempt number, defaults to null
:return: new filename
:rtype: str or unicode