import unicodedata

ABECEDA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def deaccent(unistr):
    return ''.join(aChar 
                   for aChar in unicodedata.normalize('NFD', unistr) 
                   if not unicodedata.combining(aChar))

def ocesat(text, mezery=True):
    text = deaccent(unicode(text)).upper()
    if mezery:
        pole = [' ']
        lastWh = True
        for c in text:
            if c in ABECEDA:
                pole.append(c)
                lastWh = False
            elif not lastWh:
                pole.append(' ')
                lastWh = True
        if not lastWh:
            pole.append(' ')
        return ''.join(pole)
    else: # bez mezer
        return ''.join([c for c in text if c in ABECEDA])
