[py3k] Replace uses of 'unicode'

authorRémi Cardona <remi.cardona@free.fr>
changeset5288095c9295
branchdefault
phasepublic
hiddenno
parent revision#7f4cbc65fb96 [visitor] Implement iterator.__next__()
child revision#415dd93be869 py3k: fix bool(nullobject)
files modified by this revision
test/unittest_umessage.py
umessage.py
# HG changeset patch
# User Rémi Cardona <remi.cardona@free.fr>
# Date 1405550599 -7200
# Thu Jul 17 00:43:19 2014 +0200
# Node ID 5288095c92951ddbbcbd395ceb15268996344808
# Parent 7f4cbc65fb9677a206063bdae6eac53d4688fafc
[py3k] Replace uses of 'unicode'

diff --git a/test/unittest_umessage.py b/test/unittest_umessage.py
@@ -18,10 +18,12 @@
1  # with logilab-common.  If not, see <http://www.gnu.org/licenses/>.
2  import sys
3  import email
4  from os.path import join, dirname, abspath
5 
6 +from six import text_type
7 +
8  from logilab.common.testlib import TestCase, unittest_main
9  from logilab.common.umessage import UMessage, decode_QP
10 
11  DATA = join(dirname(abspath(__file__)), 'data')
12 
@@ -38,26 +40,26 @@
13          self.umessage1 = UMessage(msg1)
14          self.umessage2 = UMessage(msg2)
15 
16      def test_get_subject(self):
17          subj = self.umessage2.get('Subject')
18 -        self.assertEqual(type(subj), unicode)
19 +        self.assertEqual(type(subj), text_type)
20          self.assertEqual(subj, u'� LA MER')
21 
22      def test_get_all(self):
23          to = self.umessage2.get_all('To')
24 -        self.assertEqual(type(to[0]), unicode)
25 +        self.assertEqual(type(to[0]), text_type)
26          self.assertEqual(to, [u'�l�ment � accents <alf@logilab.fr>'])
27 
28      def test_get_payload_no_multi(self):
29          payload = self.umessage1.get_payload()
30 -        self.assertEqual(type(payload), unicode)
31 +        self.assertEqual(type(payload), text_type)
32 
33      def test_decode_QP(self):
34          test_line =  '=??b?UmFwaGHrbA==?= DUPONT<raphael.dupont@societe.fr>'
35          test = decode_QP(test_line)
36 -        self.assertEqual(type(test), unicode)
37 +        self.assertEqual(type(test), text_type)
38          self.assertEqual(test, u'Rapha�l DUPONT<raphael.dupont@societe.fr>')
39 
40 
41  if __name__ == '__main__':
42      unittest_main()
diff --git a/umessage.py b/umessage.py
@@ -42,11 +42,11 @@
43  def decode_QP(string):
44      parts = []
45      for decoded, charset in decode_header(string):
46          if not charset :
47              charset = 'iso-8859-15'
48 -        parts.append(unicode(decoded, charset, 'replace'))
49 +        parts.append(decoded.decode(charset, 'replace'))
50 
51      if sys.version_info < (3, 3):
52          # decoding was non-RFC compliant wrt to whitespace handling
53          # see http://bugs.python.org/issue1079
54          return u' '.join(parts)