Changeset 8382 for main/waeup.kofa/trunk/src
- Timestamp:
- 7 May 2012, 10:53:25 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/smtp.py
r8379 r8382 93 93 94 94 def encode_header_item(item): 95 """Turns `item`, a string into an SMTP header part string. 96 97 Encodings are checked carefully (we try to encode as ASCII, 98 Latin-1 and UTF-8 in that order). 99 100 If `item` is not a basestring, `None` is returned. 101 """ 102 if not isinstance(item, basestring): 103 return None 95 104 if not isinstance(item, unicode): 96 try: 97 item = unicode(item, 'utf-8') 98 except TypeError: 99 return None 105 item = unicode(item, 'utf-8') 100 106 return str(Header(item, 'iso-8859-1')) # try ascii, then latin1, then utf-8 101 107 -
main/waeup.kofa/trunk/src/waeup/kofa/tests/test_smtp.py
r7819 r8382 75 75 result3 = encode_header_item(u'Plain Name') 76 76 result4 = encode_header_item(u'Name with umläut') 77 result5 = encode_header_item(None) 77 78 self.assertEqual(result1, u'Plain Name') 78 79 self.assertEqual(result2, u'=?iso-8859-1?q?Name_with_uml=E4ut?=') 79 80 self.assertEqual(result3, u'Plain Name') 80 81 self.assertEqual(result4, u'=?iso-8859-1?q?Name_with_uml=E4ut?=') 82 self.assertTrue(result5 is None) 81 83 return 82 84
Note: See TracChangeset for help on using the changeset viewer.