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
|
self.header = header
|
||||||
if mtype == MTYPE_File:
|
if mtype == MTYPE_File:
|
||||||
try:
|
try:
|
||||||
f = open(header, "r")
|
f = open(header, "rb")
|
||||||
try:
|
try:
|
||||||
self.content = str(f.read())
|
self.content = f.read()
|
||||||
except:
|
except:
|
||||||
print("An issue writing the message for \"" + self.header + "\" occured.")
|
print("An issue writing the message for \"" + self.header + "\" occured.")
|
||||||
f.close()
|
f.close()
|
||||||
except:
|
except:
|
||||||
print("An issue when opening a file for reading: \"" + self.header + "\" occured.")
|
print("An issue when opening a file for reading: \"" + self.header + "\" occured.")
|
||||||
|
#print(traceback.format_exc())
|
||||||
else:
|
else:
|
||||||
self.content = content
|
self.content = content
|
||||||
|
|
||||||
def saveContent(self):
|
def saveContent(self):
|
||||||
if self.mtype != MTYPE_File: pass
|
if self.mtype != MTYPE_File: pass
|
||||||
try:
|
try:
|
||||||
f = open(str(self.header), "w")
|
f = open(str(self.header), "wb")
|
||||||
try:
|
try:
|
||||||
|
if type(self.content) == bytes or type(self.content) == bytearray:
|
||||||
f.write(bytes(self.content))
|
f.write(bytes(self.content))
|
||||||
|
else:
|
||||||
|
f.write(bytes(self.content, encoding='utf-8'))
|
||||||
except:
|
except:
|
||||||
print("An issue writing the message for \"" + str(self.header) + "\" occured.")
|
print("An issue writing the message for \"" + str(self.header) + "\" occured.")
|
||||||
|
#print(traceback.format_exc())
|
||||||
f.close()
|
f.close()
|
||||||
except:
|
except:
|
||||||
print("An issue when opening a file for writing: \"" + str(self.header) + "\" occured.")
|
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"}
|
toReturn = {"mtype":self.mtype, "header":self.header, "ident__":"Message"}
|
||||||
if type(self.content) == bytes or type(self.content) == bytearray:
|
if type(self.content) == bytes or type(self.content) == bytearray:
|
||||||
toReturn["contentb64"] = True
|
toReturn["contentb64"] = True
|
||||||
toReturn["content"] = base64.b64encode(bytes(self.content)).decode()
|
toReturn["content"] = base64.b64encode(bytes(self.content)).decode('utf-8')
|
||||||
else:
|
else:
|
||||||
toReturn["contentb64"] = False
|
toReturn["contentb64"] = False
|
||||||
toReturn["content"] = self.content
|
toReturn["content"] = self.content
|
||||||
|
Loading…
Reference in New Issue
Block a user