~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

Create new post_connect hook for transports

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
from bzrlib.symbol_versioning import (
50
50
        DEPRECATED_PARAMETER,
51
51
        )
52
 
from bzrlib.trace import (
53
 
    mutter,
 
52
from bzrlib import (
 
53
    hooks,
 
54
    registry,
 
55
    trace,
54
56
    )
55
 
from bzrlib import registry
56
57
 
57
58
 
58
59
# a dictionary of open file streams. Keys are absolute paths, values are
267
268
        self.transport.append_bytes(self.relpath, bytes)
268
269
 
269
270
 
 
271
class TransportHooks(hooks.Hooks):
 
272
    """Mapping of hook names to registered callbacks for transport hooks"""
 
273
    def __init__(self):
 
274
        super(TransportHooks, self).__init__()
 
275
        self.create_hook(hooks.HookPoint("post_connect",
 
276
            "Called after a new connection is established or a reconnect "
 
277
            "occurs. The connected transport instance is the sole argument "
 
278
            "passed", (2, 3), None))
 
279
 
 
280
 
270
281
class Transport(object):
271
282
    """This class encapsulates methods for retrieving or putting a file
272
283
    from/to a storage location.
291
302
    #       where the biggest benefit between combining reads and
292
303
    #       and seeking is. Consider a runtime auto-tune.
293
304
    _bytes_to_read_before_seek = 0
 
305
    
 
306
    hooks = TransportHooks()
294
307
 
295
308
    def __init__(self, base):
296
309
        super(Transport, self).__init__()
1492
1505
        """
1493
1506
        self._shared_connection.connection = connection
1494
1507
        self._shared_connection.credentials = credentials
 
1508
        for hook in self.hooks["post_connect"]:
 
1509
            # GZ 2010-10-14: Should the hook be passed the new connection and
 
1510
            #                credentials too or does opaque really mean that?
 
1511
            hook(self)
1495
1512
 
1496
1513
    def _get_connection(self):
1497
1514
        """Returns the transport specific connection object."""
1589
1606
            raise errors.UnsupportedProtocol(base, last_err)
1590
1607
        # This doesn't look like a protocol, consider it a local path
1591
1608
        new_base = urlutils.local_path_to_url(base)
1592
 
        # mutter('converting os path %r => url %s', base, new_base)
1593
1609
        return new_base
1594
1610
 
1595
1611
    # Catch any URLs which are passing Unicode rather than ASCII
1637
1653
        try:
1638
1654
            return factory.get_obj()(base), None
1639
1655
        except errors.DependencyNotPresent, e:
1640
 
            mutter("failed to instantiate transport %r for %r: %r" %
1641
 
                    (factory, base, e))
 
1656
            trace.mutter("failed to instantiate transport %r for %r: %r" %
 
1657
                         (factory, base, e))
1642
1658
            last_err = e
1643
1659
            continue
1644
1660
    return None, last_err