Comment 1 for bug 142290

Revision history for this message
Andreas Jung (ajung) wrote :

Status: Pending => Accepted

 Supporters added: ajung

def join_unicode(rendered):
    """join a list of plain strings into a single plain string,
    a list of unicode strings into a single unicode strings,
    or a list containing a mix into a single unicode string with
    the plain strings converted from latin-1
    """
    try:
        return ''.join(rendered)
    except UnicodeError:
        # A mix of unicode string and non-ascii plain strings.
        # Fix up the list, treating normal strings as latin-1
        rendered = list(rendered)
        for i in range(len(rendered)):
            if type(rendered[i]) is StringType:
                rendered[i] = unicode(rendered[i],'latin-1')
        return u''.join(rendered)

Wouldn't it be better to use sys.getdefaultencoding()
instead of "latin-1". This would allow users to specify
their encoding site-wide. Using 'latin-1' is definitely
a bad choice.

-aj