summaryrefslogtreecommitdiff
path: root/fastimport
diff options
context:
space:
mode:
authorFélix Mattrat <mattr.felix@gmail.com>2016-04-14 13:16:04 +0200
committerFélix Mattrat <mattr.felix@gmail.com>2016-04-14 13:16:04 +0200
commit1980993afa14bf8bd21093551e58c834f0f099e2 (patch)
tree5d568ea723e43d3612cb03fe215129c08b97c69a /fastimport
parent5066bafc3c29f9d5babb600de48f90b70f543019 (diff)
downloadpython-fastimport-git-1980993afa14bf8bd21093551e58c834f0f099e2.tar.gz
python 3 compatibility, futurize stage 2
Diffstat (limited to 'fastimport')
-rw-r--r--fastimport/commands.py15
-rw-r--r--fastimport/parser.py6
-rw-r--r--fastimport/processor.py1
-rw-r--r--fastimport/processors/filter_processor.py2
-rw-r--r--fastimport/processors/query_processor.py4
-rw-r--r--fastimport/tests/test_commands.py3
-rw-r--r--fastimport/tests/test_errors.py1
-rw-r--r--fastimport/tests/test_filter_processor.py4
-rw-r--r--fastimport/tests/test_parser.py28
9 files changed, 42 insertions, 22 deletions
diff --git a/fastimport/commands.py b/fastimport/commands.py
index c23a337..760df8a 100644
--- a/fastimport/commands.py
+++ b/fastimport/commands.py
@@ -18,6 +18,9 @@
These objects are used by the parser to represent the content of
a fast-import stream.
"""
+from __future__ import division
+from past.utils import old_div
+from builtins import object
import stat
@@ -74,7 +77,7 @@ class ImportCommand(object):
"""
interesting = {}
if names is None:
- fields = [k for k in self.__dict__.keys() if not k.startswith('_')]
+ fields = [k for k in list(self.__dict__.keys()) if not k.startswith('_')]
else:
fields = names
for field in fields:
@@ -146,7 +149,7 @@ class CommitCommand(ImportCommand):
if not isinstance(self.file_iter, list):
self.file_iter = list(self.file_iter)
- fields = dict((k, v) for k, v in self.__dict__.iteritems()
+ fields = dict((k, v) for k, v in self.__dict__.items()
if k not in ('id', 'name')
if not k.startswith('_'))
fields.update(kwargs)
@@ -442,18 +445,18 @@ def format_who_when(fields):
offset = abs(offset)
else:
offset_sign = '+'
- offset_hours = offset / 3600
- offset_minutes = offset / 60 - offset_hours * 60
+ offset_hours = old_div(offset, 3600)
+ offset_minutes = old_div(offset, 60) - offset_hours * 60
offset_str = "%s%02d%02d" % (offset_sign, offset_hours, offset_minutes)
name = fields[0]
if name == '':
sep = ''
else:
sep = ' '
- if isinstance(name, unicode):
+ if isinstance(name, str):
name = name.encode('utf8')
email = fields[1]
- if isinstance(email, unicode):
+ if isinstance(email, str):
email = email.encode('utf8')
result = "%s%s<%s> %d %s" % (name, sep, email, fields[2], offset_str)
return result
diff --git a/fastimport/parser.py b/fastimport/parser.py
index 8db0d64..fe59eef 100644
--- a/fastimport/parser.py
+++ b/fastimport/parser.py
@@ -158,6 +158,10 @@ The grammar is:
not_lf ::= # Any byte that is not ASCII newline (LF);
"""
from __future__ import print_function
+from future import standard_library
+standard_library.install_aliases()
+from builtins import map
+from builtins import object
import collections
@@ -593,7 +597,7 @@ class ImportParser(LineBasedParser):
parts[1] = parts[1][1:-1]
elif parts[1].startswith('"') or parts[1].endswith('"'):
self.abort(errors.BadFormat, '?', '?', s)
- return map(_unquote_c_string, parts)
+ return list(map(_unquote_c_string, parts))
def _mode(self, s):
"""Check file mode format and parse into an int.
diff --git a/fastimport/processor.py b/fastimport/processor.py
index a9ebf01..3b601f5 100644
--- a/fastimport/processor.py
+++ b/fastimport/processor.py
@@ -30,6 +30,7 @@ See git-fast-import.1 for the meaning of each command and the
processors package for examples.
"""
from __future__ import absolute_import
+from builtins import object
import sys
import time
diff --git a/fastimport/processors/filter_processor.py b/fastimport/processors/filter_processor.py
index b84a009..5353b58 100644
--- a/fastimport/processors/filter_processor.py
+++ b/fastimport/processors/filter_processor.py
@@ -14,6 +14,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Import processor that filters the input (and doesn't import)."""
+from future import standard_library
+standard_library.install_aliases()
from fastimport import (
diff --git a/fastimport/processors/query_processor.py b/fastimport/processors/query_processor.py
index b9dab70..0ca51bd 100644
--- a/fastimport/processors/query_processor.py
+++ b/fastimport/processors/query_processor.py
@@ -15,6 +15,8 @@
"""Import processor that queries the input (and doesn't import)."""
from __future__ import print_function
+from future import standard_library
+standard_library.install_aliases()
from fastimport import (
@@ -41,7 +43,7 @@ class QueryProcessor(processor.ImportProcessor):
if 'commit-mark' in params:
self.interesting_commit = params['commit-mark']
del params['commit-mark']
- for name, value in params.iteritems():
+ for name, value in params.items():
if value == 1:
# All fields
fields = None
diff --git a/fastimport/tests/test_commands.py b/fastimport/tests/test_commands.py
index 3b76459..45d2a00 100644
--- a/fastimport/tests/test_commands.py
+++ b/fastimport/tests/test_commands.py
@@ -14,6 +14,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Test how Commands are displayed"""
+from future import standard_library
+standard_library.install_aliases()
+from builtins import map
from unittest import TestCase
diff --git a/fastimport/tests/test_errors.py b/fastimport/tests/test_errors.py
index ef87b05..c6ecb79 100644
--- a/fastimport/tests/test_errors.py
+++ b/fastimport/tests/test_errors.py
@@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Test the Import errors"""
+from builtins import str
from unittest import TestCase
diff --git a/fastimport/tests/test_filter_processor.py b/fastimport/tests/test_filter_processor.py
index 74847ad..7169499 100644
--- a/fastimport/tests/test_filter_processor.py
+++ b/fastimport/tests/test_filter_processor.py
@@ -14,8 +14,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Test FilterProcessor"""
+from future import standard_library
+standard_library.install_aliases()
-from cStringIO import StringIO
+from io import StringIO
from unittest import TestCase
diff --git a/fastimport/tests/test_parser.py b/fastimport/tests/test_parser.py
index 38acb87..79f293b 100644
--- a/fastimport/tests/test_parser.py
+++ b/fastimport/tests/test_parser.py
@@ -14,8 +14,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Test the Import parsing"""
+from future import standard_library
+standard_library.install_aliases()
-import StringIO
+import io
import time
import unittest
@@ -29,7 +31,7 @@ from fastimport import (
class TestLineBasedParser(unittest.TestCase):
def test_push_line(self):
- s = StringIO.StringIO("foo\nbar\nbaz\n")
+ s = io.StringIO("foo\nbar\nbaz\n")
p = parser.LineBasedParser(s)
self.assertEqual('foo', p.next_line())
self.assertEqual('bar', p.next_line())
@@ -39,7 +41,7 @@ class TestLineBasedParser(unittest.TestCase):
self.assertEqual(None, p.next_line())
def test_read_bytes(self):
- s = StringIO.StringIO("foo\nbar\nbaz\n")
+ s = io.StringIO("foo\nbar\nbaz\n")
p = parser.LineBasedParser(s)
self.assertEqual('fo', p.read_bytes(2))
self.assertEqual('o\nb', p.read_bytes(3))
@@ -53,7 +55,7 @@ class TestLineBasedParser(unittest.TestCase):
def test_read_until(self):
# TODO
return
- s = StringIO.StringIO("foo\nbar\nbaz\nabc\ndef\nghi\n")
+ s = io.StringIO("foo\nbar\nbaz\nabc\ndef\nghi\n")
p = parser.LineBasedParser(s)
self.assertEqual('foo\nbar', p.read_until('baz'))
self.assertEqual('abc', p.next_line())
@@ -153,7 +155,7 @@ class TestImportParser(unittest.TestCase):
del self.fake_time
def test_iter_commands(self):
- s = StringIO.StringIO(_sample_import_text)
+ s = io.StringIO(_sample_import_text)
p = parser.ImportParser(s)
result = []
for cmd in p.iter_commands():
@@ -271,25 +273,25 @@ class TestImportParser(unittest.TestCase):
self.assertEqual('donald@duck.org', cmd.more_authors[1][1])
def test_done_feature_missing_done(self):
- s = StringIO.StringIO("""feature done
+ s = io.StringIO("""feature done
""")
p = parser.ImportParser(s)
cmds = p.iter_commands()
self.assertEquals("feature", cmds.next().name)
- self.assertRaises(errors.PrematureEndOfStream, cmds.next)
+ self.assertRaises(errors.PrematureEndOfStream, cmds.__next__)
def test_done_with_feature(self):
- s = StringIO.StringIO("""feature done
+ s = io.StringIO("""feature done
done
more data
""")
p = parser.ImportParser(s)
cmds = p.iter_commands()
self.assertEquals("feature", cmds.next().name)
- self.assertRaises(StopIteration, cmds.next)
+ self.assertRaises(StopIteration, cmds.__next__)
def test_done_without_feature(self):
- s = StringIO.StringIO("""done
+ s = io.StringIO("""done
more data
""")
p = parser.ImportParser(s)
@@ -320,7 +322,7 @@ class TestPathPairParsing(unittest.TestCase):
class TestTagParsing(unittest.TestCase):
def test_tagger_with_email(self):
- p = parser.ImportParser(StringIO.StringIO(
+ p = parser.ImportParser(io.StringIO(
"tag refs/tags/v1.0\n"
"from :xxx\n"
"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
@@ -333,7 +335,7 @@ class TestTagParsing(unittest.TestCase):
('Joe Wong', 'joe@example.com', 1234567890.0, -21600))
def test_tagger_no_email_strict(self):
- p = parser.ImportParser(StringIO.StringIO(
+ p = parser.ImportParser(io.StringIO(
"tag refs/tags/v1.0\n"
"from :xxx\n"
"tagger Joe Wong\n"
@@ -342,7 +344,7 @@ class TestTagParsing(unittest.TestCase):
self.assertRaises(errors.BadFormat, list, p.iter_commands())
def test_tagger_no_email_not_strict(self):
- p = parser.ImportParser(StringIO.StringIO(
+ p = parser.ImportParser(io.StringIO(
"tag refs/tags/v1.0\n"
"from :xxx\n"
"tagger Joe Wong\n"