diff --git a/CHANGELOG b/CHANGELOG index 09f49b4..7b0cf9c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,23 @@ +2015-07-18 Artem Sorokin + + * Fixing UTF-8 encoding issues. + +2015-07-15 Artem Sorokin + + * Fix multiline command end marker for OpenVox GSM Gateway. + +2015-03-31 Randall Degges + + * Porting packaging to setuptools (modern). + * Adding six as a dependency (it was missing before). + +2015-03-30 Areski Belaid + + * Fixing the MANIFEST.in file I accidentally broke :) + +2015-03-29 Timur Tuchkovenko + * UPGRADE: AMI fix for Python 3 compatibility. + 2014-10-08 Timur Tuchkovenko * UPGRADE: initial Python 3 support. Now pyst2 requires Python 'six' module. Some minor changes in other files. diff --git a/MANIFEST.in b/MANIFEST.in index 5a7b17f..7dec941 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ include CHANGELOG -include README +include README.rst include MANIFEST.in diff --git a/README.rst b/README.rst index 399915a..b073de1 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,44 @@ pyst2: A Python Interface to Asterisk -==================================== +===================================== -Pyst2 consists of a set of interfaces and libraries to allow programming of +.. image:: https://img.shields.io/pypi/v/pyst2.svg + :alt: pyst2 Release + :target: https://pypi.python.org/pypi/pyst2 + +.. image:: https://img.shields.io/pypi/dm/pyst2.svg + :alt: pyst2 Downloads + :target: https://pypi.python.org/pypi/pyst2 + +.. image:: https://img.shields.io/travis/rdegges/pyst2.svg + :alt: pyst2 Build + :target: https://travis-ci.org/rdegges/pyst2 + +.. image:: https://github.com/rdegges/pyst2/raw/master/assets/snake-sketch.jpg + :alt: Snake Sketch + + +Meta +---- + +- Author: Randall Degges +- Email: r@rdegges.com +- Site: http://www.rdegges.com +- Status: *looking for maintainer*, active + +**NOTE**: This project is in need of an active maintainer. I'm quite busy with +other non-asterisk related projects in my personal time, so if you're a good +Python programmer, and working with this library and Asterisk on a daily basis +-- please consider maintaining the project! Contact me for more information: +r@rdegges.com + +In the meantime, I'm happy to accept pull requests and cut releases as needed. +If you want to contribute to the project, please do! + + +Purpose +------- + +pyst2 consists of a set of interfaces and libraries to allow programming of Asterisk from python. The library currently supports AGI, AMI, and the parsing of Asterisk configuration files. The library also includes debugging facilities for AGI. @@ -15,25 +52,20 @@ My immediate plans include adding full documentation, re-writing some of the core routines, adding a test suite, and accepting pull requests. If you are one of the current maintainers, and would like to take over the -fork, please contact me: rdegges@gmail.com, so we can get that setup! +fork, please contact me: r@rdegges.com, so we can get that setup! -Requirements ------------- - -1. six Installation ------------ -Download from `Github project page`_. +To install ``pyst2``, simply run: -.. _`Github project page`: https://github.com/rdegges/pyst2 +.. code-block:: console -Installation is the standard python install:: + $ pip install pyst2 + +This will install the latest version of the library automatically. - git clone https://github.com/rdegges/pyst2.git - cd pyst2 - python setup.py install --prefix=/usr/local Documentation ------------- @@ -57,15 +89,19 @@ directly on the host where Asterisk is running. Since Asterisk doesn't run on windows platforms (and probably never will) the agi part of the package can only be run on Asterisk platforms. + Credits ------- Thanks to Karl Putland for writing the original package. + Thanks to Matthew Nicholson for maintaining the package for some years and for handing over maintenance when he was no longer interested. + Thanks to Randall Degges for maintaining this for and accepting pull requests. + Things to do for pyst --------------------- @@ -116,82 +152,3 @@ this, I'm currently satisfied with the threaded implementation): flexible. The current code will be consolidated into a single threaded design with hooks to have the library process events and such. These hooks will be called from the host application's main loop. - - -Upgrading from older versions ------------------------------ - -If upgrading from... - -* 0.2: - - - ``get_header()`` methods in ``manager.py`` now work like - ``dict.get()`` instead of ``dict[key]`` - - -* 0.1.0: - - - ``agi.get_variable`` no longer throws an exception, instead it - returns an empty string when a channel variable is not set. - - ``manager.quit()`` has be renamed to ``manager.close()`` - -Source Code Repository Access ------------------------------ - -The current versions are kept in a Subversion repository on Sourceforge. -You can check out the trunk with:: - - svn co https://pyst.svn.sourceforge.net/svnroot/pyst/pyst/trunk pyst - -There is also a 0.2 branch in:: - - https://pyst.svn.sourceforge.net/svnroot/pyst/pyst/branches/0.2 - -which contains unreleased changes after 0.2 (which have been merged into -trunk *after* changing how manager commands to asterisk are parsed). - -Released versions are in:: - - https://pyst.svn.sourceforge.net/svnroot/pyst/pyst/tags - -For versions prior to the 0.2 release when Matthew Nicholson was -maintaining pyst, the changes are kept in a `monotone`_ repository -(monotone is a free distributed version control system). Please contact -Matthew via Sourceforge if you're interested in intermediate versions. - -.. _`monotone`: http://monotone.ca/ - -prior to that the sources are in the CVS repository on sourceforge. - - -Changes -------- - -Version 0.3: Minor feature enhancements - -New maintainer Ralf Schlatterbeck, this is my first release, please -report any problems via the Sourceforge Bug-Tracker or email me -directly. Thanks to Karl Putland for writing the original package. -Thanks to Matthew Nicholson for maintaining the package for some years -and for handing over maintenance when he was no longer interested. -The parsing of answers from asterisk was completely rewritten. This -should fix problems people were having with commands returning embedded -'/' or empty lines. Some new manager commands added. - - - Add playdtmf manager command - - add sippeers and sipshowpeer manager commands - - rewritten manager communication - - should no longer choke on '/' in answers returned from a manager - command (fixes SF Bug 2947866) - - should now correctly parse multi-line output with embedded empty - lines, e.g. ``mgr.command('dialplan show')`` - - Bug-fix for list manipulation in ``event_dispatch``, thanks to Jan - Mueller, see mailinglist comment from 2008-04-18 - - Merge unreleased changes from repository of Matthew Nicholson - in particular a typo in ``agi.py`` for ``set_autohangup``, and change - of ``get_header`` methods (see Upgrading instructions). The fixed - ``manager.command`` support is already in (with a different - solution). The unreleased changes are also on the 0.2 branch in the - subversion repository in case somebody is interested. - -See the ChangeLog for older changes. diff --git a/assets/snake-sketch.jpg b/assets/snake-sketch.jpg new file mode 100644 index 0000000..a1579a2 Binary files /dev/null and b/assets/snake-sketch.jpg differ diff --git a/asterisk/__init__.py b/asterisk/__init__.py index 510678b..13b48cd 100644 --- a/asterisk/__init__.py +++ b/asterisk/__init__.py @@ -11,4 +11,4 @@ manager - a module for interacting with the asterisk manager interface """ __all__ = ['agi', 'agitb', 'config', 'manager'] -__version__ = '0.4.1' +__version__ = '0.4.6' diff --git a/asterisk/manager.py b/asterisk/manager.py index 8eefcb0..2f84f68 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('utf8')) 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('utf8') # 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: @@ -329,7 +331,7 @@ class Manager(object): line.split(':', 1)[1].strip() == 'Follows': wait_for_marker = True # same when seeing end of multiline response - if multiline and line.startswith('--END COMMAND--'): + if multiline and (line.startswith('--END COMMAND--') or line.strip().endswith('--END COMMAND--')): wait_for_marker = False multiline = False # same when seeing end of status response @@ -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) diff --git a/setup.py b/setup.py index 46cae39..5f62cee 100755 --- a/setup.py +++ b/setup.py @@ -1,44 +1,43 @@ -#!/usr/bin/env python +"""Packaging files and information.""" -from distutils.core import setup + +from setuptools import setup from asterisk import __version__ as version -description = [] -f = open('README.rst') - -logo_stripped = False -for line in f: - if not logo_stripped and line.strip(): - continue - logo_stripped = True - description.append(line) - -licenses = ('Python Software Foundation License', - 'GNU Library or Lesser General Public License (LGPL)') - setup( - name='pyst2', - version=version, - description='A Python Interface to Asterisk', - long_description=''.join(description), author='Karl Putland', - author_email='kputland@users.sourceforge.net', - maintainer='Randall Degges', - maintainer_email='rdegges@gmail.com', - url='https://github.com/rdegges/pyst2', - packages=['asterisk'], - license=', '.join(licenses), - platforms='Any', - classifiers=[ + + # Basic package information: + name = 'pyst2', + version = version, + packages = ['asterisk'], + + # Packaging options: + zip_safe = False, + include_package_data = True, + + # Package dependencies: + install_requires = ['six>=1.9.0'], + + # Metadata for PyPI: + author = 'Randall Degges', + author_email = 'r@rdegges.com', + license = 'Python Software Foundation License / GNU Library or Lesser General Public License (LGPL) / UNLICENSE', + url = 'https://github.com/rdegges/pyst2', + keywords = 'python asterisk agi ami telephony telephony sip voip', + description = 'A Python Interface to Asterisk', + long_description = open('README.rst').read(), + + # Classifiers: + platforms = 'Any', + classifiers = [ 'Development Status :: 5 - Production/Stable', 'Environment :: Other Environment', 'Intended Audience :: Developers', 'Intended Audience :: Telecommunications Industry', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.4', - 'Programming Language :: Python :: 2.5', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', @@ -48,5 +47,6 @@ setup( 'Topic :: Communications :: Internet Phone', 'Topic :: Communications :: Telephony', 'Topic :: Software Development :: Libraries :: Python Modules' - ] + ['License :: OSI Approved :: ' + l for l in licenses] + ], + )