'Widen a piece of arbitrary text'

def WidenText(self, text, encoding):

    if (type(text) != types.StringType):
        return text
    if encoding:
        try:
            result = unicode(text, encoding)
            if (not (encoding in self._learned)):
                self._learned.append(encoding)
            return result
        except UnicodeError:
            pass
        except LookupError:
            output.Warn(('Unknown    encoding:    %s' % encoding))
    if self._user:
        try:
            return unicode(text, self._user)
        except UnicodeError:
            pass
        except LookupError:
            temp = self._user
            self._user = None
            output.Warn(('Unknown    default_encoding:    %s' % temp))
    while self._learned:
        try:
            return unicode(text, self._learned[0])
        except:
            del self._learned[0]
    try:
        return unicode(text, ENC_UTF8)
    except UnicodeError:
        pass
    output.Warn(('Unrecognized    encoding    in    text:    %s' % text))
    if (not self._user):
        output.Warn('You    may    need    to    set    a    default_encoding    in    your    configuration    file.')
    return text.decode(ENC_ASCII, 'ignore')
