X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=pdm%2Fcli.py;h=1d83920f237286714d86848cde6db0b9791bac2b;hb=refs%2Fheads%2Fpython2;hp=0b316823ef8cddc23728b85b1f2bb4c434d5e21e;hpb=d7ad337ed6a9350932b83ed320c4ebd39621e355;p=pdm.git diff --git a/pdm/cli.py b/pdm/cli.py index 0b31682..1d83920 100644 --- a/pdm/cli.py +++ b/pdm/cli.py @@ -19,16 +19,21 @@ def resolve(spec): return spec sk = None try: - if "/" in spec: + if ":" in spec: + p = spec.rindex(":") + first, second = spec[:p], spec[p + 1:] + if "/" in second: + import sshsock + sk = sshsock.sshsocket(first, second) + else: + sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sk.connect((first, second)) + elif "/" in spec: sk = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sk.connect(spec) elif spec.isdigit(): sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.connect(("localhost", int(spec))) - elif ":" in spec: - sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - p = spec.rindex(":") - sk.connect((spec[:p], int(spec[p + 1:]))) else: raise Exception("Unknown target specification %r" % spec) rv = sk @@ -59,9 +64,9 @@ class client(object): the select() method). """ self.sk = resolve(sk) - self.buf = b"" + self.buf = "" line = self.readline() - if line != b"+PDM1": + if line != "+PDM1": raise protoerr("Illegal protocol signature") if proto is not None: self.select(proto) @@ -77,25 +82,23 @@ class client(object): def readline(self): """Read a single NL-terminated line and return it.""" while True: - p = self.buf.find(b"\n") + p = self.buf.find("\n") if p >= 0: ret = self.buf[:p] self.buf = self.buf[p + 1:] return ret ret = self.sk.recv(1024) - if ret == b"": + if ret == "": return None self.buf += ret def select(self, proto): """Negotiate the given subprotocol with the server""" - if isinstance(proto, str): - proto = proto.encode("ascii") - if b"\n" in proto: + if "\n" in proto: raise Exception("Illegal protocol specified: %r" % proto) - self.sk.send(proto + b"\n") + self.sk.send(proto + "\n") rep = self.readline() - if len(rep) < 1 or rep[0] != b"+"[0]: + if len(rep) < 1 or rep[0] != "+": raise protoerr("Error reply when selecting protocol %s: %s" % (proto, rep[1:])) def __enter__(self): @@ -113,7 +116,7 @@ class replclient(client): """ def __init__(self, sk): """Create a connected client as documented in the `client' class.""" - super().__init__(sk, "repl") + super(replclient, self).__init__(sk, "repl") def run(self, code): """Run a single block of Python code on the server. Returns @@ -126,16 +129,16 @@ class replclient(client): code = ncode while len(code) > 0 and code[-1] == "\n": code = code[:-1] - self.sk.send((code + "\n\n").encode("utf-8")) - buf = b"" + self.sk.send(code + "\n\n") + buf = "" while True: ln = self.readline() - if ln[0] == b" "[0]: - buf += ln[1:] + b"\n" - elif ln[0] == b"+"[0]: - return buf.decode("utf-8") - elif ln[0] == b"-"[0]: - raise protoerr("Error reply: %s" % ln[1:].decode("utf-8")) + if ln[0] == " ": + buf += ln[1:] + "\n" + elif ln[0] == "+": + return buf + elif ln[0] == "-": + raise protoerr("Error reply: %s" % ln[1:]) else: raise protoerr("Illegal reply: %s" % ln) @@ -225,7 +228,7 @@ class perfclient(client): """ def __init__(self, sk): """Create a connected client as documented in the `client' class.""" - super().__init__(sk, "perf") + super(perfclient, self).__init__(sk, "perf") self.nextid = 0 self.lock = threading.Lock() self.proxies = {} @@ -237,10 +240,10 @@ class perfclient(client): self.sk.send(buf) def recvb(self, num): - buf = b"" + buf = "" while len(buf) < num: data = self.sk.recv(num - len(buf)) - if data == b"": + if data == "": raise EOFError() buf += data return buf