From 080bb6d627cb6753c9dff5225003d260a73a954e Mon Sep 17 00:00:00 2001 From: poing Date: Tue, 6 Sep 2016 18:47:21 +0900 Subject: [PATCH 01/17] Updated 'RECORD FILE' syntax, included silence detection value --- asterisk/agi.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index 9e8ce41..3328140 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -493,17 +493,20 @@ class AGI: self.set_extension(extension) self.set_priority(priority) - def record_file(self, filename, format='gsm', escape_digits='#', timeout=DEFAULT_RECORD, offset=0, beep='beep'): - """agi.record_file(filename, format, escape_digits, timeout=DEFAULT_TIMEOUT, offset=0, beep='beep') --> None - Record to a file until a given dtmf digit in the sequence is received - The format will specify what kind of file will be recorded. The timeout - is the maximum record time in milliseconds, or -1 for no timeout. Offset - samples is optional, and if provided will seek to the offset without - exceeding the end of the file + def record_file(self, filename, format='gsm', escape_digits='#', timeout=DEFAULT_RECORD, offset=0, beep='beep', silence=0): + """agi.record_file(filename, format, escape_digits, timeout=DEFAULT_TIMEOUT, offset=0, beep='beep', silence=0) --> None + Record to a file until a given dtmf digit in the sequence is received. Returns + '-1' on hangup or error. The format will specify what kind of file will be + recorded. The is the maximum record time in milliseconds, or '-1' + for no . is optional, and, if provided, will seek + to the offset without exceeding the end of the file. is the number + of seconds of silence allowed before the function returns despite the lack + of dtmf digits or reaching . value must be preceded by + 's=' and is also optional. """ escape_digits = self._process_digit_list(escape_digits) res = self.execute('RECORD FILE', self._quote(filename), format, - escape_digits, timeout, offset, beep)['result'][0] + escape_digits, timeout, offset, beep, ('s=%s' % silence))['result'][0] try: return chr(int(res)) except: From d7b47ccf6aa1f0540a735c347ad332ee8e064f42 Mon Sep 17 00:00:00 2001 From: poing Date: Wed, 7 Sep 2016 16:52:24 +0900 Subject: [PATCH 02/17] Chaged encoding to utf8 --- asterisk/agi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index 3328140..cbae4e6 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# vim: set et sw=4: +# -*- coding: utf-8 -*- """ .. module:: agi :synopsis: This module contains functions and classes to implment AGI scripts in python. From 2f9d2a35dc22edd3bfb7c703c44a3214083b0a72 Mon Sep 17 00:00:00 2001 From: poing Date: Wed, 7 Sep 2016 17:59:05 +0900 Subject: [PATCH 03/17] Fixing unicode --- asterisk/agi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index cbae4e6..c39ccb8 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -612,7 +612,7 @@ class AGI: Sends to the console via verbose message system. is the the verbose level (1-4) """ - self.execute('VERBOSE', self._quote(message), level) + self.execute('VERBOSE', self._quote(message) + type(message), level) def database_get(self, family, key): """agi.database_get(family, key) --> str From 59a3698a87f1e190e32cf59c8c4f9bd3e1877cd9 Mon Sep 17 00:00:00 2001 From: poing Date: Wed, 7 Sep 2016 17:59:50 +0900 Subject: [PATCH 04/17] Fixing unicode --- asterisk/agi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index c39ccb8..4880afa 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -612,7 +612,7 @@ class AGI: Sends to the console via verbose message system. is the the verbose level (1-4) """ - self.execute('VERBOSE', self._quote(message) + type(message), level) + self.execute('VERBOSE', type(self._quote(message)), level) def database_get(self, family, key): """agi.database_get(family, key) --> str From 267f8444ec6a376360e75e45afb8552f2e57d893 Mon Sep 17 00:00:00 2001 From: poing Date: Wed, 7 Sep 2016 18:01:28 +0900 Subject: [PATCH 05/17] Fixing unicode --- asterisk/agi.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index 4880afa..a6c1013 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -1,5 +1,6 @@ -#!/usr/bin/env python2 +#! /usr/bin/env python # -*- coding: utf-8 -*- +# vim:fenc=utf-8 """ .. module:: agi :synopsis: This module contains functions and classes to implment AGI scripts in python. @@ -26,6 +27,10 @@ import sys import pprint import re import signal +import sys +reload(sys) +sys.setdefaultencoding("utf-8") + DEFAULT_TIMEOUT = 2000 # 2sec timeout used as default for functions that take timeouts DEFAULT_RECORD = 20000 # 20sec record time From cae17c32bb230d46ba4172e5e00cff2a8f667874 Mon Sep 17 00:00:00 2001 From: poing Date: Wed, 7 Sep 2016 18:02:23 +0900 Subject: [PATCH 06/17] Fixing unicode --- asterisk/agi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index a6c1013..74d45d7 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -617,7 +617,7 @@ class AGI: Sends to the console via verbose message system. is the the verbose level (1-4) """ - self.execute('VERBOSE', type(self._quote(message)), level) + self.execute('VERBOSE', self._quote(message), level) def database_get(self, family, key): """agi.database_get(family, key) --> str From 68db20dd6526b83c563239a83b66b931bf86220c Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 10:51:01 +0900 Subject: [PATCH 07/17] Focus on UTF8 --- examples/unicode.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 examples/unicode.py diff --git a/examples/unicode.py b/examples/unicode.py new file mode 100755 index 0000000..ebd6f41 --- /dev/null +++ b/examples/unicode.py @@ -0,0 +1,26 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 + +""" +Example to get and set variables via AGI. + +You can call directly this script with AGI() in Asterisk dialplan. +""" + +from asterisk.agi import * + +agi = AGI() + +string = 'カタカナ' + +agi.verbose(string) + +# Get variable environment +extension = agi.env['agi_extension'] + +# Get variable in dialplan +phone_exten = agi.get_variable('PHONE_EXTEN') + +# Set variable, it will be available in dialplan +agi.set_variable('EXT_CALLERID', string) \ No newline at end of file From 96fabab755669e6c293deb508cfad4bfeb322adf Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 10:52:01 +0900 Subject: [PATCH 08/17] Focus on UTF8 --- examples/unicode.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/unicode.py b/examples/unicode.py index ebd6f41..c89162f 100755 --- a/examples/unicode.py +++ b/examples/unicode.py @@ -16,6 +16,8 @@ string = 'カタカナ' agi.verbose(string) +print('VERBOSE "カタカナ" 1') + # Get variable environment extension = agi.env['agi_extension'] From dab19ede42f28f1cd8a473075e088f2d6f19dc57 Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 10:55:56 +0900 Subject: [PATCH 09/17] Focus on UTF8 --- asterisk/agi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index 74d45d7..f19e9a0 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -129,7 +129,7 @@ class AGI: string = str(string) if isinstance(string, float): string = str(string) - return ''.join(['"', string.encode('ascii', 'ignore'), '"']) + return ''.join(['"', string.encode('utf8', 'ignore'), '"']) def _handle_sighup(self, signum, frame): """Handle the SIGHUP signal""" From f143d5fd0047761c767dd6504e2ff20fdcf6502b Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 11:01:10 +0900 Subject: [PATCH 10/17] Focus on UTF8 --- asterisk/agi.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index f19e9a0..183761c 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -1,6 +1,6 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- -# vim:fenc=utf-8 +-#!/usr/bin/env python2 +-# vim: set et sw=4: + """ .. module:: agi :synopsis: This module contains functions and classes to implment AGI scripts in python. @@ -27,10 +27,6 @@ import sys import pprint import re import signal -import sys -reload(sys) -sys.setdefaultencoding("utf-8") - DEFAULT_TIMEOUT = 2000 # 2sec timeout used as default for functions that take timeouts DEFAULT_RECORD = 20000 # 20sec record time From e4325c9be55be8a127faac80019f7fff30478059 Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 11:01:57 +0900 Subject: [PATCH 11/17] Focus on UTF8 --- asterisk/agi.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/asterisk/agi.py b/asterisk/agi.py index 183761c..033f665 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -27,6 +27,10 @@ import sys import pprint import re import signal +#import sys +reload(sys) +sys.setdefaultencoding("utf-8") + DEFAULT_TIMEOUT = 2000 # 2sec timeout used as default for functions that take timeouts DEFAULT_RECORD = 20000 # 20sec record time From 97a3c986eb14b9dca6e8a5b42c51f7bcf7144183 Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 11:02:37 +0900 Subject: [PATCH 12/17] Focus on UTF8 --- asterisk/agi.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index 033f665..f19e9a0 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -1,6 +1,6 @@ --#!/usr/bin/env python2 --# vim: set et sw=4: - +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 """ .. module:: agi :synopsis: This module contains functions and classes to implment AGI scripts in python. @@ -27,7 +27,7 @@ import sys import pprint import re import signal -#import sys +import sys reload(sys) sys.setdefaultencoding("utf-8") From 13e0369a33797aed892753dfe2ce9fb4568c2a45 Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 11:03:15 +0900 Subject: [PATCH 13/17] Focus on UTF8 --- asterisk/agi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index f19e9a0..1fdaa58 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -27,9 +27,9 @@ import sys import pprint import re import signal -import sys -reload(sys) -sys.setdefaultencoding("utf-8") +#import sys +#reload(sys) +#sys.setdefaultencoding("utf-8") DEFAULT_TIMEOUT = 2000 # 2sec timeout used as default for functions that take timeouts From c71a17ce84bf2eaa78f155d7e812faebb701f8b7 Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 11:06:13 +0900 Subject: [PATCH 14/17] Focus on UTF8 --- asterisk/agi.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index 1fdaa58..f69c546 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -27,10 +27,6 @@ import sys import pprint import re import signal -#import sys -#reload(sys) -#sys.setdefaultencoding("utf-8") - DEFAULT_TIMEOUT = 2000 # 2sec timeout used as default for functions that take timeouts DEFAULT_RECORD = 20000 # 20sec record time From 2c3357200fb43577326633b60e4b00842700f1d2 Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 11:08:21 +0900 Subject: [PATCH 15/17] Focus on UTF8 --- examples/unicode.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100755 examples/unicode.py diff --git a/examples/unicode.py b/examples/unicode.py deleted file mode 100755 index c89162f..0000000 --- a/examples/unicode.py +++ /dev/null @@ -1,28 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- -# vim:fenc=utf-8 - -""" -Example to get and set variables via AGI. - -You can call directly this script with AGI() in Asterisk dialplan. -""" - -from asterisk.agi import * - -agi = AGI() - -string = 'カタカナ' - -agi.verbose(string) - -print('VERBOSE "カタカナ" 1') - -# Get variable environment -extension = agi.env['agi_extension'] - -# Get variable in dialplan -phone_exten = agi.get_variable('PHONE_EXTEN') - -# Set variable, it will be available in dialplan -agi.set_variable('EXT_CALLERID', string) \ No newline at end of file From 1e890057dbe3373de7d0f733be10ff4e412c9da3 Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 11:11:11 +0900 Subject: [PATCH 16/17] Focus on UTF8 --- asterisk/agi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index f69c546..b2fdc03 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -1,6 +1,7 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- -# vim:fenc=utf-8 +# vim: set et sw=4 fenc=utf-8: + """ .. module:: agi :synopsis: This module contains functions and classes to implment AGI scripts in python. From 1d2f461fba061ab67238e1bb1177b53f038a9fa8 Mon Sep 17 00:00:00 2001 From: poing Date: Thu, 8 Sep 2016 11:12:19 +0900 Subject: [PATCH 17/17] Focus on UTF8 --- asterisk/agi.py | 1 - 1 file changed, 1 deletion(-) diff --git a/asterisk/agi.py b/asterisk/agi.py index b2fdc03..e2da50f 100755 --- a/asterisk/agi.py +++ b/asterisk/agi.py @@ -1,7 +1,6 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- # vim: set et sw=4 fenc=utf-8: - """ .. module:: agi :synopsis: This module contains functions and classes to implment AGI scripts in python.