/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: John Arbash Meinel
  • Date: 2008-05-29 19:46:01 UTC
  • mfrom: (3456 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3459.
  • Revision ID: john@arbash-meinel.com-20080529194601-r2gpmk536xin9c4a
merge bzr.dev, put the NEWS entry in the right place

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
from bzrlib.lazy_import import lazy_import
34
34
lazy_import(globals(), """
35
35
import errno
36
 
from collections import deque
37
36
from stat import S_ISDIR
38
 
import unittest
39
37
import urllib
40
38
import urlparse
41
 
import warnings
42
39
 
43
 
import bzrlib
44
40
from bzrlib import (
45
41
    errors,
46
42
    osutils,
50
46
""")
51
47
 
52
48
from bzrlib.symbol_versioning import (
53
 
        deprecated_passed,
54
49
        deprecated_method,
55
50
        deprecated_function,
56
51
        DEPRECATED_PARAMETER,
57
 
        zero_eight,
58
 
        zero_eleven,
59
 
        zero_ninety,
 
52
        one_four,
60
53
        )
61
54
from bzrlib.trace import (
62
 
    note,
63
55
    mutter,
64
 
    warning,
65
56
    )
66
57
from bzrlib import registry
67
58
 
143
134
                             register_netloc=False):
144
135
    transport_list_registry.register_transport(prefix, help)
145
136
    if register_netloc:
146
 
        assert prefix.endswith('://')
 
137
        if not prefix.endswith('://'):
 
138
            raise ValueError(prefix)
147
139
        register_urlparse_netloc_protocol(prefix[:-3])
148
140
 
149
141
 
187
179
        transport_list_registry.remove(scheme)
188
180
 
189
181
 
190
 
 
191
 
@deprecated_function(zero_ninety)
192
 
def split_url(url):
193
 
    # TODO: jam 20060606 urls should only be ascii, or they should raise InvalidURL
194
 
    if isinstance(url, unicode):
195
 
        url = url.encode('utf-8')
196
 
    (scheme, netloc, path, params,
197
 
     query, fragment) = urlparse.urlparse(url, allow_fragments=False)
198
 
    username = password = host = port = None
199
 
    if '@' in netloc:
200
 
        username, host = netloc.split('@', 1)
201
 
        if ':' in username:
202
 
            username, password = username.split(':', 1)
203
 
            password = urllib.unquote(password)
204
 
        username = urllib.unquote(username)
205
 
    else:
206
 
        host = netloc
207
 
 
208
 
    if ':' in host:
209
 
        host, port = host.rsplit(':', 1)
210
 
        try:
211
 
            port = int(port)
212
 
        except ValueError:
213
 
            # TODO: Should this be ConnectionError?
214
 
            raise errors.TransportError(
215
 
                'invalid port number %s in url:\n%s' % (port, url))
216
 
    host = urllib.unquote(host)
217
 
 
218
 
    path = urllib.unquote(path)
219
 
 
220
 
    return (scheme, username, password, host, port, path)
221
 
 
222
 
 
223
182
class _CoalescedOffset(object):
224
183
    """A data container for keeping track of coalesced offsets."""
225
184
 
334
293
    _bytes_to_read_before_seek = 0
335
294
 
336
295
    def __init__(self, base):
337
 
        super(Transport, self).__init__()
 
296
        super(Transport, self).__init__(base=base)
338
297
        self.base = base
339
298
 
340
299
    def _translate_error(self, e, path, raise_generic=True):
412
371
        object or string to another one.
413
372
        This just gives them something easy to call.
414
373
        """
415
 
        assert not isinstance(from_file, basestring), \
416
 
            '_pump should only be called on files not %s' % (type(from_file,))
417
374
        return osutils.pumpfile(from_file, to_file)
418
375
 
419
376
    def _get_total(self, multi):
613
570
        """
614
571
        return self.get(relpath).read()
615
572
 
 
573
    @deprecated_method(one_four)
616
574
    def get_smart_client(self):
617
575
        """Return a smart client for this transport if possible.
618
576
 
633
591
        """
634
592
        raise errors.NoSmartMedium(self)
635
593
 
 
594
    @deprecated_method(one_four)
636
595
    def get_shared_medium(self):
637
596
        """Return a smart client shared medium for this transport if possible.
638
597
 
1006
965
 
1007
966
        :returns: the length of relpath before the content was written to it.
1008
967
        """
1009
 
        assert isinstance(bytes, str), \
1010
 
            'bytes must be a plain string, not %s' % type(bytes)
 
968
        if not isinstance(bytes, str):
 
969
            raise TypeError(
 
970
                'bytes must be a plain string, not %s' % type(bytes))
1011
971
        return self.append_file(relpath, StringIO(bytes), mode=mode)
1012
972
 
1013
973
    def append_multi(self, files, pb=None):
1546
1506
        return transport
1547
1507
 
1548
1508
 
1549
 
@deprecated_function(zero_ninety)
1550
 
def urlescape(relpath):
1551
 
    urlutils.escape(relpath)
1552
 
 
1553
 
 
1554
 
@deprecated_function(zero_ninety)
1555
 
def urlunescape(url):
1556
 
    urlutils.unescape(url)
1557
 
 
1558
1509
# We try to recognize an url lazily (ignoring user, password, etc)
1559
1510
_urlRE = re.compile(r'^(?P<proto>[^:/\\]+)://(?P<rest>.*)$')
1560
1511
 
1610
1561
            transport, last_err = _try_transport_factories(base, factory_list)
1611
1562
            if transport:
1612
1563
                if possible_transports is not None:
1613
 
                    assert transport not in possible_transports
 
1564
                    if transport in possible_transports:
 
1565
                        raise AssertionError()
1614
1566
                    possible_transports.append(transport)
1615
1567
                return transport
1616
1568
 
1804
1756
                        'bzrlib.transport.fakevfat',
1805
1757
                        'FakeVFATTransportDecorator')
1806
1758
 
 
1759
register_transport_proto('nosmart+')
 
1760
register_lazy_transport('nosmart+', 'bzrlib.transport.nosmart',
 
1761
                        'NoSmartTransportDecorator')
 
1762
 
1807
1763
# These two schemes were registered, but don't seem to have an actual transport
1808
1764
# protocol registered
1809
1765
for scheme in ['ssh', 'bzr+loopback']: