From: Fredrik Tolf Date: Mon, 7 Jan 2013 06:28:45 +0000 (+0100) Subject: Merge branch 'master' into python3 X-Git-Url: http://dolda2000.com/gitweb/?p=pdm.git;a=commitdiff_plain;h=98ecc02e068d7108325210c9fd9f510ec7bae66c;hp=16e7fd3d4abbec9f5e6d976a2feca87176e79e29 Merge branch 'master' into python3 Conflicts: pdm/sshsock.py --- diff --git a/pdm-repl b/pdm-repl index c8fe277..cc5c289 100755 --- a/pdm-repl +++ b/pdm-repl @@ -14,7 +14,11 @@ for o, a in opts: if len(args) < 1: usage(sys.stderr) sys.exit(1) -cl = pdm.cli.replclient(args[0]) +try: + cl = pdm.cli.replclient(args[0]) +except Exception as e: + sys.stderr.write("%s: %s\n" % (args[0], e)) + sys.exit(1) buf = "" while True: diff --git a/pdm/sshsock.py b/pdm/sshsock.py index 3a64122..6efaba9 100644 --- a/pdm/sshsock.py +++ b/pdm/sshsock.py @@ -12,6 +12,30 @@ class sshsocket(object): args += ["python3", "-m", "pdm.sshsock", path] self.proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) fcntl.fcntl(self.proc.stdout, fcntl.F_SETFL, fcntl.fcntl(self.proc.stdout, fcntl.F_GETFL) | os.O_NONBLOCK) + head = self.recv(5) + if head != b"SSOCK": + raise socket.error("unexpected reply from %s: %r" % (host, head)) + head = self.recv(1) + if head == b"+": + buf = b"" + while True: + r = self.recv(1) + if r == b"": + raise socket.error("unexpected EOF in SSH socket stream") + elif r == b"\n": + break + buf += r + return + elif head == b"-": + buf = b"" + while True: + r = self.recv(1) + if r in {b"\n", b""}: + break + buf += r + raise socket.error(buf.decode("utf-8")) + else: + raise socket.error("unexpected reply from %s: %r" % (host, head)) def close(self): if self.proc is not None: @@ -39,7 +63,12 @@ def cli(): fcntl.fcntl(sys.stdin.buffer, fcntl.F_SETFL, fcntl.fcntl(sys.stdin.buffer, fcntl.F_GETFL) | os.O_NONBLOCK) sk = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: - sk.connect(sys.argv[1]) + try: + sk.connect(sys.argv[1]) + except socket.error as err: + sys.stdout.write("SSOCK-connect: %s\n" % err) + return + sys.stdout.write("SSOCK+\n") buf1 = b"" buf2 = b"" while True: