Skip to main content

digitmap

GitHub Workflow Status (branch) PyPI

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.

Metadata

Release files for digitmap 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for digitmap 1.0.0
File Size Uploaded
digitmap-1.0.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for digitmap 1.0.0
File Interpreter ABI Platform
digitmap-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.3 kB

Release files / digitmap-1.0.0.tar.gz

Download URL digitmap-1.0.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
dda5e66e8d14fe9774c7c45a4bccda5e7a5d091600b9cd91b2a95abde34229da
BLAKE2b-256 checksum
How to use checksums
c4a3e736f18f1e8655083f3c2ded42b03711753334cea7cd7368e06dcbc2d09d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.10 CPython/3.9.7 Linux/5.8.0-1041-azure

Release files / digitmap-1.0.0-py3-none-any.whl

Download URL digitmap-1.0.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33227c301ee34c3ca71fe1018e60abb3ed3da61f5e0c4060c772af670797a36d
BLAKE2b-256 checksum
How to use checksums
bd2002968ed7497567ea459e0016fa8161960e7904562ae947c1bc85db3aa62d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.10 CPython/3.9.7 Linux/5.8.0-1041-azure

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page