minor rewrite for Python 3 support. Some other fixes in corresponding files.
This commit is contained in:
1 parent
6bd0cc9bd6
commit
5efe3f4593
11 files changed
+122
-83
No files matched your search
@@ -11,4 +11,4 @@ manager - a module for interacting with the asterisk manager interface
|
||||
"""
|
||||
|
||||
__all__ = ['agi', 'agitb', 'config', 'manager']
|
||||
__version__ = '0.4'
|
||||
__version__ = '0.4.1'
|
||||
+2
-3
@@ -22,7 +22,6 @@ pyvr
|
||||
import sys
|
||||
import pprint
|
||||
import re
|
||||
from types import ListType
|
||||
import signal
|
||||
|
||||
DEFAULT_TIMEOUT = 2000 # 2sec timeout used as default for functions that take timeouts
|
||||
@@ -131,7 +130,7 @@ class AGI:
|
||||
try:
|
||||
self.send_command(command, *args)
|
||||
return self.get_result()
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
if e.errno == 32:
|
||||
# Broken Pipe * let us go
|
||||
raise AGISIGPIPEHangup("Received SIGPIPE")
|
||||
@@ -188,7 +187,7 @@ class AGI:
|
||||
raise AGIUnknownError(code, 'Unhandled code or undefined response')
|
||||
|
||||
def _process_digit_list(self, digits):
|
||||
if type(digits) == ListType:
|
||||
if type(digits) is list:
|
||||
digits = ''.join(map(str, digits))
|
||||
return self._quote(digits)
|
||||
|
||||
|
||||
+2
-1
@@ -79,7 +79,7 @@ def scanvars(reader, frame, locals):
|
||||
return vars
|
||||
|
||||
|
||||
def text((etype, evalue, etb), context=5):
|
||||
def text(eparams, context=5):
|
||||
"""Return a plain text document describing a given traceback."""
|
||||
import os
|
||||
import types
|
||||
@@ -89,6 +89,7 @@ def text((etype, evalue, etb), context=5):
|
||||
import inspect
|
||||
import pydoc
|
||||
|
||||
etype, evalue, etb = eparams
|
||||
if isinstance(etype, types.ClassType):
|
||||
etype = etype.__name__
|
||||
pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
|
||||
|
||||
+4
-4
@@ -11,11 +11,11 @@ This module provides parsing functionality for asterisk config files.
|
||||
# load and parse the config file
|
||||
try:
|
||||
config = asterisk.config.Config('/etc/asterisk/extensions.conf')
|
||||
except asterisk.config.ParseError, (line, reason):
|
||||
print "Parse Error line: %s: %s" % (line, reason)
|
||||
except asterisk.config.ParseError as e:
|
||||
print "Parse Error line: %s: %s" % (e.line, e.strerror)
|
||||
sys.exit(1)
|
||||
except IOError, reason:
|
||||
print "Error opening file: %s" % reason
|
||||
except IOError as e:
|
||||
print "Error opening file: %s" % e.strerror
|
||||
sys.exit(1)
|
||||
|
||||
# print our parsed output
|
||||
|
||||
+16
-17
@@ -32,14 +32,14 @@ This module provides a Python API for interfacing with the asterisk manager.
|
||||
response = manager.status()
|
||||
|
||||
manager.logoff()
|
||||
except asterisk.manager.ManagerSocketException, (errno, reason):
|
||||
print "Error connecting to the manager: %s" % reason
|
||||
except asterisk.manager.ManagerSocketException as e:
|
||||
print "Error connecting to the manager: %s" % e.strerror
|
||||
sys.exit(1)
|
||||
except asterisk.manager.ManagerAuthException, reason:
|
||||
print "Error logging in to the manager: %s" % reason
|
||||
except asterisk.manager.ManagerAuthException as e:
|
||||
print "Error logging in to the manager: %s" % e.strerror
|
||||
sys.exit(1)
|
||||
except asterisk.manager.ManagerException, reason:
|
||||
print "Error: %s" % reason
|
||||
except asterisk.manager.ManagerException as e:
|
||||
print "Error: %s" % e.strerror
|
||||
sys.exit(1)
|
||||
|
||||
finally:
|
||||
@@ -56,9 +56,8 @@ import sys
|
||||
import os
|
||||
import socket
|
||||
import threading
|
||||
import Queue
|
||||
from six.moves import queue
|
||||
import re
|
||||
from cStringIO import StringIO
|
||||
from types import *
|
||||
from time import sleep
|
||||
|
||||
@@ -181,9 +180,9 @@ class Manager(object):
|
||||
self.hostname = socket.gethostname()
|
||||
|
||||
# our queues
|
||||
self._message_queue = Queue.Queue()
|
||||
self._response_queue = Queue.Queue()
|
||||
self._event_queue = Queue.Queue()
|
||||
self._message_queue = queue.Queue()
|
||||
self._response_queue = queue.Queue()
|
||||
self._event_queue = queue.Queue()
|
||||
|
||||
# callbacks for events
|
||||
self._event_callbacks = {}
|
||||
@@ -265,8 +264,8 @@ class Manager(object):
|
||||
try:
|
||||
self._sock.write(command)
|
||||
self._sock.flush()
|
||||
except socket.error, (errno, reason):
|
||||
raise ManagerSocketException(errno, reason)
|
||||
except socket.error as e:
|
||||
raise ManagerSocketException(e.errno, e.strerror)
|
||||
|
||||
self._reswaiting.insert(0, 1)
|
||||
response = self._response_queue.get()
|
||||
@@ -410,7 +409,7 @@ class Manager(object):
|
||||
elif message.has_header('Response'):
|
||||
self._response_queue.put(message)
|
||||
else:
|
||||
print 'No clue what we got\n%s' % message.data
|
||||
print('No clue what we got\n%s' % message.data)
|
||||
finally:
|
||||
# wait for our data receiving thread to exit
|
||||
t.join()
|
||||
@@ -445,7 +444,7 @@ class Manager(object):
|
||||
raise ManagerException('Already connected to manager')
|
||||
|
||||
# make sure host is a string
|
||||
assert type(host) in StringTypes
|
||||
assert type(host) is str
|
||||
|
||||
port = int(port) # make sure port is an int
|
||||
|
||||
@@ -455,8 +454,8 @@ class Manager(object):
|
||||
_sock.connect((host, port))
|
||||
self._sock = _sock.makefile()
|
||||
_sock.close()
|
||||
except socket.error, (errno, reason):
|
||||
raise ManagerSocketException(errno, reason)
|
||||
except socket.error as e:
|
||||
raise ManagerSocketException(e.errno, e.strerror)
|
||||
|
||||
# we are connected and running
|
||||
self._connected.set()
|
||||
|
||||
Reference in new issue
Block a user