Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / dulwich / errors.py @ 959

History | View | Annotate | Download (5.14 KB)

1
# errors.py -- errors for dulwich
2
# Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
3
# Copyright (C) 2009-2012 Jelmer Vernooij <jelmer@samba.org>
4
#
5
# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
6
# General Public License as public by the Free Software Foundation; version 2.0
7
# or (at your option) any later version. You can redistribute it and/or
8
# modify it under the terms of either of these two licenses.
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
#
16
# You should have received a copy of the licenses; if not, see
17
# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
18
# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
19
# License, Version 2.0.
20
#
21

    
22
"""Dulwich-related exception classes and utility functions."""
23

    
24
import binascii
25

    
26

    
27
class ChecksumMismatch(Exception):
28
    """A checksum didn't match the expected contents."""
29

    
30
    def __init__(self, expected, got, extra=None):
31
        if len(expected) == 20:
32
            expected = binascii.hexlify(expected)
33
        if len(got) == 20:
34
            got = binascii.hexlify(got)
35
        self.expected = expected
36
        self.got = got
37
        self.extra = extra
38
        if self.extra is None:
39
            Exception.__init__(self,
40
                "Checksum mismatch: Expected %s, got %s" % (expected, got))
41
        else:
42
            Exception.__init__(self,
43
                "Checksum mismatch: Expected %s, got %s; %s" %
44
                (expected, got, extra))
45

    
46

    
47
class WrongObjectException(Exception):
48
    """Baseclass for all the _ is not a _ exceptions on objects.
49

50
    Do not instantiate directly.
51

52
    Subclasses should define a type_name attribute that indicates what
53
    was expected if they were raised.
54
    """
55

    
56
    def __init__(self, sha, *args, **kwargs):
57
        Exception.__init__(self, "%s is not a %s" % (sha, self.type_name))
58

    
59

    
60
class NotCommitError(WrongObjectException):
61
    """Indicates that the sha requested does not point to a commit."""
62

    
63
    type_name = 'commit'
64

    
65

    
66
class NotTreeError(WrongObjectException):
67
    """Indicates that the sha requested does not point to a tree."""
68

    
69
    type_name = 'tree'
70

    
71

    
72
class NotTagError(WrongObjectException):
73
    """Indicates that the sha requested does not point to a tag."""
74

    
75
    type_name = 'tag'
76

    
77

    
78
class NotBlobError(WrongObjectException):
79
    """Indicates that the sha requested does not point to a blob."""
80

    
81
    type_name = 'blob'
82

    
83

    
84
class MissingCommitError(Exception):
85
    """Indicates that a commit was not found in the repository"""
86

    
87
    def __init__(self, sha, *args, **kwargs):
88
        self.sha = sha
89
        Exception.__init__(self, "%s is not in the revision store" % sha)
90

    
91

    
92
class ObjectMissing(Exception):
93
    """Indicates that a requested object is missing."""
94

    
95
    def __init__(self, sha, *args, **kwargs):
96
        Exception.__init__(self, "%s is not in the pack" % sha)
97

    
98

    
99
class ApplyDeltaError(Exception):
100
    """Indicates that applying a delta failed."""
101

    
102
    def __init__(self, *args, **kwargs):
103
        Exception.__init__(self, *args, **kwargs)
104

    
105

    
106
class NotGitRepository(Exception):
107
    """Indicates that no Git repository was found."""
108

    
109
    def __init__(self, *args, **kwargs):
110
        Exception.__init__(self, *args, **kwargs)
111

    
112

    
113
class GitProtocolError(Exception):
114
    """Git protocol exception."""
115

    
116
    def __init__(self, *args, **kwargs):
117
        Exception.__init__(self, *args, **kwargs)
118

    
119

    
120
class SendPackError(GitProtocolError):
121
    """An error occurred during send_pack."""
122

    
123
    def __init__(self, *args, **kwargs):
124
        Exception.__init__(self, *args, **kwargs)
125

    
126

    
127
class UpdateRefsError(GitProtocolError):
128
    """The server reported errors updating refs."""
129

    
130
    def __init__(self, *args, **kwargs):
131
        self.ref_status = kwargs.pop('ref_status')
132
        Exception.__init__(self, *args, **kwargs)
133

    
134

    
135
class HangupException(GitProtocolError):
136
    """Hangup exception."""
137

    
138
    def __init__(self):
139
        Exception.__init__(self,
140
            "The remote server unexpectedly closed the connection.")
141

    
142

    
143
class UnexpectedCommandError(GitProtocolError):
144
    """Unexpected command received in a proto line."""
145

    
146
    def __init__(self, command):
147
        if command is None:
148
            command = 'flush-pkt'
149
        else:
150
            command = 'command %s' % command
151
        GitProtocolError.__init__(self, 'Protocol got unexpected %s' % command)
152

    
153

    
154
class FileFormatException(Exception):
155
    """Base class for exceptions relating to reading git file formats."""
156

    
157

    
158
class PackedRefsException(FileFormatException):
159
    """Indicates an error parsing a packed-refs file."""
160

    
161

    
162
class ObjectFormatException(FileFormatException):
163
    """Indicates an error parsing an object."""
164

    
165

    
166
class NoIndexPresent(Exception):
167
    """No index is present."""
168

    
169

    
170
class CommitError(Exception):
171
    """An error occurred while performing a commit."""
172

    
173

    
174
class RefFormatError(Exception):
175
    """Indicates an invalid ref name."""
176

    
177

    
178
class HookError(Exception):
179
    """An error occurred while executing a hook."""