Fix up networker for file sending.

This commit is contained in:
Captain ALM 2022-12-10 20:48:13 +00:00
parent c44110515e
commit a99a207c34
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

View File

@ -15,25 +15,30 @@ class Message:
self.header = header
if mtype == MTYPE_File:
try:
f = open(header, "r")
f = open(header, "rb")
try:
self.content = str(f.read())
self.content = f.read()
except:
print("An issue writing the message for \"" + self.header + "\" occured.")
f.close()
except:
print("An issue when opening a file for reading: \"" + self.header + "\" occured.")
#print(traceback.format_exc())
else:
self.content = content
def saveContent(self):
if self.mtype != MTYPE_File: pass
try:
f = open(str(self.header), "w")
f = open(str(self.header), "wb")
try:
if type(self.content) == bytes or type(self.content) == bytearray:
f.write(bytes(self.content))
else:
f.write(bytes(self.content, encoding='utf-8'))
except:
print("An issue writing the message for \"" + str(self.header) + "\" occured.")
#print(traceback.format_exc())
f.close()
except:
print("An issue when opening a file for writing: \"" + str(self.header) + "\" occured.")
@ -42,7 +47,7 @@ class Message:
toReturn = {"mtype":self.mtype, "header":self.header, "ident__":"Message"}
if type(self.content) == bytes or type(self.content) == bytearray:
toReturn["contentb64"] = True
toReturn["content"] = base64.b64encode(bytes(self.content)).decode()
toReturn["content"] = base64.b64encode(bytes(self.content)).decode('utf-8')
else:
toReturn["contentb64"] = False
toReturn["content"] = self.content