def truncate_path(path, length=MAX_FILENAME_LENGTH):
 comps = components(path)
 out = [c[:length] for c in comps]
 (base, ext) = os.path.splitext(comps[(-1)])
 if ext:
  base = base[:(length - len(ext))]
  out[(-1)] = (base + ext)
 return os.path.join(*out)

def truncate_path ( path , length = MAX_FILENAME_LENGTH ) : comps = components ( path ) out = [ c [ : length ] for c in comps ] ( base , ext ) = os . path . splitext ( comps [ ( - 1 ) ] ) if ext : base = base [ : ( length - len ( ext ) ) ] out [ ( - 1 ) ] = ( base + ext ) return os . path . join ( * out )
given a bytestring path or a unicode path fragment .