Package for working with digit maps - a syntax for indicating the sequence of digits that define a valid and complete dialing attempt by a VoIP telephone user.
Project description
digitmap
Package for working with digit maps - a syntax for indicating the sequence of digits that define a valid and complete dialing attempt by a VoIP telephone user.
Features
- Parses digit maps into their individual string patterns
- Constructs digit maps from component objects
- Processes strings of dial events for matches to a digit map (full and partial)
Installation
pip install digitmap
What are digit maps?
Naturally, VoIP systems must collect digits dialed by a telephone user in order to route their call. Most call agents (i.e. IP phones) support two modes of dialing: on-hook and off-hook dialing. On-hook dialing is when the user dials the desired phone number while the handset is still 'on-hook', and the phone device sends the digits dialed to the gateway when the user lifts the handset.
Determining what number was dialed is simple, since the phone interprets lifting the handset as the user completing their dial. However, off-hook dialing - where the user lifts the handset first then dials the digits - is more difficult to handle. Without a discreet action for the user to signal they have finished dialing, deciding what number has been dialed is not as straight-forward.
The digit map is a mechanism that was proposed in RFC 3435 to help address this problem. Based on the Unix egrep syntax, a digit map is defined using a series of patterns that describe the valid sequences of digits that when transmitted from via the gateway, will result in a successful routing.
Overview of digit map syntax
For example, the dial plan for a VoIP system might be defined as follows:
Dial... | for... |
---|---|
0 | Local operator |
00 | Long distance operator |
any 4 digits | Local extensions |
8 + any 7 digits | Local numbers |
# + any 7 digits | Shortcut to local numbers at other corporate sites |
* + any 2 digits | Star services |
9 + 1 + any 10 digits | Long distance numbers |
9 + 011 + up to 15 digits | International numbers |
The corresponding digit map for this dial plan would be:
(0T|00T|[1-7]xxx|8xxxxxxx|#xxxxxxx|*xx|91xxxxxxxxxx|9011x.T)
Digit maps can contain one or more individual strings that each describe one of these such rules. The following elements can be used in defining digit maps, each with their own meaning:
Element | Description |
---|---|
0 -9 , A -D , # , * |
A single DTMF digit or symbol |
x |
Any DTMF digit (0 -9 ) |
[1-4] |
Any DTMF digit in the specified range(s). In this example, digits 1 , 2 , 3 , and 4 would be matched. Multiple digits and ranges can be placed between the brackets. |
. |
Zero or more occurrences of the preceeding element |
T |
Timer event from the call agent. This symbol is typically used to indicate that the call agent has timed out waiting for additional digits. |
Usage
Parsing a digit map
import digitmap as dm
# match any 7-digit number OR any 3-digit number ending in '11`
expr = "(xxxxxxx|x11)"
digit_map = dm.parse(expr)
print(repr(digit_map))
Output:
DigitMap([
DigitMapString([
WildcardElement(),
WildcardElement(),
WildcardElement(),
WildcardElement(),
WildcardElement(),
WildcardElement(),
WildcardElement()
]),
DigitMapString([
WildcardElement(),
DtmfElement("1"),
DtmfElement("1")
])
])
Constructing a digit map
import digitmap as dm
import digitmap.model as dm_model
# match any 7-digit number OR any 3-digit number ending in '11`
digit_map = dm_model.DigitMap([
dm_model.DigitMapString([
dm_model.WildcardElement(),
dm_model.WildcardElement(),
dm_model.WildcardElement(),
dm_model.WildcardElement(),
dm_model.WildcardElement(),
dm_model.WildcardElement(),
dm_model.WildcardElement()
]),
dm_model.DigitMapString([
dm_model.WildcardElement(),
dm_model.DtmfElement("1"),
dm_model.DtmfElement("1")
])
])
print(str(digit_map))
Output:
(xxxxxxx|x11)
Processing a string of dial events for matches
from digitmap import match
# match any 7-digit number OR any 3-digit number ending in '11`
expr = "(xxxxxxx|x11)"
dial_str = "411"
result = match(expr, dial_str)
print(f"Full matches: {result.full_matches}")
print(f"Partial matches: {result.exact_matches}")
*Output:
Full matches: ['x11']
Partial matches: ['xxxxxxx']
Support
Please use the project's Issues page to report any issues.
Contributing
Installing for development
poetry install
Linting source files
poetry run pylint --rcfile .pylintrc src/digitmap
Running tests
poetry run pytest
License
This library is licensed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file digitmap-1.0.0.tar.gz
.
File metadata
- Download URL: digitmap-1.0.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.10 CPython/3.9.7 Linux/5.8.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dda5e66e8d14fe9774c7c45a4bccda5e7a5d091600b9cd91b2a95abde34229da |
|
MD5 | d5ab8a2e53e48a6455d68e9947901766 |
|
BLAKE2b-256 | c4a3e736f18f1e8655083f3c2ded42b03711753334cea7cd7368e06dcbc2d09d |
File details
Details for the file digitmap-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: digitmap-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.10 CPython/3.9.7 Linux/5.8.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33227c301ee34c3ca71fe1018e60abb3ed3da61f5e0c4060c772af670797a36d |
|
MD5 | 1eda6266d7586bc17154169c34939207 |
|
BLAKE2b-256 | bd2002968ed7497567ea459e0016fa8161960e7904562ae947c1bc85db3aa62d |