Internet: Use socket directly instead of telnetlib

We don't actually need telnetlib here; and it will be removed in
Python 3.11
This commit is contained in:
Valentin Lorentz 2024-05-05 20:36:58 +02:00 committed by Val Lorentz
parent 0ad61f5791
commit e18332efde

View File

@ -31,7 +31,6 @@
import time import time
import socket import socket
import telnetlib
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
@ -158,14 +157,14 @@ class Internet(callbacks.Plugin):
if not status: if not status:
status = 'unknown' status = 'unknown'
try: try:
t = telnetlib.Telnet('whois.iana.org', 43) sock = socket.create_connection(('whois.iana.org', 43))
except socket.error as e: except socket.error as e:
irc.error(str(e)) irc.error(str(e))
return return
t.write(b'registrar ') sock.sendall(b'registrar ')
t.write(registrar.split('(')[0].strip().encode('ascii')) sock.sendall(registrar.split('(')[0].strip().encode('ascii'))
t.write(b'\n') sock.sendall(b'\n')
s = t.read_all() s = sock.recv(100000)
url = '' url = ''
for line in s.splitlines(): for line in s.splitlines():
line = line.decode('ascii').strip() line = line.decode('ascii').strip()