~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

(jelmer) Use the absolute_import feature everywhere in bzrlib,
 and add a source test to make sure it's used everywhere. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
bzrlib/transport/smart/__init__.py.
25
25
"""
26
26
 
 
27
from __future__ import absolute_import
 
28
 
27
29
import errno
28
30
import os
29
31
import sys
30
32
import time
31
 
import urllib
32
33
 
33
34
import bzrlib
34
35
from bzrlib.lazy_import import lazy_import
840
841
        """
841
842
        medium_base = urlutils.join(self.base, '/')
842
843
        rel_url = urlutils.relative_url(medium_base, transport.base)
843
 
        return urllib.unquote(rel_url)
 
844
        return urlutils.unquote(rel_url)
844
845
 
845
846
 
846
847
class SmartClientStreamMedium(SmartClientMedium):
881
882
        """
882
883
        return SmartClientStreamMediumRequest(self)
883
884
 
 
885
    def reset(self):
 
886
        """We have been disconnected, reset current state.
 
887
 
 
888
        This resets things like _current_request and connected state.
 
889
        """
 
890
        self.disconnect()
 
891
        self._current_request = None
 
892
 
884
893
 
885
894
class SmartSimplePipesClientMedium(SmartClientStreamMedium):
886
895
    """A client medium using simple pipes.
895
904
 
896
905
    def _accept_bytes(self, bytes):
897
906
        """See SmartClientStreamMedium.accept_bytes."""
898
 
        self._writeable_pipe.write(bytes)
 
907
        try:
 
908
            self._writeable_pipe.write(bytes)
 
909
        except IOError, e:
 
910
            if e.errno in (errno.EINVAL, errno.EPIPE):
 
911
                raise errors.ConnectionReset(
 
912
                    "Error trying to write to subprocess:\n%s" % (e,))
 
913
            raise
899
914
        self._report_activity(len(bytes), 'write')
900
915
 
901
916
    def _flush(self):
902
917
        """See SmartClientStreamMedium._flush()."""
 
918
        # Note: If flush were to fail, we'd like to raise ConnectionReset, etc.
 
919
        #       However, testing shows that even when the child process is
 
920
        #       gone, this doesn't error.
903
921
        self._writeable_pipe.flush()
904
922
 
905
923
    def _read_bytes(self, count):
924
942
 
925
943
class SmartSSHClientMedium(SmartClientStreamMedium):
926
944
    """A client medium using SSH.
927
 
    
928
 
    It delegates IO to a SmartClientSocketMedium or
 
945
 
 
946
    It delegates IO to a SmartSimplePipesClientMedium or
929
947
    SmartClientAlreadyConnectedSocketMedium (depending on platform).
930
948
    """
931
949
 
1168
1186
        This invokes self._medium._flush to ensure all bytes are transmitted.
1169
1187
        """
1170
1188
        self._medium._flush()
1171
 
 
1172