def normalize_encoding(encoding):
 if isinstance(encoding, bytes):
  encoding = str(encoding, 'ascii')
 chars = []
 punct = False
 for c in encoding:
  if (c.isalnum() or (c == '.')):
   if (punct and chars):
    chars.append('_')
   chars.append(c)
   punct = False
  else:
   punct = True
 return ''.join(chars)

def normalize_encoding ( encoding ) : if isinstance ( encoding , bytes ) : encoding = str ( encoding , 'ascii' ) chars = [ ] punct = False for c in encoding : if ( c . isalnum ( ) or ( c == '.' ) ) : if ( punct and chars ) : chars . append ( '_' ) chars . append ( c ) punct = False else : punct = True return '' . join ( chars )
normalize an encoding name .