Fix testproto.

This commit is contained in:
Abhilash Raj 2021-06-05 10:51:59 -07:00
parent 35136f99b0
commit 4de105682e
No known key found for this signature in database
GPG Key ID: 9D9B2BA061D0A67C

View File

@ -34,9 +34,9 @@ import sys
import time import time
import traceback import traceback
import protocol # WeeChat/relay protocol from qweechat.weechat import protocol
# from .. version import qweechat_version
qweechat_version = '1.1' qweechat_version = '0.1'
NAME = 'qweechat-testproto' NAME = 'qweechat-testproto'
@ -60,12 +60,13 @@ class TestProto(object):
try: try:
self.sock = socket.socket(inet, socket.SOCK_STREAM) self.sock = socket.socket(inet, socket.SOCK_STREAM)
self.sock.connect((self.args.hostname, self.args.port)) self.sock.connect((self.args.hostname, self.args.port))
except: # noqa: E722 except Exception:
if self.sock: if self.sock:
self.sock.close() self.sock.close()
print('Failed to connect to', self.address) print('Failed to connect to', self.address)
return False return False
print('Connected to', self.address)
print(f'Connected to {self.address} socket {self.sock}')
return True return True
def send(self, messages): def send(self, messages):
@ -122,7 +123,7 @@ class TestProto(object):
data = os.read(sys.stdin.fileno(), 4096) data = os.read(sys.stdin.fileno(), 4096)
if data: if data:
if not self.send(data.strip()): if not self.send(data.strip()):
# self.sock.close() self.sock.close()
return False return False
# open stdin to read user commands # open stdin to read user commands
sys.stdin = open('/dev/tty') sys.stdin = open('/dev/tty')