~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-05 16:03:11 UTC
  • mfrom: (6432 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6433.
  • Revision ID: jelmer@samba.org-20120105160311-12o5p67kin1v3zps
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
it.
27
27
"""
28
28
 
 
29
from __future__ import absolute_import
 
30
 
29
31
from cStringIO import StringIO
30
32
import sys
31
33
 
33
35
lazy_import(globals(), """
34
36
import errno
35
37
from stat import S_ISDIR
36
 
import urllib
37
38
import urlparse
38
39
 
39
40
from bzrlib import (
51
52
from bzrlib.trace import (
52
53
    mutter,
53
54
    )
54
 
from bzrlib import registry
 
55
from bzrlib import (
 
56
    hooks,
 
57
    registry,
 
58
    )
55
59
 
56
60
 
57
61
# a dictionary of open file streams. Keys are absolute paths, values are
282
286
        self.transport.append_bytes(self.relpath, bytes)
283
287
 
284
288
 
 
289
class TransportHooks(hooks.Hooks):
 
290
    """Mapping of hook names to registered callbacks for transport hooks"""
 
291
    def __init__(self):
 
292
        super(TransportHooks, self).__init__()
 
293
        self.add_hook("post_connect",
 
294
            "Called after a new connection is established or a reconnect "
 
295
            "occurs. The sole argument passed is either the connected "
 
296
            "transport or smart medium instance.", (2, 5))
 
297
 
 
298
 
285
299
class Transport(object):
286
300
    """This class encapsulates methods for retrieving or putting a file
287
301
    from/to a storage location.
306
320
    #       where the biggest benefit between combining reads and
307
321
    #       and seeking is. Consider a runtime auto-tune.
308
322
    _bytes_to_read_before_seek = 0
 
323
    
 
324
    hooks = TransportHooks()
309
325
 
310
326
    def __init__(self, base):
311
327
        super(Transport, self).__init__()
1415
1431
 
1416
1432
        :return: The corresponding URL.
1417
1433
        """
1418
 
        netloc = urllib.quote(host)
 
1434
        netloc = urlutils.quote(host)
1419
1435
        if user is not None:
1420
1436
            # Note that we don't put the password back even if we
1421
1437
            # have one so that it doesn't get accidentally
1422
1438
            # exposed.
1423
 
            netloc = '%s@%s' % (urllib.quote(user), netloc)
 
1439
            netloc = '%s@%s' % (urlutils.quote(user), netloc)
1424
1440
        if port is not None:
1425
1441
            netloc = '%s:%d' % (netloc, port)
1426
1442
        path = urlutils.escape(path)
1495
1511
        """
1496
1512
        self._shared_connection.connection = connection
1497
1513
        self._shared_connection.credentials = credentials
 
1514
        for hook in self.hooks["post_connect"]:
 
1515
            hook(self)
1498
1516
 
1499
1517
    def _get_connection(self):
1500
1518
        """Returns the transport specific connection object."""