code: def alternative_filename(filename, attempt=None):
      '''
      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
      '''
      filename_parts = filename.rsplit(u'.', 2)
      name = filename_parts[0]
      ext = ''.join(u'.%s' % ext for ext in filename_parts[1:])
      if attempt is None:
          choose = random.choice
          extra = u' %s' % ''.join(choose(fs_safe_characters) for i in range(8))
      else:
          extra = u' (%d)' % attempt
      return u'%s%s%s' % (name, extra, extf alternative_filename(filename, attempt=None):
      '''
      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
      '''
      filename_parts = filename.rsplit(u'.', 2)
      name = filename_parts[0]
      ext = ''.join(u'.%s' % ext for ext in filename_parts[1:])
      if attempt is None:
          choose = random.choice
          extra = u' %s' % ''.join(choose(fs_safe_characters) for i in range(8))
      else:
          extra = u' (%d)' % attempt
      return u'%s%s%s' % (name, extra, ext)
docs: 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