~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ssh.py

Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
172
172
    signal.signal(signal.SIGINT, signal.SIG_IGN)
173
173
 
174
174
 
175
 
class SocketAsChannelAdapter(object):
 
175
class LoopbackSFTP(object):
176
176
    """Simple wrapper for a socket that pretends to be a paramiko Channel."""
177
177
 
178
178
    def __init__(self, sock):
179
179
        self.__socket = sock
180
180
 
181
 
    def get_name(self):
182
 
        return "bzr SocketAsChannelAdapter"
183
 
    
184
181
    def send(self, data):
185
182
        return self.__socket.send(data)
186
183
 
187
184
    def recv(self, n):
188
 
        try:
189
 
            return self.__socket.recv(n)
190
 
        except socket.error, e:
191
 
            if e.args[0] in (errno.EPIPE, errno.ECONNRESET, errno.ECONNABORTED,
192
 
                             errno.EBADF):
193
 
                # Connection has closed.  Paramiko expects an empty string in
194
 
                # this case, not an exception.
195
 
                return ''
196
 
            raise
 
185
        return self.__socket.recv(n)
197
186
 
198
187
    def recv_ready(self):
199
 
        # TODO: jam 20051215 this function is necessary to support the
200
 
        # pipelined() function. In reality, it probably should use
201
 
        # poll() or select() to actually return if there is data
202
 
        # available, otherwise we probably don't get any benefit
203
188
        return True
204
189
 
205
190
    def close(self):
252
237
            sock.connect((host, port))
253
238
        except socket.error, e:
254
239
            self._raise_connection_error(host, port=port, orig_error=e)
255
 
        return SFTPClient(SocketAsChannelAdapter(sock))
 
240
        return SFTPClient(LoopbackSFTP(sock))
256
241
 
257
242
register_ssh_vendor('loopback', LoopbackVendor())
258
243
 
362
347
            argv = self._get_vendor_specific_argv(username, host, port,
363
348
                                                  subsystem='sftp')
364
349
            sock = self._connect(argv)
365
 
            return SFTPClient(SocketAsChannelAdapter(sock))
 
350
            return SFTPClient(sock)
366
351
        except _sftp_connection_errors, e:
367
352
            self._raise_connection_error(host, port=port, orig_error=e)
368
353
        except (OSError, IOError), e:
616
601
    def send(self, data):
617
602
        return os.write(self.proc.stdin.fileno(), data)
618
603
 
 
604
    def recv_ready(self):
 
605
        # TODO: jam 20051215 this function is necessary to support the
 
606
        # pipelined() function. In reality, it probably should use
 
607
        # poll() or select() to actually return if there is data
 
608
        # available, otherwise we probably don't get any benefit
 
609
        return True
 
610
 
619
611
    def recv(self, count):
620
612
        return os.read(self.proc.stdout.fileno(), count)
621
613