1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Transport is an abstraction layer to handle file access.
330
329
raise NotImplementedError(self.clone)
331
def create_prefix(self):
332
"""Create all the directories leading down to self.base."""
334
needed = [cur_transport]
335
# Recurse upwards until we can create a directory successfully
337
new_transport = cur_transport.clone('..')
338
if new_transport.base == cur_transport.base:
339
raise errors.BzrCommandError(
340
"Failed to create path prefix for %s."
341
% cur_transport.base)
343
new_transport.mkdir('.')
344
except errors.NoSuchFile:
345
needed.append(new_transport)
346
cur_transport = new_transport
347
except errors.FileExists:
351
# Now we only need to create child directories
353
cur_transport = needed.pop()
354
cur_transport.ensure_base()
332
356
def ensure_base(self):
333
357
"""Ensure that the directory this transport references exists.
590
@deprecated_method(one_four)
591
def get_smart_client(self):
592
"""Return a smart client for this transport if possible.
594
A smart client doesn't imply the presence of a smart server: it implies
595
that the smart protocol can be tunnelled via this transport.
597
:raises NoSmartServer: if no smart server client is available.
599
raise errors.NoSmartServer(self.base)
601
613
def get_smart_medium(self):
602
614
"""Return a smart client medium for this transport if possible.
609
621
raise errors.NoSmartMedium(self)
611
@deprecated_method(one_four)
612
def get_shared_medium(self):
613
"""Return a smart client shared medium for this transport if possible.
615
A smart medium doesn't imply the presence of a smart server: it implies
616
that the smart protocol can be tunnelled via this transport.
618
:raises NoSmartMedium: if no smart server medium is available.
620
raise errors.NoSmartMedium(self)
622
623
def readv(self, relpath, offsets, adjust_for_latency=False,
623
624
upper_limit=None):
624
625
"""Get parts of the file at the given relative path.
1359
1360
def _split_url(url):
1361
Extract the server address, the credentials and the path from the url.
1363
user, password, host and path should be quoted if they contain reserved
1366
:param url: an quoted url
1368
:return: (scheme, user, password, host, port, path) tuple, all fields
1371
if isinstance(url, unicode):
1372
raise errors.InvalidURL('should be ascii:\n%r' % url)
1373
url = url.encode('utf-8')
1374
(scheme, netloc, path, params,
1375
query, fragment) = urlparse.urlparse(url, allow_fragments=False)
1376
user = password = host = port = None
1378
user, host = netloc.rsplit('@', 1)
1380
user, password = user.split(':', 1)
1381
password = urllib.unquote(password)
1382
user = urllib.unquote(user)
1387
host, port = host.rsplit(':', 1)
1391
raise errors.InvalidURL('invalid port number %s in url:\n%s' %
1394
raise errors.InvalidURL('Host empty in: %s' % url)
1396
host = urllib.unquote(host)
1397
path = urllib.unquote(path)
1399
return (scheme, user, password, host, port, path)
1361
return urlutils.parse_url(url)
1402
1364
def _unsplit_url(scheme, user, password, host, port, path):
1787
1749
register_transport_proto('aftp://', help="Access using active FTP.")
1788
1750
register_lazy_transport('aftp://', 'bzrlib.transport.ftp', 'FtpTransport')
1790
# Default to trying GSSAPI authentication (if the kerberos module is available)
1791
register_transport_proto('ftp+gssapi://', register_netloc=True)
1792
register_lazy_transport('ftp+gssapi://', 'bzrlib.transport.ftp._gssapi',
1793
'GSSAPIFtpTransport')
1794
register_transport_proto('aftp+gssapi://', register_netloc=True)
1795
register_lazy_transport('aftp+gssapi://', 'bzrlib.transport.ftp._gssapi',
1796
'GSSAPIFtpTransport')
1797
register_transport_proto('ftp+nogssapi://', register_netloc=True)
1798
register_transport_proto('aftp+nogssapi://', register_netloc=True)
1800
register_lazy_transport('ftp://', 'bzrlib.transport.ftp._gssapi',
1801
'GSSAPIFtpTransport')
1802
register_lazy_transport('aftp://', 'bzrlib.transport.ftp._gssapi',
1803
'GSSAPIFtpTransport')
1804
register_lazy_transport('ftp+nogssapi://', 'bzrlib.transport.ftp',
1806
register_lazy_transport('aftp+nogssapi://', 'bzrlib.transport.ftp',
1754
kerberos_available = True
1756
kerberos_available = False
1758
if kerberos_available:
1759
# Default to trying GSSAPI authentication (if the kerberos module is
1761
register_transport_proto('ftp+gssapi://', register_netloc=True)
1762
register_lazy_transport('ftp+gssapi://', 'bzrlib.transport.ftp._gssapi',
1763
'GSSAPIFtpTransport')
1764
register_transport_proto('aftp+gssapi://', register_netloc=True)
1765
register_lazy_transport('aftp+gssapi://', 'bzrlib.transport.ftp._gssapi',
1766
'GSSAPIFtpTransport')
1767
register_transport_proto('ftp+nogssapi://', register_netloc=True)
1768
register_transport_proto('aftp+nogssapi://', register_netloc=True)
1770
register_lazy_transport('ftp://', 'bzrlib.transport.ftp._gssapi',
1771
'GSSAPIFtpTransport')
1772
register_lazy_transport('aftp://', 'bzrlib.transport.ftp._gssapi',
1773
'GSSAPIFtpTransport')
1774
register_lazy_transport('ftp+nogssapi://', 'bzrlib.transport.ftp',
1776
register_lazy_transport('aftp+nogssapi://', 'bzrlib.transport.ftp',
1809
1779
register_transport_proto('memory://')
1810
1780
register_lazy_transport('memory://', 'bzrlib.transport.memory',