示例#1
0
文件: utils.py 项目: fengidri/netdump
def decode_body(content, charset):
    if content is None:
        return None
    if content == b'':
        return ''
    if charset:
        charset = six.ensure_unicode(charset)
        try:
            return content.decode(charset)
        except:
            return '{decode content failed with charset: %s}' % charset

    # todo: encoding detect
    try:
        return content.decode('utf-8')
    except:
        pass
    try:
        return content.decode('gb18030')
    except:
        pass
    return '{decode content failed, unknown charset}'
示例#2
0
def decode_body(content, charset):
    if content is None:
        return None
    if content == b'':
        return ''
    if charset:
        charset = six.ensure_unicode(charset)
        try:
            return content.decode(charset)
        except:
            return '{decode content failed with charset: %s}' % charset

    # todo: encoding detect
    try:
        return content.decode('utf-8')
    except:
        pass
    try:
        return content.decode('gb18030')
    except:
        pass
    return '{decode content failed, unknown charset}'
示例#3
0
 def _println(self, line=''):
     line = six.ensure_unicode(line)
     self.buf.write(line)
     self.buf.write('\n')
示例#4
0
 def _println(self, line=''):
     line = six.ensure_unicode(line)
     self.buf.write(line)
     self.buf.write('\n')