Only get "fallback-encoding" setting when we need it

This commit is contained in:
jesopo 2018-08-05 11:42:25 +01:00
parent 5e42608ead
commit 558b368b1a

View file

@ -170,10 +170,6 @@ class Server(object):
self.remove_user(user) self.remove_user(user)
self.new_users.clear() self.new_users.clear()
def read(self): def read(self):
encoding = self.bot.database.get_server_setting(self.id,
"encoding", "utf8")
fallback_encoding = self.bot.database.get_server_setting(
self.id, "fallback-encoding", "latin-1")
data = b"" data = b""
try: try:
data = self.read_buffer + self.socket.recv(4096) data = self.read_buffer + self.socket.recv(4096)
@ -188,10 +184,12 @@ class Server(object):
decoded_lines = [] decoded_lines = []
for line in data_lines: for line in data_lines:
try: try:
line = line.decode(encoding) line = line.decode(self.get_setting(
"encoding", "utf8"))
except: except:
try: try:
line = line.decode(fallback_encoding) line = line.decode(self.get_setting(
"fallback-encoding", "latin-1"))
except: except:
continue continue
decoded_lines.append(line) decoded_lines.append(line)