/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Robert Collins
  • Date: 2009-05-23 20:57:12 UTC
  • mfrom: (4371 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4441.
  • Revision ID: robertc@robertcollins.net-20090523205712-lcwbfqk6vwavinuv
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
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
12
12
#
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
16
16
 
17
17
"""Transport is an abstraction layer to handle file access.
18
18
 
50
50
        deprecated_method,
51
51
        deprecated_function,
52
52
        DEPRECATED_PARAMETER,
53
 
        one_four,
54
53
        )
55
54
from bzrlib.trace import (
56
55
    mutter,
329
328
        """
330
329
        raise NotImplementedError(self.clone)
331
330
 
 
331
    def create_prefix(self):
 
332
        """Create all the directories leading down to self.base."""
 
333
        cur_transport = self
 
334
        needed = [cur_transport]
 
335
        # Recurse upwards until we can create a directory successfully
 
336
        while True:
 
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)
 
342
            try:
 
343
                new_transport.mkdir('.')
 
344
            except errors.NoSuchFile:
 
345
                needed.append(new_transport)
 
346
                cur_transport = new_transport
 
347
            except errors.FileExists:
 
348
                break
 
349
            else:
 
350
                break
 
351
        # Now we only need to create child directories
 
352
        while needed:
 
353
            cur_transport = needed.pop()
 
354
            cur_transport.ensure_base()
 
355
 
332
356
    def ensure_base(self):
333
357
        """Ensure that the directory this transport references exists.
334
358
 
516
540
        """
517
541
        raise errors.NotLocalUrl(self.abspath(relpath))
518
542
 
519
 
 
520
543
    def has(self, relpath):
521
544
        """Does the file relpath exist?
522
545
 
587
610
        finally:
588
611
            f.close()
589
612
 
590
 
    @deprecated_method(one_four)
591
 
    def get_smart_client(self):
592
 
        """Return a smart client for this transport if possible.
593
 
 
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.
596
 
 
597
 
        :raises NoSmartServer: if no smart server client is available.
598
 
        """
599
 
        raise errors.NoSmartServer(self.base)
600
 
 
601
613
    def get_smart_medium(self):
602
614
        """Return a smart client medium for this transport if possible.
603
615
 
608
620
        """
609
621
        raise errors.NoSmartMedium(self)
610
622
 
611
 
    @deprecated_method(one_four)
612
 
    def get_shared_medium(self):
613
 
        """Return a smart client shared medium for this transport if possible.
614
 
 
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.
617
 
 
618
 
        :raises NoSmartMedium: if no smart server medium is available.
619
 
        """
620
 
        raise errors.NoSmartMedium(self)
621
 
 
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.
1357
1358
 
1358
1359
    @staticmethod
1359
1360
    def _split_url(url):
1360
 
        """
1361
 
        Extract the server address, the credentials and the path from the url.
1362
 
 
1363
 
        user, password, host and path should be quoted if they contain reserved
1364
 
        chars.
1365
 
 
1366
 
        :param url: an quoted url
1367
 
 
1368
 
        :return: (scheme, user, password, host, port, path) tuple, all fields
1369
 
            are unquoted.
1370
 
        """
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
1377
 
        if '@' in netloc:
1378
 
            user, host = netloc.rsplit('@', 1)
1379
 
            if ':' in user:
1380
 
                user, password = user.split(':', 1)
1381
 
                password = urllib.unquote(password)
1382
 
            user = urllib.unquote(user)
1383
 
        else:
1384
 
            host = netloc
1385
 
 
1386
 
        if ':' in host:
1387
 
            host, port = host.rsplit(':', 1)
1388
 
            try:
1389
 
                port = int(port)
1390
 
            except ValueError:
1391
 
                raise errors.InvalidURL('invalid port number %s in url:\n%s' %
1392
 
                                        (port, url))
1393
 
        if host == '':
1394
 
            raise errors.InvalidURL('Host empty in: %s' % url)
1395
 
 
1396
 
        host = urllib.unquote(host)
1397
 
        path = urllib.unquote(path)
1398
 
 
1399
 
        return (scheme, user, password, host, port, path)
 
1361
        return urlutils.parse_url(url)
1400
1362
 
1401
1363
    @staticmethod
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')
1789
1751
 
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)
1799
 
 
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',
1805
 
                        'FtpTransport')
1806
 
register_lazy_transport('aftp+nogssapi://', 'bzrlib.transport.ftp',
1807
 
                        'FtpTransport')
 
1752
try:
 
1753
    import kerberos
 
1754
    kerberos_available = True
 
1755
except ImportError:
 
1756
    kerberos_available = False
 
1757
 
 
1758
if kerberos_available:
 
1759
    # Default to trying GSSAPI authentication (if the kerberos module is
 
1760
    # available)
 
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)
 
1769
 
 
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',
 
1775
                            'FtpTransport')
 
1776
    register_lazy_transport('aftp+nogssapi://', 'bzrlib.transport.ftp',
 
1777
                            'FtpTransport')
1808
1778
 
1809
1779
register_transport_proto('memory://')
1810
1780
register_lazy_transport('memory://', 'bzrlib.transport.memory',