808 lines
108 KiB
HTML
808 lines
108 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<title>asterisk.agi — pyst2 0.4.9 documentation</title>
|
|
|
|
<link rel="stylesheet" href="../../_static/alabaster.css" type="text/css" />
|
|
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '../../',
|
|
VERSION: '0.4.9',
|
|
COLLAPSE_INDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="../../_static/jquery.js"></script>
|
|
<script type="text/javascript" src="../../_static/underscore.js"></script>
|
|
<script type="text/javascript" src="../../_static/doctools.js"></script>
|
|
<link rel="top" title="pyst2 0.4.9 documentation" href="../../index.html" />
|
|
<link rel="up" title="Module code" href="../index.html" />
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
|
|
|
|
</head>
|
|
<body role="document">
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body" role="main">
|
|
|
|
<h1>Source code for asterisk.agi</h1><div class="highlight"><pre>
|
|
<span></span><span class="ch">#!/usr/bin/env python2</span>
|
|
<span class="c1"># vim: set et sw=4:</span>
|
|
<span class="sd">"""</span>
|
|
<span class="sd">.. module:: agi</span>
|
|
<span class="sd"> :synopsis: This module contains functions and classes to implment AGI scripts in python. </span>
|
|
<span class="sd"> </span>
|
|
<span class="sd">pyvr</span>
|
|
|
|
<span class="sd">{'agi_callerid' : 'mars.putland.int',</span>
|
|
<span class="sd"> 'agi_channel' : 'IAX[kputland@kputland]/119',</span>
|
|
<span class="sd"> 'agi_context' : 'default',</span>
|
|
<span class="sd"> 'agi_dnid' : '1000',</span>
|
|
<span class="sd"> 'agi_enhanced' : '0.0',</span>
|
|
<span class="sd"> 'agi_extension': '1000',</span>
|
|
<span class="sd"> 'agi_language' : 'en',</span>
|
|
<span class="sd"> 'agi_priority' : '1',</span>
|
|
<span class="sd"> 'agi_rdnis' : '',</span>
|
|
<span class="sd"> 'agi_request' : 'pyst',</span>
|
|
<span class="sd"> 'agi_type' : 'IAX'}</span>
|
|
|
|
<span class="sd">Specification</span>
|
|
<span class="sd">-------------</span>
|
|
<span class="sd">"""</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">sys</span>
|
|
<span class="kn">import</span> <span class="nn">pprint</span>
|
|
<span class="kn">import</span> <span class="nn">re</span>
|
|
<span class="kn">import</span> <span class="nn">signal</span>
|
|
|
|
<span class="n">DEFAULT_TIMEOUT</span> <span class="o">=</span> <span class="mi">2000</span> <span class="c1"># 2sec timeout used as default for functions that take timeouts</span>
|
|
<span class="n">DEFAULT_RECORD</span> <span class="o">=</span> <span class="mi">20000</span> <span class="c1"># 20sec record time</span>
|
|
|
|
<span class="n">re_code</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">r'(^\d*)\s*(.*)'</span><span class="p">)</span>
|
|
<span class="n">re_kv</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">r'(?P<key>\w+)=(?P<value>[^\s]+)\s*(?:\((?P<data>.*)\))*'</span><span class="p">)</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGIException</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGIError</span><span class="p">(</span><span class="n">AGIException</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGIUnknownError</span><span class="p">(</span><span class="n">AGIError</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGIAppError</span><span class="p">(</span><span class="n">AGIError</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
<span class="c1"># there are several different types of hangups we can detect</span>
|
|
<span class="c1"># they all are derrived from AGIHangup</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGIHangup</span><span class="p">(</span><span class="n">AGIAppError</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGISIGHUPHangup</span><span class="p">(</span><span class="n">AGIHangup</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGISIGPIPEHangup</span><span class="p">(</span><span class="n">AGIHangup</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGIResultHangup</span><span class="p">(</span><span class="n">AGIHangup</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGIDBError</span><span class="p">(</span><span class="n">AGIAppError</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGIUsageError</span><span class="p">(</span><span class="n">AGIError</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
|
|
<span class="k">class</span> <span class="nc">AGIInvalidCommand</span><span class="p">(</span><span class="n">AGIError</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
|
|
<div class="viewcode-block" id="AGI"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI">[docs]</a><span class="k">class</span> <span class="nc">AGI</span><span class="p">:</span>
|
|
<span class="sd">"""</span>
|
|
<span class="sd"> This class encapsulates communication between Asterisk an a python script.</span>
|
|
<span class="sd"> It handles encoding commands to Asterisk and parsing responses from</span>
|
|
<span class="sd"> Asterisk.</span>
|
|
<span class="sd"> """</span>
|
|
|
|
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stdin</span> <span class="o">=</span> <span class="n">stdin</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stdout</span> <span class="o">=</span> <span class="n">stdout</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span> <span class="o">=</span> <span class="n">stderr</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">_got_sighup</span> <span class="o">=</span> <span class="bp">False</span>
|
|
<span class="n">signal</span><span class="o">.</span><span class="n">signal</span><span class="p">(</span><span class="n">signal</span><span class="o">.</span><span class="n">SIGHUP</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_handle_sighup</span><span class="p">)</span> <span class="c1"># handle SIGHUP</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'ARGS: '</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">))</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">env</span> <span class="o">=</span> <span class="p">{}</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">_get_agi_env</span><span class="p">()</span>
|
|
|
|
<span class="k">def</span> <span class="nf">_get_agi_env</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
|
|
<span class="n">line</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'ENV LINE: '</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">line</span> <span class="o">==</span> <span class="s1">''</span><span class="p">:</span>
|
|
<span class="c1">#blank line signals end</span>
|
|
<span class="k">break</span>
|
|
<span class="n">key</span><span class="p">,</span> <span class="n">data</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">':'</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">':'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">':'</span><span class="p">)[</span><span class="mi">1</span><span class="p">:])</span>
|
|
<span class="n">key</span> <span class="o">=</span> <span class="n">key</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
|
|
<span class="n">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
|
|
<span class="k">if</span> <span class="n">key</span> <span class="o">!=</span> <span class="s1">''</span><span class="p">:</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'class AGI: self.env = '</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">))</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
|
|
|
<span class="k">def</span> <span class="nf">_quote</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">string</span><span class="p">):</span>
|
|
<span class="sd">""" provides double quotes to string, converts int/bool to string """</span>
|
|
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
|
|
<span class="n">string</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">string</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="nb">float</span><span class="p">):</span>
|
|
<span class="n">string</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">string</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s1">'"'</span><span class="p">,</span> <span class="n">string</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'ascii'</span><span class="p">,</span> <span class="s1">'ignore'</span><span class="p">),</span> <span class="s1">'"'</span><span class="p">])</span>
|
|
|
|
<span class="k">def</span> <span class="nf">_handle_sighup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">signum</span><span class="p">,</span> <span class="n">frame</span><span class="p">):</span>
|
|
<span class="sd">"""Handle the SIGHUP signal"""</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">_got_sighup</span> <span class="o">=</span> <span class="bp">True</span>
|
|
|
|
<div class="viewcode-block" id="AGI.test_hangup"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.test_hangup">[docs]</a> <span class="k">def</span> <span class="nf">test_hangup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="sd">"""This function throws AGIHangup if we have recieved a SIGHUP"""</span>
|
|
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_got_sighup</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGISIGHUPHangup</span><span class="p">(</span><span class="s2">"Received SIGHUP from Asterisk"</span><span class="p">)</span></div>
|
|
|
|
<span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">command</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">test_hangup</span><span class="p">()</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">send_command</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_result</span><span class="p">()</span>
|
|
<span class="k">except</span> <span class="ne">IOError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">errno</span> <span class="o">==</span> <span class="mi">32</span><span class="p">:</span>
|
|
<span class="c1"># Broken Pipe * let us go</span>
|
|
<span class="k">raise</span> <span class="n">AGISIGPIPEHangup</span><span class="p">(</span><span class="s2">"Received SIGPIPE"</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">raise</span>
|
|
|
|
<div class="viewcode-block" id="AGI.send_command"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.send_command">[docs]</a> <span class="k">def</span> <span class="nf">send_command</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">command</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
|
|
<span class="sd">"""Send a command to Asterisk"""</span>
|
|
<span class="n">command</span> <span class="o">=</span> <span class="n">command</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
|
|
<span class="n">command</span> <span class="o">=</span> <span class="s1">'</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="s1">' '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">args</span><span class="p">)))</span>
|
|
<span class="n">command</span> <span class="o">=</span> <span class="n">command</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
|
|
<span class="k">if</span> <span class="n">command</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">:</span>
|
|
<span class="n">command</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">' COMMAND: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">command</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.get_result"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.get_result">[docs]</a> <span class="k">def</span> <span class="nf">get_result</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">):</span>
|
|
<span class="sd">"""Read the result of a command from Asterisk"""</span>
|
|
<span class="n">code</span> <span class="o">=</span> <span class="mi">0</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'result'</span><span class="p">:</span> <span class="p">(</span><span class="s1">''</span><span class="p">,</span> <span class="s1">''</span><span class="p">)}</span>
|
|
<span class="n">line</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">' RESULT_LINE: </span><span class="si">%s</span><span class="se">\n</span><span class="s1">'</span> <span class="o">%</span> <span class="n">line</span><span class="p">)</span>
|
|
<span class="n">m</span> <span class="o">=</span> <span class="n">re_code</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">m</span><span class="p">:</span>
|
|
<span class="n">code</span><span class="p">,</span> <span class="n">response</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">groups</span><span class="p">()</span>
|
|
<span class="n">code</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">code</span><span class="p">)</span>
|
|
|
|
<span class="k">if</span> <span class="n">code</span> <span class="o">==</span> <span class="mi">200</span><span class="p">:</span>
|
|
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">re_kv</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="n">response</span><span class="p">):</span>
|
|
<span class="n">result</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
|
|
|
|
<span class="c1"># If user hangs up... we get 'hangup' in the data</span>
|
|
<span class="k">if</span> <span class="n">data</span> <span class="o">==</span> <span class="s1">'hangup'</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIResultHangup</span><span class="p">(</span><span class="s2">"User hungup during execution"</span><span class="p">)</span>
|
|
|
|
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="s1">'result'</span> <span class="ow">and</span> <span class="n">value</span> <span class="o">==</span> <span class="s1">'-1'</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIAppError</span><span class="p">(</span><span class="s2">"Error executing application, or hangup"</span><span class="p">)</span>
|
|
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">' RESULT_DICT: </span><span class="si">%s</span><span class="se">\n</span><span class="s1">'</span> <span class="o">%</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">result</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">result</span>
|
|
<span class="k">elif</span> <span class="n">code</span> <span class="o">==</span> <span class="mi">510</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIInvalidCommand</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
|
|
<span class="k">elif</span> <span class="n">code</span> <span class="o">==</span> <span class="mi">520</span><span class="p">:</span>
|
|
<span class="n">usage</span> <span class="o">=</span> <span class="p">[</span><span class="n">line</span><span class="p">]</span>
|
|
<span class="n">line</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
|
|
<span class="k">while</span> <span class="n">line</span><span class="p">[:</span><span class="mi">3</span><span class="p">]</span> <span class="o">!=</span> <span class="s1">'520'</span><span class="p">:</span>
|
|
<span class="n">usage</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
|
|
<span class="n">line</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
|
|
<span class="n">usage</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
|
|
<span class="n">usage</span> <span class="o">=</span> <span class="s1">'</span><span class="si">%s</span><span class="se">\n</span><span class="s1">'</span> <span class="o">%</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">usage</span><span class="p">)</span>
|
|
<span class="k">raise</span> <span class="n">AGIUsageError</span><span class="p">(</span><span class="n">usage</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIUnknownError</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="s1">'Unhandled code or undefined response'</span><span class="p">)</span></div>
|
|
|
|
<span class="k">def</span> <span class="nf">_process_digit_list</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">digits</span><span class="p">):</span>
|
|
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">digits</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">list</span><span class="p">:</span>
|
|
<span class="n">digits</span> <span class="o">=</span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">digits</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">digits</span><span class="p">)</span>
|
|
|
|
<div class="viewcode-block" id="AGI.answer"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.answer">[docs]</a> <span class="k">def</span> <span class="nf">answer</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="sd">"""agi.answer() --> None</span>
|
|
<span class="sd"> Answer channel if not already in answer state.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'ANSWER'</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.wait_for_digit"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.wait_for_digit">[docs]</a> <span class="k">def</span> <span class="nf">wait_for_digit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">DEFAULT_TIMEOUT</span><span class="p">):</span>
|
|
<span class="sd">"""agi.wait_for_digit(timeout=DEFAULT_TIMEOUT) --> digit</span>
|
|
<span class="sd"> Waits for up to 'timeout' milliseconds for a channel to receive a DTMF</span>
|
|
<span class="sd"> digit. Returns digit dialed</span>
|
|
<span class="sd"> Throws AGIError on channel falure</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'WAIT FOR DIGIT'</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to digit: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.send_text"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.send_text">[docs]</a> <span class="k">def</span> <span class="nf">send_text</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.send_text(text='') --> None</span>
|
|
<span class="sd"> Sends the given text on a channel. Most channels do not support the</span>
|
|
<span class="sd"> transmission of text.</span>
|
|
<span class="sd"> Throws AGIError on error/hangup</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SEND TEXT'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">text</span><span class="p">))[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.receive_char"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.receive_char">[docs]</a> <span class="k">def</span> <span class="nf">receive_char</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">DEFAULT_TIMEOUT</span><span class="p">):</span>
|
|
<span class="sd">"""agi.receive_char(timeout=DEFAULT_TIMEOUT) --> chr</span>
|
|
<span class="sd"> Receives a character of text on a channel. Specify timeout to be the</span>
|
|
<span class="sd"> maximum time to wait for input in milliseconds, or 0 for infinite. Most channels</span>
|
|
<span class="sd"> do not support the reception of text.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'RECEIVE CHAR'</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.tdd_mode"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.tdd_mode">[docs]</a> <span class="k">def</span> <span class="nf">tdd_mode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">'off'</span><span class="p">):</span>
|
|
<span class="sd">"""agi.tdd_mode(mode='on'|'off') --> None</span>
|
|
<span class="sd"> Enable/Disable TDD transmission/reception on a channel.</span>
|
|
<span class="sd"> Throws AGIAppError if channel is not TDD-capable.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'TDD MODE'</span><span class="p">,</span> <span class="n">mode</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIAppError</span><span class="p">(</span><span class="s1">'Channel </span><span class="si">%s</span><span class="s1"> is not TDD-capable'</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.stream_file"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.stream_file">[docs]</a> <span class="k">def</span> <span class="nf">stream_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">sample_offset</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
|
<span class="sd">"""agi.stream_file(filename, escape_digits='', sample_offset=0) --> digit</span>
|
|
<span class="sd"> Send the given file, allowing playback to be interrupted by the given</span>
|
|
<span class="sd"> digits, if any. escape_digits is a string '12345' or a list of</span>
|
|
<span class="sd"> ints [1,2,3,4,5] or strings ['1','2','3'] or mixed [1,'2',3,'4']</span>
|
|
<span class="sd"> If sample offset is provided then the audio will seek to sample</span>
|
|
<span class="sd"> offset before play starts. Returns digit if one was pressed.</span>
|
|
<span class="sd"> Throws AGIError if the channel was disconnected. Remember, the file</span>
|
|
<span class="sd"> extension must not be included in the filename.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span>
|
|
<span class="s1">'STREAM FILE'</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">escape_digits</span><span class="p">,</span> <span class="n">sample_offset</span><span class="p">)</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="n">response</span><span class="p">[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.control_stream_file"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.control_stream_file">[docs]</a> <span class="k">def</span> <span class="nf">control_stream_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">skipms</span><span class="o">=</span><span class="mi">3000</span><span class="p">,</span> <span class="n">fwd</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">rew</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">pause</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""</span>
|
|
<span class="sd"> Send the given file, allowing playback to be interrupted by the given</span>
|
|
<span class="sd"> digits, if any. escape_digits is a string '12345' or a list of</span>
|
|
<span class="sd"> ints [1,2,3,4,5] or strings ['1','2','3'] or mixed [1,'2',3,'4']</span>
|
|
<span class="sd"> If sample offset is provided then the audio will seek to sample</span>
|
|
<span class="sd"> offset before play starts. Returns digit if one was pressed.</span>
|
|
<span class="sd"> Throws AGIError if the channel was disconnected. Remember, the file</span>
|
|
<span class="sd"> extension must not be included in the filename.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'CONTROL STREAM FILE'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">filename</span><span class="p">),</span> <span class="n">escape_digits</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">skipms</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">fwd</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">rew</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">pause</span><span class="p">))</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="n">response</span><span class="p">[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.send_image"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.send_image">[docs]</a> <span class="k">def</span> <span class="nf">send_image</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
|
|
<span class="sd">"""agi.send_image(filename) --> None</span>
|
|
<span class="sd"> Sends the given image on a channel. Most channels do not support the</span>
|
|
<span class="sd"> transmission of images. Image names should not include extensions.</span>
|
|
<span class="sd"> Throws AGIError on channel failure</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SEND IMAGE'</span><span class="p">,</span> <span class="n">filename</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">!=</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIAppError</span><span class="p">(</span><span class="s1">'Channel falure on channel </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'agi_channel'</span><span class="p">,</span> <span class="s1">'UNKNOWN'</span><span class="p">))</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.say_digits"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.say_digits">[docs]</a> <span class="k">def</span> <span class="nf">say_digits</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">digits</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.say_digits(digits, escape_digits='') --> digit</span>
|
|
<span class="sd"> Say a given digit string, returning early if any of the given DTMF digits</span>
|
|
<span class="sd"> are received on the channel.</span>
|
|
<span class="sd"> Throws AGIError on channel failure</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">digits</span><span class="p">)</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SAY DIGITS'</span><span class="p">,</span> <span class="n">digits</span><span class="p">,</span> <span class="n">escape_digits</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.say_number"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.say_number">[docs]</a> <span class="k">def</span> <span class="nf">say_number</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">number</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.say_number(number, escape_digits='') --> digit</span>
|
|
<span class="sd"> Say a given digit string, returning early if any of the given DTMF digits</span>
|
|
<span class="sd"> are received on the channel.</span>
|
|
<span class="sd"> Throws AGIError on channel failure</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">number</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">number</span><span class="p">)</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SAY NUMBER'</span><span class="p">,</span> <span class="n">number</span><span class="p">,</span> <span class="n">escape_digits</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.say_alpha"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.say_alpha">[docs]</a> <span class="k">def</span> <span class="nf">say_alpha</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">characters</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.say_alpha(string, escape_digits='') --> digit</span>
|
|
<span class="sd"> Say a given character string, returning early if any of the given DTMF</span>
|
|
<span class="sd"> digits are received on the channel.</span>
|
|
<span class="sd"> Throws AGIError on channel failure</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">characters</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">characters</span><span class="p">)</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SAY ALPHA'</span><span class="p">,</span> <span class="n">characters</span><span class="p">,</span> <span class="n">escape_digits</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.say_phonetic"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.say_phonetic">[docs]</a> <span class="k">def</span> <span class="nf">say_phonetic</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">characters</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.say_phonetic(string, escape_digits='') --> digit</span>
|
|
<span class="sd"> Phonetically say a given character string, returning early if any of</span>
|
|
<span class="sd"> the given DTMF digits are received on the channel.</span>
|
|
<span class="sd"> Throws AGIError on channel failure</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">characters</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">characters</span><span class="p">)</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span>
|
|
<span class="s1">'SAY PHONETIC'</span><span class="p">,</span> <span class="n">characters</span><span class="p">,</span> <span class="n">escape_digits</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.say_date"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.say_date">[docs]</a> <span class="k">def</span> <span class="nf">say_date</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">seconds</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.say_date(seconds, escape_digits='') --> digit</span>
|
|
<span class="sd"> Say a given date, returning early if any of the given DTMF digits are</span>
|
|
<span class="sd"> pressed. The date should be in seconds since the UNIX Epoch (Jan 1, 1970 00:00:00)</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SAY DATE'</span><span class="p">,</span> <span class="n">seconds</span><span class="p">,</span> <span class="n">escape_digits</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.say_time"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.say_time">[docs]</a> <span class="k">def</span> <span class="nf">say_time</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">seconds</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.say_time(seconds, escape_digits='') --> digit</span>
|
|
<span class="sd"> Say a given time, returning early if any of the given DTMF digits are</span>
|
|
<span class="sd"> pressed. The time should be in seconds since the UNIX Epoch (Jan 1, 1970 00:00:00)</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SAY TIME'</span><span class="p">,</span> <span class="n">seconds</span><span class="p">,</span> <span class="n">escape_digits</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.say_datetime"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.say_datetime">[docs]</a> <span class="k">def</span> <span class="nf">say_datetime</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">seconds</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">zone</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.say_datetime(seconds, escape_digits='', format='', zone='') --> digit</span>
|
|
<span class="sd"> Say a given date in the format specfied (see voicemail.conf), returning</span>
|
|
<span class="sd"> early if any of the given DTMF digits are pressed. The date should be</span>
|
|
<span class="sd"> in seconds since the UNIX Epoch (Jan 1, 1970 00:00:00).</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">format</span><span class="p">:</span>
|
|
<span class="n">format</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">format</span><span class="p">)</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span>
|
|
<span class="s1">'SAY DATETIME'</span><span class="p">,</span> <span class="n">seconds</span><span class="p">,</span> <span class="n">escape_digits</span><span class="p">,</span> <span class="n">format</span><span class="p">,</span> <span class="n">zone</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.get_data"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.get_data">[docs]</a> <span class="k">def</span> <span class="nf">get_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">DEFAULT_TIMEOUT</span><span class="p">,</span> <span class="n">max_digits</span><span class="o">=</span><span class="mi">255</span><span class="p">):</span>
|
|
<span class="sd">"""agi.get_data(filename, timeout=DEFAULT_TIMEOUT, max_digits=255) --> digits</span>
|
|
<span class="sd"> Stream the given file and receive dialed digits</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'GET DATA'</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">max_digits</span><span class="p">)</span>
|
|
<span class="n">res</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s1">'result'</span><span class="p">]</span>
|
|
<span class="k">return</span> <span class="n">res</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.get_option"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.get_option">[docs]</a> <span class="k">def</span> <span class="nf">get_option</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
|
<span class="sd">"""agi.get_option(filename, escape_digits='', timeout=0) --> digit</span>
|
|
<span class="sd"> Send the given file, allowing playback to be interrupted by the given</span>
|
|
<span class="sd"> digits, if any. escape_digits is a string '12345' or a list of</span>
|
|
<span class="sd"> ints [1,2,3,4,5] or strings ['1','2','3'] or mixed [1,'2',3,'4']</span>
|
|
<span class="sd"> Returns digit if one was pressed.</span>
|
|
<span class="sd"> Throws AGIError if the channel was disconnected. Remember, the file</span>
|
|
<span class="sd"> extension must not be included in the filename.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">timeout</span><span class="p">:</span>
|
|
<span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span>
|
|
<span class="s1">'GET OPTION'</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">escape_digits</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'GET OPTION'</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">escape_digits</span><span class="p">)</span>
|
|
|
|
<span class="n">res</span> <span class="o">=</span> <span class="n">response</span><span class="p">[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s1">''</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to char: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.set_context"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.set_context">[docs]</a> <span class="k">def</span> <span class="nf">set_context</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
|
|
<span class="sd">"""agi.set_context(context)</span>
|
|
<span class="sd"> Sets the context for continuation upon exiting the application.</span>
|
|
<span class="sd"> No error appears to be produced. Does not set exten or priority</span>
|
|
<span class="sd"> Use at your own risk. Ensure that you specify a valid context.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SET CONTEXT'</span><span class="p">,</span> <span class="n">context</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.set_extension"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.set_extension">[docs]</a> <span class="k">def</span> <span class="nf">set_extension</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">extension</span><span class="p">):</span>
|
|
<span class="sd">"""agi.set_extension(extension)</span>
|
|
<span class="sd"> Sets the extension for continuation upon exiting the application.</span>
|
|
<span class="sd"> No error appears to be produced. Does not set context or priority</span>
|
|
<span class="sd"> Use at your own risk. Ensure that you specify a valid extension.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SET EXTENSION'</span><span class="p">,</span> <span class="n">extension</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.set_priority"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.set_priority">[docs]</a> <span class="k">def</span> <span class="nf">set_priority</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">priority</span><span class="p">):</span>
|
|
<span class="sd">"""agi.set_priority(priority)</span>
|
|
<span class="sd"> Sets the priority for continuation upon exiting the application.</span>
|
|
<span class="sd"> No error appears to be produced. Does not set exten or context</span>
|
|
<span class="sd"> Use at your own risk. Ensure that you specify a valid priority.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'set priority'</span><span class="p">,</span> <span class="n">priority</span><span class="p">)</span></div>
|
|
|
|
<span class="k">def</span> <span class="nf">goto_on_exit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">extension</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">priority</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="n">context</span> <span class="o">=</span> <span class="n">context</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s1">'agi_context'</span><span class="p">]</span>
|
|
<span class="n">extension</span> <span class="o">=</span> <span class="n">extension</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s1">'agi_extension'</span><span class="p">]</span>
|
|
<span class="n">priority</span> <span class="o">=</span> <span class="n">priority</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s1">'agi_priority'</span><span class="p">]</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">set_context</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">set_extension</span><span class="p">(</span><span class="n">extension</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">set_priority</span><span class="p">(</span><span class="n">priority</span><span class="p">)</span>
|
|
|
|
<div class="viewcode-block" id="AGI.record_file"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.record_file">[docs]</a> <span class="k">def</span> <span class="nf">record_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s1">'gsm'</span><span class="p">,</span> <span class="n">escape_digits</span><span class="o">=</span><span class="s1">'#'</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">DEFAULT_RECORD</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">beep</span><span class="o">=</span><span class="s1">'beep'</span><span class="p">):</span>
|
|
<span class="sd">"""agi.record_file(filename, format, escape_digits, timeout=DEFAULT_TIMEOUT, offset=0, beep='beep') --> None</span>
|
|
<span class="sd"> Record to a file until a given dtmf digit in the sequence is received</span>
|
|
<span class="sd"> The format will specify what kind of file will be recorded. The timeout</span>
|
|
<span class="sd"> is the maximum record time in milliseconds, or -1 for no timeout. Offset</span>
|
|
<span class="sd"> samples is optional, and if provided will seek to the offset without</span>
|
|
<span class="sd"> exceeding the end of the file</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">escape_digits</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_digit_list</span><span class="p">(</span><span class="n">escape_digits</span><span class="p">)</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'RECORD FILE'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">filename</span><span class="p">),</span> <span class="n">format</span><span class="p">,</span>
|
|
<span class="n">escape_digits</span><span class="p">,</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">beep</span><span class="p">)[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">res</span><span class="p">))</span>
|
|
<span class="k">except</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unable to convert result to digit: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">res</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.set_autohangup"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.set_autohangup">[docs]</a> <span class="k">def</span> <span class="nf">set_autohangup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">secs</span><span class="p">):</span>
|
|
<span class="sd">"""agi.set_autohangup(secs) --> None</span>
|
|
<span class="sd"> Cause the channel to automatically hangup at <secs> seconds in the</span>
|
|
<span class="sd"> future. Of course it can be hungup before then as well. Setting to</span>
|
|
<span class="sd"> 0 will cause the autohangup feature to be disabled on this channel.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SET AUTOHANGUP'</span><span class="p">,</span> <span class="n">secs</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.hangup"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.hangup">[docs]</a> <span class="k">def</span> <span class="nf">hangup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.hangup(channel='')</span>
|
|
<span class="sd"> Hangs up the specified channel.</span>
|
|
<span class="sd"> If no channel name is given, hangs up the current channel</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'HANGUP'</span><span class="p">,</span> <span class="n">channel</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.appexec"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.appexec">[docs]</a> <span class="k">def</span> <span class="nf">appexec</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">application</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.appexec(application, options='')</span>
|
|
<span class="sd"> Executes <application> with given <options>.</span>
|
|
<span class="sd"> Returns whatever the application returns, or -2 on failure to find</span>
|
|
<span class="sd"> application</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'EXEC'</span><span class="p">,</span> <span class="n">application</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">options</span><span class="p">))</span>
|
|
<span class="n">res</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'-2'</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIAppError</span><span class="p">(</span><span class="s1">'Unable to find application: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">application</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="n">res</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.set_callerid"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.set_callerid">[docs]</a> <span class="k">def</span> <span class="nf">set_callerid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">number</span><span class="p">):</span>
|
|
<span class="sd">"""agi.set_callerid(number) --> None</span>
|
|
<span class="sd"> Changes the callerid of the current channel.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SET CALLERID'</span><span class="p">,</span> <span class="n">number</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.channel_status"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.channel_status">[docs]</a> <span class="k">def</span> <span class="nf">channel_status</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.channel_status(channel='') --> int</span>
|
|
<span class="sd"> Returns the status of the specified channel. If no channel name is</span>
|
|
<span class="sd"> given the returns the status of the current channel.</span>
|
|
|
|
<span class="sd"> Return values:</span>
|
|
<span class="sd"> 0 Channel is down and available</span>
|
|
<span class="sd"> 1 Channel is down, but reserved</span>
|
|
<span class="sd"> 2 Channel is off hook</span>
|
|
<span class="sd"> 3 Digits (or equivalent) have been dialed</span>
|
|
<span class="sd"> 4 Line is ringing</span>
|
|
<span class="sd"> 5 Remote end is ringing</span>
|
|
<span class="sd"> 6 Line is up</span>
|
|
<span class="sd"> 7 Line is busy</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'CHANNEL STATUS'</span><span class="p">,</span> <span class="n">channel</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">AGIHangup</span><span class="p">:</span>
|
|
<span class="k">raise</span>
|
|
<span class="k">except</span> <span class="n">AGIAppError</span><span class="p">:</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'result'</span><span class="p">:</span> <span class="p">(</span><span class="s1">'-1'</span><span class="p">,</span> <span class="s1">''</span><span class="p">)}</span>
|
|
|
|
<span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="s1">'result'</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.set_variable"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.set_variable">[docs]</a> <span class="k">def</span> <span class="nf">set_variable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
|
|
<span class="sd">"""Set a channel variable.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'SET VARIABLE'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">value</span><span class="p">))</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.get_variable"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.get_variable">[docs]</a> <span class="k">def</span> <span class="nf">get_variable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
|
|
<span class="sd">"""Get a channel variable.</span>
|
|
|
|
<span class="sd"> This function returns the value of the indicated channel variable. If</span>
|
|
<span class="sd"> the variable is not set, an empty string is returned.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'GET VARIABLE'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="n">AGIResultHangup</span><span class="p">:</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'result'</span><span class="p">:</span> <span class="p">(</span><span class="s1">'1'</span><span class="p">,</span> <span class="s1">'hangup'</span><span class="p">)}</span>
|
|
|
|
<span class="n">res</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s1">'result'</span><span class="p">]</span>
|
|
<span class="k">return</span> <span class="n">value</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.get_full_variable"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.get_full_variable">[docs]</a> <span class="k">def</span> <span class="nf">get_full_variable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
|
|
<span class="sd">"""Get a channel variable.</span>
|
|
|
|
<span class="sd"> This function returns the value of the indicated channel variable. If</span>
|
|
<span class="sd"> the variable is not set, an empty string is returned.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">if</span> <span class="n">channel</span><span class="p">:</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'GET FULL VARIABLE'</span><span class="p">,</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">channel</span><span class="p">))</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'GET FULL VARIABLE'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
|
|
|
|
<span class="k">except</span> <span class="n">AGIResultHangup</span><span class="p">:</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'result'</span><span class="p">:</span> <span class="p">(</span><span class="s1">'1'</span><span class="p">,</span> <span class="s1">'hangup'</span><span class="p">)}</span>
|
|
|
|
<span class="n">res</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s1">'result'</span><span class="p">]</span>
|
|
<span class="k">return</span> <span class="n">value</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.verbose"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.verbose">[docs]</a> <span class="k">def</span> <span class="nf">verbose</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
|
|
<span class="sd">"""agi.verbose(message='', level=1) --> None</span>
|
|
<span class="sd"> Sends <message> to the console via verbose message system.</span>
|
|
<span class="sd"> <level> is the the verbose level (1-4)</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'VERBOSE'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">message</span><span class="p">),</span> <span class="n">level</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.database_get"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.database_get">[docs]</a> <span class="k">def</span> <span class="nf">database_get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">family</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
|
|
<span class="sd">"""agi.database_get(family, key) --> str</span>
|
|
<span class="sd"> Retrieves an entry in the Asterisk database for a given family and key.</span>
|
|
<span class="sd"> Returns 0 if <key> is not set. Returns 1 if <key></span>
|
|
<span class="sd"> is set and returns the variable in parenthesis</span>
|
|
<span class="sd"> example return code: 200 result=1 (testvariable)</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">family</span> <span class="o">=</span> <span class="s1">'"</span><span class="si">%s</span><span class="s1">"'</span> <span class="o">%</span> <span class="n">family</span>
|
|
<span class="n">key</span> <span class="o">=</span> <span class="s1">'"</span><span class="si">%s</span><span class="s1">"'</span> <span class="o">%</span> <span class="n">key</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span>
|
|
<span class="s1">'DATABASE GET'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">family</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
|
|
<span class="n">res</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s1">'result'</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIDBError</span><span class="p">(</span><span class="s1">'Key not found in database: family=</span><span class="si">%s</span><span class="s1">, key=</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span>
|
|
<span class="p">(</span><span class="n">family</span><span class="p">,</span> <span class="n">key</span><span class="p">))</span>
|
|
<span class="k">elif</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'1'</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">value</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIError</span><span class="p">(</span><span class="s1">'Unknown exception for : family=</span><span class="si">%s</span><span class="s1">, key=</span><span class="si">%s</span><span class="s1">, result=</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">family</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">result</span><span class="p">)))</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.database_put"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.database_put">[docs]</a> <span class="k">def</span> <span class="nf">database_put</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">family</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
|
|
<span class="sd">"""agi.database_put(family, key, value) --> None</span>
|
|
<span class="sd"> Adds or updates an entry in the Asterisk database for a</span>
|
|
<span class="sd"> given family, key, and value.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'DATABASE PUT'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span>
|
|
<span class="n">family</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">key</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>
|
|
<span class="n">res</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s1">'result'</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIDBError</span><span class="p">(</span><span class="s1">'Unable to put vaule in databale: family=</span><span class="si">%s</span><span class="s1">, key=</span><span class="si">%s</span><span class="s1">, value=</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">family</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">))</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.database_del"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.database_del">[docs]</a> <span class="k">def</span> <span class="nf">database_del</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">family</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
|
|
<span class="sd">"""agi.database_del(family, key) --> None</span>
|
|
<span class="sd"> Deletes an entry in the Asterisk database for a</span>
|
|
<span class="sd"> given family and key.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span>
|
|
<span class="s1">'DATABASE DEL'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">family</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
|
|
<span class="n">res</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s1">'result'</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIDBError</span><span class="p">(</span><span class="s1">'Unable to delete from database: family=</span><span class="si">%s</span><span class="s1">, key=</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">family</span><span class="p">,</span> <span class="n">key</span><span class="p">))</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.database_deltree"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.database_deltree">[docs]</a> <span class="k">def</span> <span class="nf">database_deltree</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">family</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span>
|
|
<span class="sd">"""agi.database_deltree(family, key='') --> None</span>
|
|
<span class="sd"> Deletes a family or specific keytree with in a family</span>
|
|
<span class="sd"> in the Asterisk database.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span>
|
|
<span class="s1">'DATABASE DELTREE'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">family</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quote</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
|
|
<span class="n">res</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s1">'result'</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="n">res</span> <span class="o">==</span> <span class="s1">'0'</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">AGIDBError</span><span class="p">(</span><span class="s1">'Unable to delete tree from database: family=</span><span class="si">%s</span><span class="s1">, key=</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">family</span><span class="p">,</span> <span class="n">key</span><span class="p">))</span></div>
|
|
|
|
<div class="viewcode-block" id="AGI.noop"><a class="viewcode-back" href="../../agi.html#asterisk.agi.AGI.noop">[docs]</a> <span class="k">def</span> <span class="nf">noop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="sd">"""agi.noop() --> None</span>
|
|
<span class="sd"> Does nothing</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'NOOP'</span><span class="p">)</span></div></div>
|
|
|
|
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
|
|
<span class="n">agi</span> <span class="o">=</span> <span class="n">AGI</span><span class="p">()</span>
|
|
<span class="c1">#agi.appexec('festival','Welcome to Klass Technologies. Thank you for calling.')</span>
|
|
<span class="c1">#agi.appexec('festival','This is a test of the text to speech engine.')</span>
|
|
<span class="c1">#agi.appexec('festival','Press 1 for sales ')</span>
|
|
<span class="c1">#agi.appexec('festival','Press 2 for customer support ')</span>
|
|
<span class="c1">#agi.hangup()</span>
|
|
<span class="c1">#agi.goto_on_exit(extension='1234', priority='1')</span>
|
|
<span class="c1">#sys.exit(0)</span>
|
|
<span class="c1">#agi.say_digits('123', [4,'5',6])</span>
|
|
<span class="c1">#agi.say_digits([4,5,6])</span>
|
|
<span class="c1">#agi.say_number('1234')</span>
|
|
<span class="c1">#agi.say_number('01234') # 668</span>
|
|
<span class="c1">#agi.say_number('0xf5') # 245</span>
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="s1">'demo-congrats'</span><span class="p">)</span>
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">hangup</span><span class="p">()</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
|
<span class="c1">#agi.record_file('pyst-test') #FAILS</span>
|
|
<span class="c1">#agi.stream_file('demo-congrats', [1,2,3,4,5,6,7,8,9,0,'#','*'])</span>
|
|
<span class="c1">#agi.appexec('background','demo-congrats')</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">appexec</span><span class="p">(</span><span class="s1">'backgrounder'</span><span class="p">,</span> <span class="s1">'demo-congrats'</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">AGIAppError</span><span class="p">:</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
|
|
<span class="s2">"Handled exception for missing application backgrounder</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
|
|
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">set_variable</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">)</span>
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">get_variable</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">get_variable</span><span class="p">(</span><span class="s1">'foobar'</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">AGIAppError</span><span class="p">:</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"Handled exception for missing variable foobar</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">database_put</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">,</span> <span class="s1">'foobar'</span><span class="p">)</span>
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">database_put</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'baz'</span><span class="p">,</span> <span class="s1">'foobaz'</span><span class="p">)</span>
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">database_put</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bat'</span><span class="p">,</span> <span class="s1">'foobat'</span><span class="p">)</span>
|
|
<span class="n">v</span> <span class="o">=</span> <span class="n">agi</span><span class="o">.</span><span class="n">database_get</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">)</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'DBVALUE foo:bar = </span><span class="si">%s</span><span class="se">\n</span><span class="s1">'</span> <span class="o">%</span> <span class="n">v</span><span class="p">)</span>
|
|
<span class="n">v</span> <span class="o">=</span> <span class="n">agi</span><span class="o">.</span><span class="n">database_get</span><span class="p">(</span><span class="s1">'bar'</span><span class="p">,</span> <span class="s1">'foo'</span><span class="p">)</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'DBVALUE foo:bar = </span><span class="si">%s</span><span class="se">\n</span><span class="s1">'</span> <span class="o">%</span> <span class="n">v</span><span class="p">)</span>
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">database_del</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">)</span>
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">database_deltree</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">AGIDBError</span><span class="p">:</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
|
|
<span class="s2">"Handled exception for missing database entry bar:foo</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
|
|
|
|
<span class="n">agi</span><span class="o">.</span><span class="n">hangup</span><span class="p">()</span>
|
|
</pre></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
|
<div class="sphinxsidebarwrapper"><div class="relations">
|
|
<h3>Related Topics</h3>
|
|
<ul>
|
|
<li><a href="../../index.html">Documentation overview</a><ul>
|
|
<li><a href="../index.html">Module code</a><ul>
|
|
</ul></li>
|
|
</ul></li>
|
|
</ul>
|
|
</div>
|
|
<div id="searchbox" style="display: none" role="search">
|
|
<h3>Quick search</h3>
|
|
<form class="search" action="../../search.html" method="get">
|
|
<input type="text" name="q" />
|
|
<input type="submit" value="Go" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
<p class="searchtip" style="font-size: 90%">
|
|
Enter search terms or a module, class or function name.
|
|
</p>
|
|
</div>
|
|
<script type="text/javascript">$('#searchbox').show(0);</script>
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="footer">
|
|
©2016, Randall Degges.
|
|
|
|
|
|
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.3.6</a>
|
|
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.7</a>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</body>
|
|
</html> |