45
45
def __init__(self, base):
46
46
"""Set the base path where files will be stored."""
47
super(HttpTransport, self).__init__(base)
49
def _get_url(self, url, method=None):
50
mutter("get_url %s" % url)
47
super(HttpTransport_urllib, self).__init__(base)
49
def get(self, relpath):
50
"""Get the file at the given relative path.
52
:param relpath: The relative path to the file
54
return self._get(relpath, [])
56
def _get(self, relpath, ranges):
59
path = self._real_abspath(relpath)
60
return self._get_url_impl(path, method=method, ranges=ranges)
61
except urllib2.HTTPError, e:
62
mutter('url error code: %s for has url: %r', e.code, path)
64
raise NoSuchFile(path, extra=e)
66
except (BzrError, IOError), e:
67
if hasattr(e, 'errno'):
68
mutter('io error: %s %s for has url: %r',
69
e.errno, errno.errorcode.get(e.errno), path)
70
if e.errno == errno.ENOENT:
71
raise NoSuchFile(path, extra=e)
72
raise ConnectionError(msg = "Error retrieving %s: %s"
73
% (self.abspath(relpath), str(e)),
76
def _get_url_impl(self, url, method, ranges):
81
mutter("get_url %s [%s]" % (url, range_string))
51
82
manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
52
83
url = extract_auth(url, manager)
53
84
auth_handler = urllib2.HTTPBasicAuthHandler(manager)
66
99
def has(self, relpath):
67
100
"""Does the target location exist?
102
abspath = self._real_abspath(relpath)
71
path = self._real_abspath(relpath)
72
f = self._get_url(path, 'HEAD')
104
f = self._get_url_impl(abspath, 'HEAD', [])
73
105
# Without the read and then close()
74
106
# we tend to have busy sockets.
78
110
except urllib2.URLError, e:
79
mutter('url error code: %s for has url: %r', e.code, path)
111
mutter('url error code: %s for has url: %r', e.code, abspath)
83
115
except IOError, e:
84
mutter('io error: %s %s for has url: %r',
85
e.errno, errno.errorcode.get(e.errno), path)
116
mutter('io error: %s %s for has url: %r',
117
e.errno, errno.errorcode.get(e.errno), abspath)
86
118
if e.errno == errno.ENOENT:
88
120
raise TransportError(orig_error=e)
90
def get(self, relpath):
91
"""Get the file at the given relative path.
93
:param relpath: The relative path to the file
97
path = self._real_abspath(relpath)
98
return self._get_url(path)
99
except urllib2.HTTPError, e:
100
mutter('url error code: %s for has url: %r', e.code, path)
102
raise NoSuchFile(path, extra=e)
104
except (BzrError, IOError), e:
105
if hasattr(e, 'errno'):
106
mutter('io error: %s %s for has url: %r',
107
e.errno, errno.errorcode.get(e.errno), path)
108
if e.errno == errno.ENOENT:
109
raise NoSuchFile(path, extra=e)
110
raise ConnectionError(msg = "Error retrieving %s: %s"
111
% (self._real_abspath(relpath), str(e)),
114
122
def copy_to(self, relpaths, other, mode=None, pb=None):
115
123
"""Copy a set of entries from self into another Transport.
119
127
TODO: if other is LocalTransport, is it possible to
120
128
do better than put(get())?
122
# At this point HttpTransport might be able to check and see if
130
# At this point HttpTransport_urllib might be able to check and see if
123
131
# the remote location is the same, and rather than download, and
124
132
# then upload, it could just issue a remote copy_this command.
125
if isinstance(other, HttpTransport):
133
if isinstance(other, HttpTransport_urllib):
126
134
raise TransportNotPossible('http cannot be the target of copy_to()')
128
return super(HttpTransport, self).copy_to(relpaths, other, mode=mode, pb=pb)
136
return super(HttpTransport_urllib, self).copy_to(relpaths, other, mode=mode, pb=pb)
130
138
def move(self, rel_from, rel_to):
131
139
"""Move the item at rel_from to the location at rel_to"""
150
158
def get_test_permutations():
151
159
"""Return the permutations to be used in testing."""
152
return [(HttpTransport, HttpServer_urllib),
160
return [(HttpTransport_urllib, HttpServer_urllib),