Skip to content

Commit

Permalink
Refactor writing to socket a little
Browse files Browse the repository at this point in the history
  • Loading branch information
jirutka committed Aug 20, 2014
1 parent e326457 commit 49ad6f4
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions rsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,18 @@ def parse_file(self, line):
self.file += line

def close(self):
self.socket.send(b"close\n")
self.socket.send(b"token: " + self.env['token'].encode("utf8") + b"\n")
self.socket.send(b"\n")
for line in ["close", "token: " + self.env['token'], ""]:
self.socket.send(bytes(line + "\n", 'utf8'))
self.socket.shutdown(socket.SHUT_RDWR)
self.socket.close()
os.unlink(self.temp_path)
os.rmdir(self.temp_dir)

def send_save(self):
self.socket.send(b"save\n")
self.socket.send(b"token: " + self.env['token'].encode("utf8") + b"\n")
with open(self.temp_path, 'rb') as f:
new_file = f.read()
self.socket.send(b"data: " + str(len(new_file)).encode("utf8") + b"\n")
for line in ["save", "token: " + self.env['token'], "data: " + str(len(new_file))]:
self.socket.send(bytes(line + "\n", 'utf8'))
self.socket.send(new_file)
self.socket.send(b"\n")

Expand Down

0 comments on commit 49ad6f4

Please sign in to comment.