parent
7b19c1b2f6
commit
c0a4901181
@ -4,7 +4,10 @@ import select
|
|||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
except ImportError:
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
def noop():
|
def noop():
|
||||||
pass
|
pass
|
||||||
@ -84,13 +87,16 @@ class Connection:
|
|||||||
return self.socket.close()
|
return self.socket.close()
|
||||||
|
|
||||||
def send(self, payload):
|
def send(self, payload):
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
self.socket.sendall(bytes(payload, 'UTF-8'))
|
||||||
|
else:
|
||||||
self.socket.sendall(payload)
|
self.socket.sendall(payload)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def receive(self, char=None):
|
def receive(self, char=None):
|
||||||
while len(select.select([self.socket], [], [], 0.1)[0]) == 0:
|
|
||||||
self.poll()
|
|
||||||
f = self.socket.makefile()
|
f = self.socket.makefile()
|
||||||
|
while len(select.select([f], [], [], 0.1)[0]) == 0:
|
||||||
|
self.poll()
|
||||||
try:
|
try:
|
||||||
return bdecode(f)
|
return bdecode(f)
|
||||||
finally:
|
finally:
|
||||||
@ -118,8 +124,8 @@ def dispatch(host, port, poll, keepalive, command, *args):
|
|||||||
def main(host, port, keepalive, command, *args):
|
def main(host, port, keepalive, command, *args):
|
||||||
try:
|
try:
|
||||||
sys.stdout.write(vim_encode(dispatch(host, port, noop, keepalive, command, *[bdecode(StringIO(arg)) for arg in args])))
|
sys.stdout.write(vim_encode(dispatch(host, port, noop, keepalive, command, *[bdecode(StringIO(arg)) for arg in args])))
|
||||||
except Exception, e:
|
except Exception:
|
||||||
print(e)
|
print((sys.exc_info()[1]))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user