瀏覽代碼

Fix the build on python3.

Jelmer Vernooij 7 年之前
父節點
當前提交
947ceca8b2
共有 3 個文件被更改,包括 43 次插入43 次删除
  1. 5 5
      dulwich/mailmap.py
  2. 32 32
      dulwich/tests/test_mailmap.py
  3. 6 6
      dulwich/tests/test_porcelain.py

+ 5 - 5
dulwich/mailmap.py

@@ -43,12 +43,12 @@ def read_mailmap(f):
     """
     for line in f:
         # Remove comments
-        line = line.split('#')[0]
+        line = line.split(b'#')[0]
         line = line.strip()
         if not line:
             continue
-        (canonical_identity, from_identity) = line.split('>', 1)
-        canonical_identity += ">"
+        (canonical_identity, from_identity) = line.split(b'>', 1)
+        canonical_identity += b">"
         if from_identity.strip():
             parsed_from_identity = parse_identity(from_identity)
         else:
@@ -103,9 +103,9 @@ class Mailmap(object):
         if was_tuple:
             return identity
         else:
-            return "%s <%s>" % identity
+            return identity[0] + b" <" + identity[1] + b">"
 
     @classmethod
     def from_path(cls, path):
-        with open(path, 'r') as f:
+        with open(path, 'rb') as f:
             return cls(read_mailmap(f))

+ 32 - 32
dulwich/tests/test_mailmap.py

@@ -30,7 +30,7 @@ from dulwich.mailmap import Mailmap, read_mailmap
 class ReadMailmapTests(TestCase):
 
     def test_read(self):
-        b = BytesIO("""\
+        b = BytesIO(b"""\
 Jane Doe         <jane@desktop.(none)>
 Joe R. Developer <joe@example.com>
 # A comment
@@ -41,16 +41,16 @@ Other Author <other@author.xx>         <nick2@company.xx>
 Santa Claus <santa.claus@northpole.xx> <me@company.xx>
 """)
         self.assertEqual([
-            (('Jane Doe', 'jane@desktop.(none)'), None),
-            (('Joe R. Developer', 'joe@example.com'), None),
-            ((None, 'cto@company.xx'), (None, 'cto@coompany.xx')),
-            (('Some Dude', 'some@dude.xx'), ('nick1', 'bugs@company.xx')),
-            (('Other Author', 'other@author.xx'),
-                ('nick2', 'bugs@company.xx')),
-            (('Other Author', 'other@author.xx'),
-                (None, 'nick2@company.xx')),
-            (('Santa Claus', 'santa.claus@northpole.xx'),
-                (None, 'me@company.xx'))],
+            ((b'Jane Doe', b'jane@desktop.(none)'), None),
+            ((b'Joe R. Developer', b'joe@example.com'), None),
+            ((None, b'cto@company.xx'), (None, b'cto@coompany.xx')),
+            ((b'Some Dude', b'some@dude.xx'), (b'nick1', b'bugs@company.xx')),
+            ((b'Other Author', b'other@author.xx'),
+                (b'nick2', b'bugs@company.xx')),
+            ((b'Other Author', b'other@author.xx'),
+                (None, b'nick2@company.xx')),
+            ((b'Santa Claus', b'santa.claus@northpole.xx'),
+                (None, b'me@company.xx'))],
             list(read_mailmap(b)))
 
 
@@ -58,33 +58,33 @@ class MailmapTests(TestCase):
 
     def test_lookup(self):
         m = Mailmap()
-        m.add_entry(('Jane Doe', 'jane@desktop.(none)'), (None, None))
-        m.add_entry(('Joe R. Developer', 'joe@example.com'), None)
-        m.add_entry((None, 'cto@company.xx'), (None, 'cto@coompany.xx'))
+        m.add_entry((b'Jane Doe', b'jane@desktop.(none)'), (None, None))
+        m.add_entry((b'Joe R. Developer', b'joe@example.com'), None)
+        m.add_entry((None, b'cto@company.xx'), (None, b'cto@coompany.xx'))
         m.add_entry(
-                ('Some Dude', 'some@dude.xx'),
-                ('nick1', 'bugs@company.xx'))
+                (b'Some Dude', b'some@dude.xx'),
+                (b'nick1', b'bugs@company.xx'))
         m.add_entry(
-                ('Other Author', 'other@author.xx'),
-                ('nick2', 'bugs@company.xx'))
+                (b'Other Author', b'other@author.xx'),
+                (b'nick2', b'bugs@company.xx'))
         m.add_entry(
-                ('Other Author', 'other@author.xx'),
-                (None, 'nick2@company.xx'))
+                (b'Other Author', b'other@author.xx'),
+                (None, b'nick2@company.xx'))
         m.add_entry(
-                ('Santa Claus', 'santa.claus@northpole.xx'),
-                (None, 'me@company.xx'))
+                (b'Santa Claus', b'santa.claus@northpole.xx'),
+                (None, b'me@company.xx'))
         self.assertEqual(
-            'Jane Doe <jane@desktop.(none)>',
-            m.lookup('Jane Doe <jane@desktop.(none)>'))
+            b'Jane Doe <jane@desktop.(none)>',
+            m.lookup(b'Jane Doe <jane@desktop.(none)>'))
         self.assertEqual(
-            'Jane Doe <jane@desktop.(none)>',
-            m.lookup('Jane Doe <jane@example.com>'))
+            b'Jane Doe <jane@desktop.(none)>',
+            m.lookup(b'Jane Doe <jane@example.com>'))
         self.assertEqual(
-            'Jane Doe <jane@desktop.(none)>',
-            m.lookup('Jane D. <jane@desktop.(none)>'))
+            b'Jane Doe <jane@desktop.(none)>',
+            m.lookup(b'Jane D. <jane@desktop.(none)>'))
         self.assertEqual(
-            'Some Dude <some@dude.xx>',
-            m.lookup('nick1 <bugs@company.xx>'))
+            b'Some Dude <some@dude.xx>',
+            m.lookup(b'nick1 <bugs@company.xx>'))
         self.assertEqual(
-            'CTO <cto@company.xx>',
-            m.lookup('CTO <cto@coompany.xx>'))
+            b'CTO <cto@company.xx>',
+            m.lookup(b'CTO <cto@coompany.xx>'))

+ 6 - 6
dulwich/tests/test_porcelain.py

@@ -1279,16 +1279,16 @@ class MailmapTests(PorcelainTestCase):
 
     def test_no_mailmap(self):
         self.assertEqual(
-            'Jelmer Vernooij <jelmer@samba.org>',
+            b'Jelmer Vernooij <jelmer@samba.org>',
             porcelain.check_mailmap(
-                self.repo, 'Jelmer Vernooij <jelmer@samba.org>'))
+                self.repo, b'Jelmer Vernooij <jelmer@samba.org>'))
 
     def test_mailmap_lookup(self):
-        with open(os.path.join(self.repo.path, '.mailmap'), 'w') as f:
-            f.write("""\
+        with open(os.path.join(self.repo.path, '.mailmap'), 'wb') as f:
+            f.write(b"""\
 Jelmer Vernooij <jelmer@debian.org>
 """)
         self.assertEqual(
-            'Jelmer Vernooij <jelmer@debian.org>',
+            b'Jelmer Vernooij <jelmer@debian.org>',
             porcelain.check_mailmap(
-                self.repo, 'Jelmer Vernooij <jelmer@samba.org>'))
+                self.repo, b'Jelmer Vernooij <jelmer@samba.org>'))