1181
1181
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1183
def __init__(self, source, target, is_permament=False):
1183
def __init__(self, source, target, is_permament=False, qual_proto=None):
1184
1184
self.source = source
1185
1185
self.target = target
1186
1186
if is_permament:
1189
1189
self.permanently = ''
1190
1190
self.is_permament = is_permament
1191
self._qualified_proto = qual_proto
1191
1192
TransportError.__init__(self)
1194
def _requalify_url(self, url):
1195
"""Restore the qualified proto in front of the url"""
1196
# When this exception is raised, source and target are in
1197
# user readable format. But some transports mau use a
1198
# different proto (http+urllib:// will present http:// to
1199
# the user. If a qualified proto is specified, the code
1200
# trapping the exeception can get the qualified urls to
1201
# properly handle the redirection themself (creating a
1202
# new transport object from the target url for example).
1203
if self._qualified_proto is None:
1206
# The TODO related to NotBranchError mention that doing
1207
# that kind of manipulation on the urls may not be the
1208
# exception object job. On the other hand, this object is
1209
# the interface between the code and the user so
1210
# presenting the urls in different ways is indeed its
1213
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1214
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1217
def get_source_url(self):
1218
return self._requalify_url(self.source)
1220
def get_target_url(self):
1221
return self._requalify_url(self.source)
1194
1224
class UnknownHint(TransportError):