def unique_path(path):
 if (not os.path.exists(syspath(path))):
  return path
 (base, ext) = os.path.splitext(path)
 match = re.search('\\.(\\d)+$', base)
 if match:
  num = int(match.group(1))
  base = base[:match.start()]
 else:
  num = 0
 while True:
  num += 1
  suffix = (u'.{}'.format(num).encode() + ext)
  new_path = (base + suffix)
  if (not os.path.exists(new_path)):
   return new_path

def unique_path ( path ) : if ( not os . path . exists ( syspath ( path ) ) ) : return path ( base , ext ) = os . path . splitext ( path ) match = re . search ( '\\.(\\d)+$' , base ) if match : num = int ( match . group ( 1 ) ) base = base [ : match . start ( ) ] else : num = 0 while True : num += 1 suffix = ( u'.{}' . format ( num ) . encode ( ) + ext ) new_path = ( base + suffix ) if ( not os . path . exists ( new_path ) ) : return new_path
returns a version of path that does not exist on the filesystem .