summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Mattrat <mattr.felix@gmail.com>2016-04-14 13:05:36 +0200
committerFélix Mattrat <mattr.felix@gmail.com>2016-04-14 13:05:36 +0200
commit5066bafc3c29f9d5babb600de48f90b70f543019 (patch)
tree15476e6b881fc20876a74127125cf9be5474fc16
parentb4d10b102d54b8c8e429ac3025f857bb067b02d4 (diff)
downloadpython-fastimport-git-5066bafc3c29f9d5babb600de48f90b70f543019.tar.gz
python 3 compatibility, futurize stage 1
-rw-r--r--fastimport/commands.py10
-rw-r--r--fastimport/parser.py13
-rw-r--r--fastimport/processor.py3
-rw-r--r--fastimport/processors/query_processor.py7
-rw-r--r--fastimport/tests/test_commands.py20
-rw-r--r--fastimport/tests/test_parser.py6
6 files changed, 31 insertions, 28 deletions
diff --git a/fastimport/commands.py b/fastimport/commands.py
index d83b905..c23a337 100644
--- a/fastimport/commands.py
+++ b/fastimport/commands.py
@@ -321,15 +321,15 @@ class FileModifyCommand(FileCommand):
return self.to_string(include_file_contents=False)
def _format_mode(self, mode):
- if mode in (0755, 0100755):
+ if mode in (0o755, 0o100755):
return "755"
- elif mode in (0644, 0100644):
+ elif mode in (0o644, 0o100644):
return "644"
- elif mode == 040000:
+ elif mode == 0o40000:
return "040000"
- elif mode == 0120000:
+ elif mode == 0o120000:
return "120000"
- elif mode == 0160000:
+ elif mode == 0o160000:
return "160000"
else:
raise AssertionError("Unknown mode %o" % mode)
diff --git a/fastimport/parser.py b/fastimport/parser.py
index 5f81eef..8db0d64 100644
--- a/fastimport/parser.py
+++ b/fastimport/parser.py
@@ -157,6 +157,7 @@ The grammar is:
comment ::= '#' not_lf* lf;
not_lf ::= # Any byte that is not ASCII newline (LF);
"""
+from __future__ import print_function
import collections
@@ -526,7 +527,7 @@ class ImportParser(LineBasedParser):
try:
when = self.date_parser(datestr, self.lineno)
except ValueError:
- print "failed to parse datestr '%s'" % (datestr,)
+ print("failed to parse datestr '%s'" % (datestr,))
raise
name = match.group(1)
email = match.group(2)
@@ -601,15 +602,15 @@ class ImportParser(LineBasedParser):
"""
# Note: Output from git-fast-export slightly different to spec
if s in ['644', '100644', '0100644']:
- return 0100644
+ return 0o100644
elif s in ['755', '100755', '0100755']:
- return 0100755
+ return 0o100755
elif s in ['040000', '0040000']:
- return 040000
+ return 0o40000
elif s in ['120000', '0120000']:
- return 0120000
+ return 0o120000
elif s in ['160000', '0160000']:
- return 0160000
+ return 0o160000
else:
self.abort(errors.BadFormat, 'filemodify', 'mode', s)
diff --git a/fastimport/processor.py b/fastimport/processor.py
index 13aa987..a9ebf01 100644
--- a/fastimport/processor.py
+++ b/fastimport/processor.py
@@ -29,11 +29,12 @@ To import from a fast-import stream to your version-control system:
See git-fast-import.1 for the meaning of each command and the
processors package for examples.
"""
+from __future__ import absolute_import
import sys
import time
-import errors
+from . import errors
class ImportProcessor(object):
diff --git a/fastimport/processors/query_processor.py b/fastimport/processors/query_processor.py
index c2e750f..b9dab70 100644
--- a/fastimport/processors/query_processor.py
+++ b/fastimport/processors/query_processor.py
@@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Import processor that queries the input (and doesn't import)."""
+from __future__ import print_function
from fastimport import (
@@ -54,13 +55,13 @@ class QueryProcessor(processor.ImportProcessor):
return
if self.interesting_commit and cmd.name == 'commit':
if cmd.mark == self.interesting_commit:
- print cmd.to_string()
+ print(cmd.to_string())
self._finished = True
return
- if self.parsed_params.has_key(cmd.name):
+ if cmd.name in self.parsed_params:
fields = self.parsed_params[cmd.name]
str = cmd.dump_str(fields, self.parsed_params, self.verbose)
- print "%s" % (str,)
+ print("%s" % (str,))
def progress_handler(self, cmd):
"""Process a ProgressCommand."""
diff --git a/fastimport/tests/test_commands.py b/fastimport/tests/test_commands.py
index 0da0773..3b76459 100644
--- a/fastimport/tests/test_commands.py
+++ b/fastimport/tests/test_commands.py
@@ -133,7 +133,7 @@ class TestCommitDisplay(TestCase):
def test_commit_with_filecommands(self):
file_cmds = iter([
commands.FileDeleteCommand('readme.txt'),
- commands.FileModifyCommand('NEWS', 0100644, None,
+ commands.FileModifyCommand('NEWS', 0o100644, None,
'blah blah blah'),
])
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -203,7 +203,7 @@ class TestCommitCopy(TestCase):
super(TestCommitCopy, self).setUp()
file_cmds = iter([
commands.FileDeleteCommand('readme.txt'),
- commands.FileModifyCommand('NEWS', 0100644, None, 'blah blah blah'),
+ commands.FileModifyCommand('NEWS', 0o100644, None, 'blah blah blah'),
])
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
@@ -284,24 +284,24 @@ class TestTagDisplay(TestCase):
class TestFileModifyDisplay(TestCase):
def test_filemodify_file(self):
- c = commands.FileModifyCommand("foo/bar", 0100644, ":23", None)
+ c = commands.FileModifyCommand("foo/bar", 0o100644, ":23", None)
self.assertEqual("M 644 :23 foo/bar", repr(c))
def test_filemodify_file_executable(self):
- c = commands.FileModifyCommand("foo/bar", 0100755, ":23", None)
+ c = commands.FileModifyCommand("foo/bar", 0o100755, ":23", None)
self.assertEqual("M 755 :23 foo/bar", repr(c))
def test_filemodify_file_internal(self):
- c = commands.FileModifyCommand("foo/bar", 0100644, None,
+ c = commands.FileModifyCommand("foo/bar", 0o100644, None,
"hello world")
self.assertEqual("M 644 inline foo/bar\ndata 11\nhello world", repr(c))
def test_filemodify_symlink(self):
- c = commands.FileModifyCommand("foo/bar", 0120000, None, "baz")
+ c = commands.FileModifyCommand("foo/bar", 0o120000, None, "baz")
self.assertEqual("M 120000 inline foo/bar\ndata 3\nbaz", repr(c))
def test_filemodify_treeref(self):
- c = commands.FileModifyCommand("tree-info", 0160000,
+ c = commands.FileModifyCommand("tree-info", 0o160000,
"revision-id-info", None)
self.assertEqual("M 160000 revision-id-info tree-info", repr(c))
@@ -362,7 +362,7 @@ class TestNotesDisplay(TestCase):
from_=None,
merges=[],
file_iter=[
- commands.FileModifyCommand('bar', 0100644, None, '')
+ commands.FileModifyCommand('bar', 0o100644, None, '')
]),
commands.CommitCommand(
ref='refs/notes/commits',
@@ -423,9 +423,9 @@ class TestPathChecking(TestCase):
def test_filemodify_path_checking(self):
self.assertRaises(ValueError, commands.FileModifyCommand, "",
- 0100644, None, "text")
+ 0o100644, None, "text")
self.assertRaises(ValueError, commands.FileModifyCommand, None,
- 0100644, None, "text")
+ 0o100644, None, "text")
def test_filedelete_path_checking(self):
self.assertRaises(ValueError, commands.FileDeleteCommand, "")
diff --git a/fastimport/tests/test_parser.py b/fastimport/tests/test_parser.py
index ff0b8e1..38acb87 100644
--- a/fastimport/tests/test_parser.py
+++ b/fastimport/tests/test_parser.py
@@ -199,7 +199,7 @@ class TestImportParser(unittest.TestCase):
file_cmd1 = result.pop(0)
self.assertEqual('filemodify', file_cmd1.name)
self.assertEqual('README', file_cmd1.path)
- self.assertEqual(0100644, file_cmd1.mode)
+ self.assertEqual(0o100644, file_cmd1.mode)
self.assertEqual('Welcome from bugs\n', file_cmd1.data)
cmd5 = result.pop(0)
self.assertEqual('commit', cmd5.name)
@@ -215,7 +215,7 @@ class TestImportParser(unittest.TestCase):
file_cmd2 = result.pop(0)
self.assertEqual('filemodify', file_cmd2.name)
self.assertEqual('README', file_cmd2.path)
- self.assertEqual(0100644, file_cmd2.mode)
+ self.assertEqual(0o100644, file_cmd2.mode)
self.assertEqual('Welcome from bugs, etc.', file_cmd2.data)
cmd6 = result.pop(0)
self.assertEqual(cmd6.name, 'checkpoint')
@@ -237,7 +237,7 @@ class TestImportParser(unittest.TestCase):
file_cmd1 = result.pop(0)
self.assertEqual('filemodify', file_cmd1.name)
self.assertEqual('tree-id', file_cmd1.path)
- self.assertEqual(0160000, file_cmd1.mode)
+ self.assertEqual(0o160000, file_cmd1.mode)
self.assertEqual("rev-id", file_cmd1.dataref)
cmd = result.pop(0)
self.assertEqual('feature', cmd.name)