~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ssh.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-21 09:32:44 UTC
  • mfrom: (5430.6.1 ssh-connect-socket-error)
  • Revision ID: pqm@pqm.ubuntu.com-20100921093244-q0290ai8j4s3lo1v
(spiv) Simplify connect_ssh/sftp error handling (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
336
336
            self._raise_connection_error(host, port=port, orig_error=e,
337
337
                                         msg='Unable to invoke remote bzr')
338
338
 
 
339
_ssh_connection_errors = (EOFError, OSError, IOError, socket.error)
339
340
if paramiko is not None:
340
341
    vendor = ParamikoVendor()
341
342
    register_ssh_vendor('paramiko', vendor)
342
343
    register_ssh_vendor('none', vendor)
343
344
    register_default_ssh_vendor(vendor)
344
 
    _sftp_connection_errors = (EOFError, paramiko.SSHException)
 
345
    _ssh_connection_errors += (paramiko.SSHException,)
345
346
    del vendor
346
 
else:
347
 
    _sftp_connection_errors = (EOFError,)
348
347
 
349
348
 
350
349
class SubprocessVendor(SSHVendor):
375
374
                                                  subsystem='sftp')
376
375
            sock = self._connect(argv)
377
376
            return SFTPClient(SocketAsChannelAdapter(sock))
378
 
        except _sftp_connection_errors, e:
379
 
            self._raise_connection_error(host, port=port, orig_error=e)
380
 
        except (OSError, IOError, socket.error), e:
381
 
            # If the machine is fast enough, ssh can actually exit
382
 
            # before we try and send it the sftp request, which
383
 
            # raises a Broken Pipe
384
 
            if e.errno not in (errno.EPIPE,):
385
 
                raise
 
377
        except _ssh_connection_errors, e:
386
378
            self._raise_connection_error(host, port=port, orig_error=e)
387
379
 
388
380
    def connect_ssh(self, username, password, host, port, command):
390
382
            argv = self._get_vendor_specific_argv(username, host, port,
391
383
                                                  command=command)
392
384
            return self._connect(argv)
393
 
        except (EOFError), e:
394
 
            self._raise_connection_error(host, port=port, orig_error=e)
395
 
        except (OSError, IOError, socket.error), e:
396
 
            # If the machine is fast enough, ssh can actually exit
397
 
            # before we try and send it the sftp request, which
398
 
            # raises a Broken Pipe
399
 
            if e.errno not in (errno.EPIPE,):
400
 
                raise
 
385
        except _ssh_connection_errors, e:
401
386
            self._raise_connection_error(host, port=port, orig_error=e)
402
387
 
403
388
    def _get_vendor_specific_argv(self, username, host, port, subsystem=None,