def latinify(unicode_string, default='?', pure_ascii=False):
 from unicodedata import name
 converted = []
 for unich in iter(unicode_string):
  try:
   ch = unich.decode('ascii')
  except UnicodeDecodeError:
   what = name(unich)
   if (what in _UNICODE_MAP):
    ch = _UNICODE_MAP[what]
   else:
    what = what.split()
    if ((what[0] == 'LATIN') and (what[2] == 'LETTER') and (len(what[3]) == 1)):
     ch = (what[3].lower() if (what[1] == 'SMALL') else what[3].upper())
    else:
     ch = default
  converted.append(chr(ord(ch)))
 return ''.join(converted)

def latinify ( unicode_string , default = '?' , pure_ascii = False ) : from unicodedata import name converted = [ ] for unich in iter ( unicode_string ) : try : ch = unich . decode ( 'ascii' ) except UnicodeDecodeError : what = name ( unich ) if ( what in _UNICODE_MAP ) : ch = _UNICODE_MAP [ what ] else : what = what . split ( ) if ( ( what [ 0 ] == 'LATIN' ) and ( what [ 2 ] == 'LETTER' ) and ( len ( what [ 3 ] ) == 1 ) ) : ch = ( what [ 3 ] . lower ( ) if ( what [ 1 ] == 'SMALL' ) else what [ 3 ] . upper ( ) ) else : ch = default converted . append ( chr ( ord ( ch ) ) ) return '' . join ( converted )
convert a unicode string to "safe" ascii/latin-1 characters .