예제 #1
0
 def get_details_and_string(self):
     """Get a details dict and expected string."""
     text1 = lambda: [_b("1\n2\n")]
     text2 = lambda: [_b("3\n4\n")]
     bin1 = lambda: [_b("5\n")]
     details = {'text 1': Content(ContentType('text', 'plain'), text1),
         'text 2': Content(ContentType('text', 'strange'), text2),
         'bin 1': Content(ContentType('application', 'binary'), bin1)}
     return (details, "Binary content: bin 1\n"
         "Text attachment: text 1\n------------\n1\n2\n"
         "------------\nText attachment: text 2\n------------\n"
         "3\n4\n------------\n")
예제 #2
0
파일: content.py 프로젝트: endisd/samba
 def _iter_text(self):
     """Worker for iter_text - does the decoding."""
     encoding = self.content_type.parameters.get('charset', 'ISO-8859-1')
     try:
         # 2.5+
         decoder = codecs.getincrementaldecoder(encoding)()
         for bytes in self.iter_bytes():
             yield decoder.decode(bytes)
         final = decoder.decode(_b(''), True)
         if final:
             yield final
     except AttributeError:
         # < 2.5
         bytes = ''.join(self.iter_bytes())
         yield bytes.decode(encoding)