Example #1
0
def decode_body(content, charset):
    if content is None:
        return None
    if content == b'':
        return ''
    if charset:
        charset = six.ensure_unicode(charset)
        return content.decode(charset, errors='ignore')

    # todo: encoding detect
    try:
        return content.decode('utf-8')
    except:
        pass
    try:
        return content.decode('gb18030')
    except:
        pass

    return '{decode content failed, unknown charset}'