'Create a Unicode string
If that fails, let Tcl try its best'

def decode(self, chars):

    if chars.startswith(BOM_UTF8):
        try:
            chars = chars[3:].decode('utf-8')
        except UnicodeError:
            return chars
        else:
            self.fileencoding = BOM_UTF8
            return chars
    try:
        enc = coding_spec(chars)
    except LookupError as name:
        tkMessageBox.showerror(title='Error    loading    the    file', message=("The    encoding    '%s'    is    not    known    to    this    Python    installation.    The    file    may    not    display    correctly" % name), master=self.text)
        enc = None
    if enc:
        try:
            return unicode(chars, enc)
        except UnicodeError:
            pass
    try:
        return unicode(chars, 'ascii')
    except UnicodeError:
        pass
    try:
        chars = unicode(chars, encoding)
        self.fileencoding = encoding
    except UnicodeError:
        pass
    return chars
