(pkg_info, field)
return text
Hack to coax Unicode out of an email Message() - Python 3.3+
Hack to coax Unicode out of an email Message() - Python 3.3+
Hack to coax Unicode out of an email Message () - Python 3 . 3 +
def pkginfo_unicode(pkg_info, field):
    """Hack to coax Unicode out of an email Message() - Python 3.3+"""
    text = pkg_info[field]
    field = field.lower()
    if not isinstance(text, str):
        if not hasattr(pkg_info, 'raw_items'):  # Python 3.2
            return str(text)
        for item in pkg_info.raw_items():
            if item[0].lower() == field:
                text = item[1].encode('ascii', 'surrogateescape') \
                    .decode('utf-8')
                break

    return text
def pkginfo_unicode ( pkg_info , field ) : text = pkg_info [ field ] field = field . lower ( ) if not isinstance ( text , str ) : if not hasattr ( pkg_info , 'raw_items' ) : # Python 3.2 return str ( text ) for item in pkg_info . raw_items ( ) : if item [ 0 ] . lower ( ) == field : text = item [ 1 ] . encode ( 'ascii' , 'surrogateescape' ) . decode ( 'utf-8' ) break return text