Skip to main content

Helpers to convert numbers to dialplan strings for use in Asterisk

Project description

Introduction

Asterisk is a very powerful IP PBX application, however it’s dialplan logic can appear quite complicated.

This module adds some python bindings to help you manipulate patterns (and in future, more) from the dialplan. Initially, there is functions to help you “chunk” a range of numbers into asterisk dialplan patterns.

Installation

You can install this by simply running:

pip install asterisk_dialplan

Or you can use the latest development version:

pip install -e git+git://github.com/andrewyager/python-asterisk-dialplan.git#egg=asterisk_dialplan

Usage

asterisk_dialplan contains two main modules you want to interact with, namely ranges and patterns.

ranges contains the functionality required to chunk a number set in E.164 format into the subset of ranges Asterisk needs to parse. patterns contains the functionality to convert numeric ranges into Asterisk dialplan patterns.

Example usage:

from asterisk_dialplan.patterns import generate_patterns

# A relatively boring example that produces the patterns
# _61290000[0-3]XX
patterns = generate_patterns("61290000000", "61290000399")

# A more interesting example that produces the patterns
# _6129000029[3-9], _612900003XX
patterns = generate_patterns("61290000293", "61290000399")

# A single string number may as well not be a pattern match
# because Asterisk is better if it does less work
#61290000299
patterns = generate_patterns(61290000299, 61290000299)

You can also use the ranges module to just split the range (perhaps you want to build phone dialplans and need similar logic)

from asterisk_dialplan.ranges import split_range
ranges = split_range("61290000000", "61290000399")

Error Handling

If you provide bad input (i.e. your input strings/numbers aren’t the same length, or your upper number is less than your lower number) the module will throw a DialplanException which you can handle.

The module only (currently) handles numeric matches, so while you can match on strings etc within Asterisk, it’s not designed to handle anything like that. It also expects both arguments to be of the same length and in E.164 format (as indicated by the fact it will throw an exception).

If you provide numbers in a national format (perhaps with a leading 0?) this is currently untested and probably won’t work properly.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asterisk_dialplan-0.1.2.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

asterisk_dialplan-0.1.2-py2.7.egg (11.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page