Avoid crashing in the repl

This commit is contained in:
Juhani Krekelä 2019-07-11 00:00:44 +03:00
parent 206440659f
commit ab454ca2ee
1 changed files with 22 additions and 17 deletions

View File

@ -30,27 +30,32 @@ writeall(proc.stdin, (bytes([0, len(nick)]) + nick))
print('s - request status, i - request msgid, m - send message, ^D - quit')
try:
while True:
command = input('')
while True:
try:
try:
command = input('')
if command == 's':
mac = parse_mac(input('mac> '))
writeall(proc.stdin, b's' + mac)
if command == 's':
mac = parse_mac(input('mac> '))
writeall(proc.stdin, b's' + mac)
elif command == 'i':
mac = parse_mac(input('mac> '))
writeall(proc.stdin, b'i' + mac)
elif command == 'i':
mac = parse_mac(input('mac> '))
writeall(proc.stdin, b'i' + mac)
elif command == 'm':
mac = parse_mac(input('mac> '))
message = input('message> ').encode('utf-8')
writeall(proc.stdin, b'm' + mac + bytes([len(message) >> 8, len(message) & 0xff]) + message)
elif command == 'm':
mac = parse_mac(input('mac> '))
message = input('message> ').encode('utf-8')
writeall(proc.stdin, b'm' + mac + bytes([len(message) >> 8, len(message) & 0xff]) + message)
else:
print('s - request status, i - request msgid, m - send message, ^D - quit')
else:
print('s - request status, i - request msgid, m - send message, ^D - quit')
except EOFError:
writeall(proc.stdin, b'q')
except EOFError:
writeall(proc.stdin, b'q')
break
except Exception as err:
print(err)
sys.exit(proc.wait())