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}'
def _println(self, line=''): line = six.ensure_unicode(line) self.buf.write(line) self.buf.write('\n')