~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Martin Pool
  • Date: 2011-11-18 05:13:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6277.
  • Revision ID: mbp@canonical.com-20111118051319-9cj53bg5e06zl7rw
Remove more lzma related code

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
 
 
29
27
import errno
30
28
import os
31
29
import sys
32
30
import time
 
31
import urllib
33
32
 
34
33
import bzrlib
35
34
from bzrlib.lazy_import import lazy_import
43
42
    debug,
44
43
    errors,
45
44
    trace,
46
 
    transport,
47
45
    ui,
48
46
    urlutils,
49
47
    )
842
840
        """
843
841
        medium_base = urlutils.join(self.base, '/')
844
842
        rel_url = urlutils.relative_url(medium_base, transport.base)
845
 
        return urlutils.unquote(rel_url)
 
843
        return urllib.unquote(rel_url)
846
844
 
847
845
 
848
846
class SmartClientStreamMedium(SmartClientMedium):
883
881
        """
884
882
        return SmartClientStreamMediumRequest(self)
885
883
 
886
 
    def reset(self):
887
 
        """We have been disconnected, reset current state.
888
 
 
889
 
        This resets things like _current_request and connected state.
890
 
        """
891
 
        self.disconnect()
892
 
        self._current_request = None
893
 
 
894
884
 
895
885
class SmartSimplePipesClientMedium(SmartClientStreamMedium):
896
886
    """A client medium using simple pipes.
905
895
 
906
896
    def _accept_bytes(self, bytes):
907
897
        """See SmartClientStreamMedium.accept_bytes."""
908
 
        try:
909
 
            self._writeable_pipe.write(bytes)
910
 
        except IOError, e:
911
 
            if e.errno in (errno.EINVAL, errno.EPIPE):
912
 
                raise errors.ConnectionReset(
913
 
                    "Error trying to write to subprocess:\n%s" % (e,))
914
 
            raise
 
898
        self._writeable_pipe.write(bytes)
915
899
        self._report_activity(len(bytes), 'write')
916
900
 
917
901
    def _flush(self):
918
902
        """See SmartClientStreamMedium._flush()."""
919
 
        # Note: If flush were to fail, we'd like to raise ConnectionReset, etc.
920
 
        #       However, testing shows that even when the child process is
921
 
        #       gone, this doesn't error.
922
903
        self._writeable_pipe.flush()
923
904
 
924
905
    def _read_bytes(self, count):
943
924
 
944
925
class SmartSSHClientMedium(SmartClientStreamMedium):
945
926
    """A client medium using SSH.
946
 
 
947
 
    It delegates IO to a SmartSimplePipesClientMedium or
 
927
    
 
928
    It delegates IO to a SmartClientSocketMedium or
948
929
    SmartClientAlreadyConnectedSocketMedium (depending on platform).
949
930
    """
950
931
 
1022
1003
            raise AssertionError(
1023
1004
                "Unexpected io_kind %r from %r"
1024
1005
                % (io_kind, self._ssh_connection))
1025
 
        for hook in transport.Transport.hooks["post_connect"]:
1026
 
            hook(self)
1027
1006
 
1028
1007
    def _flush(self):
1029
1008
        """See SmartClientStreamMedium._flush()."""
1132
1111
            raise errors.ConnectionError("failed to connect to %s:%d: %s" %
1133
1112
                    (self._host, port, err_msg))
1134
1113
        self._connected = True
1135
 
        for hook in transport.Transport.hooks["post_connect"]:
1136
 
            hook(self)
1137
1114
 
1138
1115
 
1139
1116
class SmartClientAlreadyConnectedSocketMedium(SmartClientSocketMedium):
1191
1168
        This invokes self._medium._flush to ensure all bytes are transmitted.
1192
1169
        """
1193
1170
        self._medium._flush()
 
1171
 
 
1172