def unormalize(ustring, ignorenonascii=None, substitute=None):
 if (ignorenonascii is not None):
  warn('ignorenonascii is deprecated, use substitute named parameter instead', DeprecationWarning, stacklevel=2)
  if ignorenonascii:
   substitute = ''
 res = []
 for letter in ustring[:]:
  try:
   replacement = MANUAL_UNICODE_MAP[letter]
  except KeyError:
   replacement = _uninormalize('NFKD', letter)[0]
   if (ord(replacement) >= (2 ** 7)):
    if (substitute is None):
     raise ValueError("can't deal with non-ascii based characters")
    replacement = substitute
  res.append(replacement)
 return u''.join(res)

def unormalize ( ustring , ignorenonascii = None , substitute = None ) : if ( ignorenonascii is not None ) : warn ( 'ignorenonascii is deprecated, use substitute named parameter instead' , DeprecationWarning , stacklevel = 2 ) if ignorenonascii : substitute = '' res = [ ] for letter in ustring [ : ] : try : replacement = MANUAL_UNICODE_MAP [ letter ] except KeyError : replacement = _uninormalize ( 'NFKD' , letter ) [ 0 ] if ( ord ( replacement ) >= ( 2 ** 7 ) ) : if ( substitute is None ) : raise ValueError ( "can't deal with non-ascii based characters" ) replacement = substitute res . append ( replacement ) return u'' . join ( res )
replace diacritical characters with their corresponding ascii characters convert the unicode string to its long normalized form and keep the first one only .