python3 compatibility manager fix

develop
Timur Tuchkovenko 2015-02-27 00:10:32 +05:00
parent 5efe3f4593
commit 9fe12dfa83
1 changed files with 7 additions and 2 deletions

View File

@ -56,6 +56,7 @@ import sys
import os import os
import socket import socket
import threading import threading
from six import PY3
from six.moves import queue from six.moves import queue
import re import re
from types import * from types import *
@ -262,7 +263,7 @@ class Manager(object):
# lock the socket and send our command # lock the socket and send our command
try: try:
self._sock.write(command) self._sock.write(command.encode('ascii'))
self._sock.flush() self._sock.flush()
except socket.error as e: except socket.error as e:
raise ManagerSocketException(e.errno, e.strerror) raise ManagerSocketException(e.errno, e.strerror)
@ -290,6 +291,7 @@ class Manager(object):
try: try:
lines = [] lines = []
for line in self._sock: for line in self._sock:
line = line.decode('ascii')
# check to see if this is the greeting line # check to see if this is the greeting line
if not self.title and '/' in line and not ':' in line: if not self.title and '/' in line and not ':' in line:
# store the title of the manager we are connecting to: # store the title of the manager we are connecting to:
@ -452,7 +454,10 @@ class Manager(object):
try: try:
_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) _sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
_sock.connect((host, port)) _sock.connect((host, port))
self._sock = _sock.makefile() if PY3:
self._sock = _sock.makefile(mode='rwb', buffering=0)
else:
self._sock = _sock.makefile()
_sock.close() _sock.close()
except socket.error as e: except socket.error as e:
raise ManagerSocketException(e.errno, e.strerror) raise ManagerSocketException(e.errno, e.strerror)