From 9fe12dfa83284ecde3368c222f8d2d31ea38199c Mon Sep 17 00:00:00 2001 From: Timur Tuchkovenko Date: Fri, 27 Feb 2015 00:10:32 +0500 Subject: [PATCH] python3 compatibility manager fix --- asterisk/manager.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/asterisk/manager.py b/asterisk/manager.py index 8eefcb0..6fa9bb0 100644 --- a/asterisk/manager.py +++ b/asterisk/manager.py @@ -56,6 +56,7 @@ import sys import os import socket import threading +from six import PY3 from six.moves import queue import re from types import * @@ -262,7 +263,7 @@ class Manager(object): # lock the socket and send our command try: - self._sock.write(command) + self._sock.write(command.encode('ascii')) self._sock.flush() except socket.error as e: raise ManagerSocketException(e.errno, e.strerror) @@ -290,6 +291,7 @@ class Manager(object): try: lines = [] for line in self._sock: + line = line.decode('ascii') # check to see if this is the greeting line if not self.title and '/' in line and not ':' in line: # store the title of the manager we are connecting to: @@ -452,7 +454,10 @@ class Manager(object): try: _sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) _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() except socket.error as e: raise ManagerSocketException(e.errno, e.strerror)