7
7
from bzrlib.trace import mutter
8
from bzrlib.errors import BzrError
8
from bzrlib.errors import (BzrError,
9
TransportError, TransportNotPossible, NonRelativePath,
10
NoSuchFile, FileExists, PermissionDenied,
10
13
_protocol_handlers = {
21
24
mutter('registering transport: %s => %s' % (prefix, klass.__name__))
22
25
_protocol_handlers[prefix] = klass
24
class TransportError(BzrError):
25
"""All errors thrown by Transport implementations should derive
28
def __init__(self, msg=None, orig_error=None):
29
if msg is None and orig_error is not None:
31
BzrError.__init__(self, msg)
33
self.orig_error = orig_error
35
class AsyncError(TransportError):
38
# A set of semi-meaningful errors which can be thrown
39
class TransportNotPossible(TransportError):
40
"""This is for transports where a specific function is explicitly not
41
possible. Such as pushing files to an HTTP server.
45
class NonRelativePath(TransportError):
46
"""An absolute path was supplied, that could not be decoded into
51
class NoSuchFile(TransportError, IOError):
52
"""A get() was issued for a file that doesn't exist."""
53
def __init__(self, msg=None, orig_error=None):
55
TransportError.__init__(self, msg=msg, orig_error=orig_error)
56
IOError.__init__(self, errno.ENOENT, self.msg)
58
class FileExists(TransportError, OSError):
59
"""An operation was attempted, which would overwrite an entry,
60
but overwritting is not supported.
62
mkdir() can throw this, but put() just overwites existing files.
64
def __init__(self, msg=None, orig_error=None):
66
TransportError.__init__(self, msg=msg, orig_error=orig_error)
67
OSError.__init__(self, errno.EEXIST, self.msg)
69
class PermissionDenied(TransportError):
70
"""An operation cannot succeed because of a lack of permissions."""
73
class ConnectionReset(TransportError):
74
"""The connection has been closed."""
77
27
class Transport(object):
78
28
"""This class encapsulates methods for retrieving or putting a file
79
29
from/to a storage location.