~bzr/bzr-fastimport/0.6

« back to all changes in this revision

Viewing changes to errors.py

  • Committer: Ian Clatworthy
  • Date: 2008-02-14 06:28:42 UTC
  • Revision ID: ian.clatworthy@internode.on.net-20080214062842-x2yy4rk70ny1ounp
1st cut: gfi parser + --info processing method

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Exception classes for fastimport"""
 
18
 
 
19
from bzrlib import errors as bzr_errors
 
20
 
 
21
 
 
22
# Prefix to messages to show location information
 
23
_LOCATION_FMT = "line %(lineno)d: "
 
24
 
 
25
 
 
26
class ImportError(bzr_errors.BzrError):
 
27
    """The base exception class for all import processing exceptions."""
 
28
 
 
29
    _fmt = "Unknown Import Error"
 
30
 
 
31
 
 
32
class ParsingError(ImportError):
 
33
    """The base exception class for all import processing exceptions."""
 
34
 
 
35
    _fmt = _LOCATION_FMT + "Unknown Import Parsing Error"
 
36
 
 
37
    def __init__(self, lineno):
 
38
        ImportError.__init__(self)
 
39
        self.lineno = lineno
 
40
 
 
41
 
 
42
class MissingBytes(ParsingError):
 
43
    """Raised when EOF encountered while expecting to find more bytes."""
 
44
 
 
45
    _fmt = (_LOCATION_FMT + "Unexpected EOF - expected %(expected)d bytes,"
 
46
        " found %(found)d")
 
47
 
 
48
    def __init__(self, lineno, expected, found):
 
49
        ParsingError.__init__(self, lineno)
 
50
        self.expected = expected
 
51
        self.found = found
 
52
 
 
53
 
 
54
class MissingTerminator(ParsingError):
 
55
    """Raised when EOF encountered while expecting to find a terminator."""
 
56
 
 
57
    _fmt = (_LOCATION_FMT +
 
58
        "Unexpected EOF - expected '%(terminator)s' terminator")
 
59
 
 
60
    def __init__(self, lineno, terminator):
 
61
        ParsingError.__init__(self, lineno)
 
62
        self.terminator = terminator
 
63
 
 
64
 
 
65
class InvalidCommand(ParsingError):
 
66
    """Raised when an unknown command found."""
 
67
 
 
68
    _fmt = (_LOCATION_FMT + "Invalid command '%(cmd)s'")
 
69
 
 
70
    def __init__(self, lineno, cmd):
 
71
        ParsingError.__init__(self, lineno)
 
72
        self.cmd = cmd
 
73
 
 
74
 
 
75
class MissingSection(ParsingError):
 
76
    """Raised when a section is required in a command but not present."""
 
77
 
 
78
    _fmt = (_LOCATION_FMT + "Command %(cmd)s is missing section %(section)s")
 
79
 
 
80
    def __init__(self, lineno, cmd, section):
 
81
        ParsingError.__init__(self, lineno)
 
82
        self.cmd = cmd
 
83
        self.section = section
 
84
 
 
85
 
 
86
class BadFormat(ParsingError):
 
87
    """Raised when a section is formatted incorrectly."""
 
88
 
 
89
    _fmt = (_LOCATION_FMT + "Bad format for section %(section)s in "
 
90
        "command %(cmd)s: found '%(text)s'")
 
91
 
 
92
    def __init__(self, lineno, cmd, section, text):
 
93
        ParsingError.__init__(self, lineno)
 
94
        self.cmd = cmd
 
95
        self.section = section
 
96
        self.text = text
 
97
 
 
98
 
 
99
class InvalidTimezone(ParsingError):
 
100
    """Raised when converting a string timezone to a seconds offset."""
 
101
 
 
102
    _fmt = (_LOCATION_FMT +
 
103
        "Timezone %(timezone)r could not be converted.%(reason)s")
 
104
 
 
105
    def __init__(self, lineno, timezone, reason=None):
 
106
        ParsingError.__init__(self, lineno)
 
107
        self.timezone = timezone
 
108
        if reason:
 
109
            self.reason = ' ' + reason
 
110
        else:
 
111
            self.reason = ''
 
112
 
 
113
 
 
114
class UnknownDateFormat(ImportError):
 
115
    """Raised when an unknown date format is given."""
 
116
 
 
117
    _fmt = ("Unknown date format '%(format)s'")
 
118
 
 
119
    def __init__(self, format):
 
120
        ImportError.__init__(self)
 
121
        self.format = format
 
122
 
 
123
 
 
124
class MissingHandler(ImportError):
 
125
    """Raised when a processor can't handle a command."""
 
126
 
 
127
    _fmt = ("Missing handler for command %(cmd)s")
 
128
 
 
129
    def __init__(self, cmd):
 
130
        ImportError.__init__(self)
 
131
        self.cmd = cmd