~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Martin Packman
  • Date: 2012-01-05 10:44:12 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6427.
  • Revision ID: martin.packman@canonical.com-20120105104412-z03fi9m43h946fvs
Merge bzr.dev to resolve conflicts

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