diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2012-02-28 12:49:37 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2012-02-28 12:49:37 +0100 |
commit | 3238618f956afa5d2f23ee607536c4383f5b1cd8 (patch) | |
tree | 758dac89b0688c38da1dcf16ed07c537af94e796 | |
parent | 0d0a934996871e5245564ba06d4fc3b9b2f5964c (diff) | |
download | python-fastimport-3238618f956afa5d2f23ee607536c4383f5b1cd8.tar.gz |
Implement 'done' feature.
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | fastimport/errors.py | 9 | ||||
-rw-r--r-- | fastimport/parser.py | 4 | ||||
-rw-r--r-- | fastimport/tests/test_parser.py | 26 |
4 files changed, 45 insertions, 0 deletions
@@ -1,3 +1,9 @@ +0.9.1 UNRELEASED + + * Update FSF address in headers. (Dan Callaghan, #868800) + + * Support 'done' feature. (Jelmer Vernooij, #942563) + 0.9.0 2011-01-30 Initial release. diff --git a/fastimport/errors.py b/fastimport/errors.py index 068af6f..afb78bc 100644 --- a/fastimport/errors.py +++ b/fastimport/errors.py @@ -165,6 +165,15 @@ class InvalidTimezone(ParsingError): self.reason = '' +class PrematureEndOfStream(ParsingError): + """Raised when the 'done' feature was specified but missing.""" + + _fmt = (_LOCATION_FMT + "Stream end before 'done' command") + + def __init__(self, lineno): + ParsingError.__init__(self, lineno) + + class UnknownDateFormat(ImportError): """Raised when an unknown date format is given.""" diff --git a/fastimport/parser.py b/fastimport/parser.py index 7612ac0..ca8e294 100644 --- a/fastimport/parser.py +++ b/fastimport/parser.py @@ -272,6 +272,7 @@ class ImportParser(LineBasedParser): self.user_mapper = user_mapper # We auto-detect the date format when a date is first encountered self.date_parser = None + self.features = {} def warning(self, msg): sys.stderr.write("warning line %d: %s\n" % (self.lineno, msg)) @@ -281,6 +282,8 @@ class ImportParser(LineBasedParser): while True: line = self.next_line() if line is None: + if 'done' in self.features: + raise errors.PrematureEndOfStream(self.lineno) break elif len(line) == 0 or line.startswith('#'): continue @@ -387,6 +390,7 @@ class ImportParser(LineBasedParser): value = self._path(parts[1]) else: value = None + self.features[name] = value return commands.FeatureCommand(name, value, lineno=self.lineno) def _parse_file_modify(self, info): diff --git a/fastimport/tests/test_parser.py b/fastimport/tests/test_parser.py index 06270a8..4bf11c7 100644 --- a/fastimport/tests/test_parser.py +++ b/fastimport/tests/test_parser.py @@ -259,6 +259,32 @@ class TestImportParser(testtools.TestCase): self.assertEqual('Donald', cmd.more_authors[1][0]) self.assertEqual('donald@duck.org', cmd.more_authors[1][1]) + def test_done_feature_missing_done(self): + s = StringIO.StringIO("""feature done +""") + p = parser.ImportParser(s) + cmds = p.iter_commands() + self.assertEquals("feature", cmds.next().name) + self.assertRaises(errors.PrematureEndOfStream, cmds.next) + + def test_done_with_feature(self): + s = StringIO.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) + + def test_done_without_feature(self): + s = StringIO.StringIO("""done +more data +""") + p = parser.ImportParser(s) + cmds = p.iter_commands() + self.assertEquals([], list(cmds)) + class TestStringParsing(testtools.TestCase): |