14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from cStringIO import StringIO
19
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
20
from bzrlib.lazy_import import lazy_import
17
from __future__ import absolute_import
20
from ..lazy_import import lazy_import
21
21
lazy_import(globals(), """
24
transport as _mod_transport,
26
from bzrlib.bundle import serializer as _serializer
27
from bzrlib.merge_directive import MergeDirective
28
from bzrlib.transport import (
29
do_catching_redirections,
27
from breezy.bundle import serializer as _serializer
28
from breezy.merge_directive import MergeDirective
29
from breezy.i18n import gettext
33
from bzrlib.trace import note
36
@deprecated_function(deprecated_in((1, 12, 0)))
37
def read_bundle_from_url(url):
38
return read_mergeable_from_url(url, _do_directive=False)
31
from ..sixish import (
34
from ..trace import note
41
37
def read_mergeable_from_url(url, _do_directive=True, possible_transports=None):
44
40
:return: An object supporting get_target_revision. Raises NotABundle if
45
41
the target is not a mergeable type.
47
child_transport = get_transport(url,
48
possible_transports=possible_transports)
43
child_transport = _mod_transport.get_transport(url,
44
possible_transports=possible_transports)
49
45
transport = child_transport.clone('..')
50
46
filename = transport.relpath(child_transport.base)
51
47
mergeable, transport = read_mergeable_from_transport(transport, filename,
56
52
def read_mergeable_from_transport(transport, filename, _do_directive=True):
57
53
def get_bundle(transport):
58
return StringIO(transport.get_bytes(filename)), transport
54
return BytesIO(transport.get_bytes(filename)), transport
60
56
def redirected_transport(transport, exception, redirection_notice):
61
57
note(redirection_notice)
62
58
url, filename = urlutils.split(exception.target,
63
59
exclude_trailing_slash=False)
65
raise errors.NotABundle('A directory cannot be a bundle')
66
return get_transport(url)
61
raise errors.NotABundle(gettext('A directory cannot be a bundle'))
62
return _mod_transport.get_transport_from_url(url)
69
bytef, transport = do_catching_redirections(get_bundle, transport,
65
bytef, transport = _mod_transport.do_catching_redirections(
66
get_bundle, transport, redirected_transport)
71
67
except errors.TooManyRedirections:
72
68
raise errors.NotABundle(transport.clone(filename).base)
73
except (errors.ConnectionReset, errors.ConnectionError), e:
69
except (errors.ConnectionReset, errors.ConnectionError) as e:
75
except (errors.TransportError, errors.PathError), e:
71
except (errors.TransportError, errors.PathError) as e:
76
72
raise errors.NotABundle(str(e))
73
except (IOError,) as e:
79
75
# Abstraction leakage, SFTPTransport.get('directory')
80
76
# doesn't always fail at get() time. Sometimes it fails