def urlify(s, maxlen=80, keep_underscores=False):
 s = to_unicode(s)
 s = s.lower()
 s = unicodedata.normalize('NFKD', s)
 s = to_native(s, charset='ascii', errors='ignore')
 s = re.sub('&\\w+?;', '', s)
 if keep_underscores:
  s = re.sub('\\s+', '-', s)
  s = re.sub('[^\\w\\-]', '', s)
 else:
  s = re.sub('[\\s_]+', '-', s)
  s = re.sub('[^a-z0-9\\-]', '', s)
 s = re.sub('[-_][-_]+', '-', s)
 s = s.strip('-')
 return s[:maxlen]

def urlify ( s , maxlen = 80 , keep_underscores = False ) : s = to_unicode ( s ) s = s . lower ( ) s = unicodedata . normalize ( 'NFKD' , s ) s = to_native ( s , charset = 'ascii' , errors = 'ignore' ) s = re . sub ( '&\\w+?;' , '' , s ) if keep_underscores : s = re . sub ( '\\s+' , '-' , s ) s = re . sub ( '[^\\w\\-]' , '' , s ) else : s = re . sub ( '[\\s_]+' , '-' , s ) s = re . sub ( '[^a-z0-9\\-]' , '' , s ) s = re . sub ( '[-_][-_]+' , '-' , s ) s = s . strip ( '-' ) return s [ : maxlen ]
converts incoming string to a simplified ascii subset .