mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Dict: Open connection in binary mode.
This commit is contained in:
parent
dcd07a2ec4
commit
9dcfce01c7
@ -45,15 +45,15 @@ class Connection:
|
|||||||
def __init__(self, hostname = 'localhost', port = 2628):
|
def __init__(self, hostname = 'localhost', port = 2628):
|
||||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.sock.connect((hostname, port))
|
self.sock.connect((hostname, port))
|
||||||
self.rfile = self.sock.makefile("rt")
|
self.rfile = self.sock.makefile("rb")
|
||||||
self.wfile = self.sock.makefile("wt", 0)
|
self.wfile = self.sock.makefile("wb", 0)
|
||||||
self.saveconnectioninfo()
|
self.saveconnectioninfo()
|
||||||
|
|
||||||
def getresultcode(self):
|
def getresultcode(self):
|
||||||
"""Generic function to get a result code. It will return a list
|
"""Generic function to get a result code. It will return a list
|
||||||
consisting of two items: the integer result code and the text
|
consisting of two items: the integer result code and the text
|
||||||
following. You will not usually use this function directly."""
|
following. You will not usually use this function directly."""
|
||||||
line = self.rfile.readline().strip()
|
line = self.rfile.readline().decode('ascii').strip()
|
||||||
code, text = line.split(' ', 1)
|
code, text = line.split(' ', 1)
|
||||||
return [int(code), text]
|
return [int(code), text]
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class Connection:
|
|||||||
part only. Does not get any codes or anything! Returns a string."""
|
part only. Does not get any codes or anything! Returns a string."""
|
||||||
data = []
|
data = []
|
||||||
while 1:
|
while 1:
|
||||||
line = self.rfile.readline().strip()
|
line = self.rfile.readline().decode('ascii').strip()
|
||||||
if line == '.':
|
if line == '.':
|
||||||
break
|
break
|
||||||
data.append(line)
|
data.append(line)
|
||||||
@ -163,7 +163,7 @@ class Connection:
|
|||||||
def sendcommand(self, command):
|
def sendcommand(self, command):
|
||||||
"""Takes a command, without a newline character, and sends it to
|
"""Takes a command, without a newline character, and sends it to
|
||||||
the server."""
|
the server."""
|
||||||
self.wfile.write(command + "\n")
|
self.wfile.write(command.encode('ascii') + b"\n")
|
||||||
|
|
||||||
def define(self, database, word):
|
def define(self, database, word):
|
||||||
"""Returns a list of Definition objects for each matching
|
"""Returns a list of Definition objects for each matching
|
||||||
|
Loading…
Reference in New Issue
Block a user