Skip to content

Commit

Permalink
Fix bytes and string conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Feb 16, 2015
1 parent 0794d85 commit 3a11fa0
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions chess/uci.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,10 @@ def __init__(self, engine, shell, command):

def write(self, byte):
# Interally called whenever a byte is received.
byte = byte.decode("utf-8")

if byte == "\r":
if byte == b"\r":
pass
elif byte == "\n":
self.engine.on_line_received("".join(self._stdout_buffer))
elif byte == b"\n":
self.engine.on_line_received(b"".join(self._stdout_buffer).decode("utf-8"))
del self._stdout_buffer[:]
else:
self._stdout_buffer.append(byte)
Expand All @@ -551,8 +549,8 @@ def close_std_streams(self):
pass

def send_line(self, string):
self.process.stdin_write(string)
self.process.stdin_write("\n")
self.process.stdin_write(string.encode("utf-8"))
self.process.stdin_write(b"\n")

def get_return_code(self):
return self._result.return_code if self._result else None
Expand Down

0 comments on commit 3a11fa0

Please sign in to comment.