~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

(jelmer) Add a post_connect hook for transports. (Bazaar Developers)

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
from bzrlib.trace import (
53
53
    mutter,
54
54
    )
55
 
from bzrlib import registry
 
55
from bzrlib import (
 
56
    hooks,
 
57
    registry,
 
58
    )
56
59
 
57
60
 
58
61
# a dictionary of open file streams. Keys are absolute paths, values are
283
286
        self.transport.append_bytes(self.relpath, bytes)
284
287
 
285
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
 
286
299
class Transport(object):
287
300
    """This class encapsulates methods for retrieving or putting a file
288
301
    from/to a storage location.
307
320
    #       where the biggest benefit between combining reads and
308
321
    #       and seeking is. Consider a runtime auto-tune.
309
322
    _bytes_to_read_before_seek = 0
 
323
    
 
324
    hooks = TransportHooks()
310
325
 
311
326
    def __init__(self, base):
312
327
        super(Transport, self).__init__()
1496
1511
        """
1497
1512
        self._shared_connection.connection = connection
1498
1513
        self._shared_connection.credentials = credentials
 
1514
        for hook in self.hooks["post_connect"]:
 
1515
            hook(self)
1499
1516
 
1500
1517
    def _get_connection(self):
1501
1518
        """Returns the transport specific connection object."""