Made relevant Python3 changes.
authorFredrik Tolf <fredrik@dolda2000.com>
Sun, 15 Jan 2012 07:14:53 +0000 (08:14 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Sun, 15 Jan 2012 07:14:53 +0000 (08:14 +0100)
pdm/cli.py
pdm/sshsock.py

index 272be86..667e2ed 100644 (file)
@@ -23,7 +23,7 @@ def resolve(spec):
             p = spec.rindex(":")
             first, second = spec[:p], spec[p + 1:]
             if "/" in second:
-                import sshsock
+                from . import sshsock
                 sk = sshsock.sshsocket(first, second)
             else:
                 sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
index feb2f9f..3a64122 100644 (file)
@@ -9,7 +9,7 @@ class sshsocket(object):
         if port is not None:
             args += ["-p", str(int(port))]
         args += [host]
-        args += ["python", "-m", "pdm.sshsock", path]
+        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)
 
@@ -36,36 +36,36 @@ class sshsocket(object):
         self.close()
 
 def cli():
-    fcntl.fcntl(sys.stdin, fcntl.F_SETFL, fcntl.fcntl(sys.stdin, fcntl.F_GETFL) | os.O_NONBLOCK)
+    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])
-        buf1 = ""
-        buf2 = ""
+        buf1 = b""
+        buf2 = b""
         while True:
             wfd = []
             if buf1: wfd.append(sk)
-            if buf2: wfd.append(sys.stdout)
-            rfd, wfd, efd = select.select([sk, sys.stdin], wfd, [])
+            if buf2: wfd.append(sys.stdout.buffer)
+            rfd, wfd, efd = select.select([sk, sys.stdin.buffer], wfd, [])
             if sk in rfd:
                 ret = sk.recv(65536)
-                if ret == "":
+                if ret == b"":
                     break
                 else:
                     buf2 += ret
-            if sys.stdin in rfd:
-                ret = sys.stdin.read()
-                if ret == "":
+            if sys.stdin.buffer in rfd:
+                ret = sys.stdin.buffer.read()
+                if ret == b"":
                     break
                 else:
                     buf1 = ret
             if sk in wfd:
                 ret = sk.send(buf1)
                 buf1 = buf1[ret:]
-            if sys.stdout in wfd:
-                sys.stdout.write(buf2)
-                sys.stdout.flush()
-                buf2 = ""
+            if sys.stdout.buffer in wfd:
+                sys.stdout.buffer.write(buf2)
+                sys.stdout.buffer.flush()
+                buf2 = b""
     finally:
         sk.close()