Fix up networker for file sending.
This commit is contained in:
parent
c44110515e
commit
a99a207c34
13
networker.py
13
networker.py
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user