Skip to content

Commit 96ffeba

Browse files
committed
Init
0 parents  commit 96ffeba

File tree

9 files changed

+2773
-0
lines changed

9 files changed

+2773
-0
lines changed

PKG-INFO

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
Metadata-Version: 1.0
2+
Name: smspdu
3+
Version: 1.0
4+
Summary: SMS PDU encoding and decoding, including GSM-0338 character set
5+
Home-page: http://pypi.python.org/pypi/smspdu
6+
Author: Richard Jones
7+
Author-email: [email protected]
8+
License: UNKNOWN
9+
Description: SMS PDU encoding and decoding, including GSM-0338 character set.
10+
11+
Overview
12+
--------
13+
14+
This library handles SMS-DELIVER and SMS-SUBMIT format PDUs, and includes
15+
full support for all data formats, flags and headers, and round-trips from
16+
PDU to object and back again.
17+
18+
It also includes convenience APIs for constructing new PDUs from text or
19+
data.
20+
21+
This library is very mature - it's been in production use for many years
22+
before the 1.0 release was made. It's also, as far as I'm aware, the most
23+
complete SMS PDU encoding and decoding library available.
24+
25+
The T39 functionality has been copied from the previous PyPI package with
26+
the same name as this library to provide some continuity. It is untested.
27+
28+
29+
PDU Interface
30+
-------------
31+
32+
Typical usage will involve the SMS_SUBMIT and SMS_DELIVER .fromPDU(),
33+
.toPDU() and .create() methods:
34+
35+
>>> from smspdu import SMS_SUBMIT
36+
>>> pdu = SMS_SUBMIT.create('sender', 'recipient', 'hello, world')
37+
>>> pdu.toPDU()
38+
'010010D0F2F2380D4F97DD7400000CE8329BFD6681EE6F399B0C'
39+
>>> pdu = smspdu.SMS_SUBMIT.fromPDU(_, 'sender')
40+
>>> pdu.user_data
41+
u'hello, world'
42+
43+
44+
Command-line Usage
45+
------------------
46+
47+
To decode a PDU on the command-line (using python2.7+), use::
48+
49+
% python -m smspdu 010010D0F2F2380D4F97DD7400000CE8329BFD6681EE6F399B0C
50+
51+
010010D0F2F2380D4F97DD7400000CE8329BFD6681EE6F399B0C
52+
tp_mti = 1 (SMS-SUBMIT)
53+
sender = unknown
54+
tp_rd = 0
55+
tp_vpf = 0
56+
tp_vp = None
57+
tp_rp = 0
58+
tp_udhi = 0
59+
tp_srr = 0
60+
tp_mr = 0
61+
tp_al = 16
62+
tp_toa = d0 (Alphanumeric; Unknown)
63+
(recipient) address = 'recipient'
64+
tp_pid = 0x00 (Normal Case)
65+
tp_dcs = 0x00 (Immedate Display, GSM-0338 Default Alphabet)
66+
tp_udl = 12
67+
tp_ud = '\xe82\x9b\xfdf\x81\xeeo9\x9b\x0c'
68+
datestamp = 11062712173200
69+
user_data = u'hello, world'
70+
user_data_headers = []
71+
72+
The first line re-displays the PDU with the various sections colourised.
73+
74+
Users of versions of Python 2.6 will need to run "python -m smspdu.pdu".
75+
76+
77+
SMS Text - Handling the Awesomeness of GSM 0338
78+
------------------------------------------------
79+
80+
First the basics; encoding some text:
81+
82+
>>> from smspdu import gsm0338
83+
>>> c = gsm0338()
84+
>>> gsm_message = c.encode(u'test message')
85+
86+
And decoding that message:
87+
88+
>>> from smspdu import gsm0338
89+
>>> c = gsm0338()
90+
>>> c.decode(gsm_message)
91+
u'test message'
92+
93+
The library also provides some functions for making text SMS-happy:
94+
95+
:func:`gsm0338_safe`
96+
A simplistic function which just replaces any characters in the unicode
97+
input. You should probably use :func:`attempt_encoding` instead since it
98+
tries to make the message appear the same.
99+
:func:`attempt_encoding`
100+
Attempt to encode the supplied text for SMS transmission in a single
101+
message. This will alter the message to replace accents and typography
102+
where necessary to reduce the per-character septet count.
103+
:func:`remove_accent`
104+
Used by :func:`attempt_encoding` to remove all accents from characters in
105+
the supplied text.
106+
:func:`remove_typography`
107+
Used by :func:`attempt_encoding` to replaced typograpically-correct
108+
punctuation with simplified GSM-0338 characters.
109+
:func:`decode_ascii_safe`
110+
Removes all non-printable, non-ASCII codes in the string.
111+
:func:`smpp_to_sms_data_coding`
112+
Attempt to convert the SMPP data coding scheme (SMPP v34) to a useful
113+
SMS PDU (GSM 03.38) data coding scheme.
114+
115+
Version History (in Brief)
116+
--------------------------
117+
118+
- 1.0 the initial release based on mature internal ekit.com code
119+
120+
----
121+
This code is copyright 2011 eKit.com Inc (http://www.ekit.com/)
122+
See the end of the source file for the license of use.
123+
124+
125+
Platform: UNKNOWN
126+
Classifier: Intended Audience :: Developers
127+
Classifier: Programming Language :: Python :: 2.6
128+
Classifier: Programming Language :: Python :: 2.7
129+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
130+
Classifier: License :: OSI Approved :: BSD License

README.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
For documentation please "pydoc smspdu". The same documentation is available
2+
at http://pypi.python.org/pypi/smspdu
3+
4+
To run its tests use "python -m html".
5+
6+
To install under Python 2:
7+
8+
% python setup.py install
9+
10+
To install under Python 3:
11+
12+
% python3 setup.py build install

setup.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#! /usr/bin/env python
2+
3+
from distutils.core import setup
4+
5+
from smspdu import __version__, __doc__
6+
7+
# perform the setup action
8+
setup(
9+
name = "smspdu",
10+
version = __version__,
11+
description = "SMS PDU encoding and decoding, including GSM-0338 character set",
12+
long_description = __doc__.decode('utf8'),
13+
author = "Richard Jones",
14+
author_email = "[email protected]",
15+
packages = ['smspdu'],
16+
url = 'http://pypi.python.org/pypi/smspdu',
17+
classifiers = [
18+
'Intended Audience :: Developers',
19+
'Programming Language :: Python :: 2.6',
20+
'Programming Language :: Python :: 2.7',
21+
'Topic :: Software Development :: Libraries :: Python Modules',
22+
'License :: OSI Approved :: BSD License',
23+
],
24+
)
25+
26+
# vim: set filetype=python ts=4 sw=4 et si

smspdu/__init__.py

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#-*- encoding: utf8 -*-
2+
'''SMS PDU encoding and decoding, including GSM-0338 character set.
3+
4+
Overview
5+
--------
6+
7+
This library handles SMS-DELIVER and SMS-SUBMIT format PDUs, and includes
8+
full support for all data formats, flags and headers, and round-trips from
9+
PDU to object and back again.
10+
11+
It also includes convenience APIs for constructing new PDUs from text or
12+
data.
13+
14+
This library is very mature - it's been in production use for many years
15+
before the 1.0 release was made. It's also, as far as I'm aware, the most
16+
complete SMS PDU encoding and decoding library available.
17+
18+
The T39 functionality has been copied from the previous PyPI package with
19+
the same name as this library to provide some continuity. It is untested.
20+
21+
22+
PDU Interface
23+
-------------
24+
25+
Typical usage will involve the SMS_SUBMIT and SMS_DELIVER .fromPDU(),
26+
.toPDU() and .create() methods:
27+
28+
>>> from smspdu import SMS_SUBMIT
29+
>>> pdu = SMS_SUBMIT.create('sender', 'recipient', 'hello, world')
30+
>>> pdu.toPDU()
31+
'010010D0F2F2380D4F97DD7400000CE8329BFD6681EE6F399B0C'
32+
>>> pdu = smspdu.SMS_SUBMIT.fromPDU(_, 'sender')
33+
>>> pdu.user_data
34+
u'hello, world'
35+
36+
37+
Command-line Usage
38+
------------------
39+
40+
To decode a PDU on the command-line (using python2.7+), use::
41+
42+
% python -m smspdu 010010D0F2F2380D4F97DD7400000CE8329BFD6681EE6F399B0C
43+
44+
010010D0F2F2380D4F97DD7400000CE8329BFD6681EE6F399B0C
45+
tp_mti = 1 (SMS-SUBMIT)
46+
sender = unknown
47+
tp_rd = 0
48+
tp_vpf = 0
49+
tp_vp = None
50+
tp_rp = 0
51+
tp_udhi = 0
52+
tp_srr = 0
53+
tp_mr = 0
54+
tp_al = 16
55+
tp_toa = d0 (Alphanumeric; Unknown)
56+
(recipient) address = 'recipient'
57+
tp_pid = 0x00 (Normal Case)
58+
tp_dcs = 0x00 (Immedate Display, GSM-0338 Default Alphabet)
59+
tp_udl = 12
60+
tp_ud = '\\xe82\\x9b\\xfdf\\x81\\xeeo9\\x9b\\x0c'
61+
datestamp = 11062712173200
62+
user_data = u'hello, world'
63+
user_data_headers = []
64+
65+
The first line re-displays the PDU with the various sections colourised.
66+
67+
Users of versions of Python 2.6 will need to run "python -m smspdu.pdu".
68+
69+
70+
SMS Text - Handling the Awesomeness of GSM 0338
71+
------------------------------------------------
72+
73+
First the basics; encoding some text:
74+
75+
>>> from smspdu import gsm0338
76+
>>> c = gsm0338()
77+
>>> gsm_message = c.encode(u'test message')
78+
79+
And decoding that message:
80+
81+
>>> from smspdu import gsm0338
82+
>>> c = gsm0338()
83+
>>> c.decode(gsm_message)
84+
u'test message'
85+
86+
The library also provides some functions for making text SMS-happy:
87+
88+
:func:`gsm0338_safe`
89+
A simplistic function which just replaces any characters in the unicode
90+
input. You should probably use :func:`attempt_encoding` instead since it
91+
tries to make the message appear the same.
92+
:func:`attempt_encoding`
93+
Attempt to encode the supplied text for SMS transmission in a single
94+
message. This will alter the message to replace accents and typography
95+
where necessary to reduce the per-character septet count.
96+
:func:`remove_accent`
97+
Used by :func:`attempt_encoding` to remove all accents from characters in
98+
the supplied text.
99+
:func:`remove_typography`
100+
Used by :func:`attempt_encoding` to replaced typograpically-correct
101+
punctuation with simplified GSM-0338 characters.
102+
:func:`decode_ascii_safe`
103+
Removes all non-printable, non-ASCII codes in the string.
104+
:func:`smpp_to_sms_data_coding`
105+
Attempt to convert the SMPP data coding scheme (SMPP v34) to a useful
106+
SMS PDU (GSM 03.38) data coding scheme.
107+
108+
Version History (in Brief)
109+
--------------------------
110+
111+
- 1.0 the initial release based on mature internal ekit.com code
112+
113+
----
114+
This code is copyright 2011 eKit.com Inc (http://www.ekit.com/)
115+
See the end of the source file for the license of use.
116+
117+
'''
118+
119+
__version__ = '1.0'
120+
121+
from .pdu import (SMS_SUBMIT, SMS_DELIVER, attempt_encoding,
122+
smpp_to_sms_data_coding, remove_accent, remove_typography,
123+
decode_ascii_safe)
124+
from .gsm0338 import Codec as gsm0338
125+
126+
def gsm0338_safe(message):
127+
'''Make the given unicode string gsm0338-safe by replacing out any
128+
characters not present in the above.
129+
'''
130+
c = gsm0338()
131+
gsm_message = c.encode(message, 'replace')
132+
return c.decode(gsm_message)[0]
133+
134+
135+
# Copyright (c) 2011 eKit.com Inc (http://www.ekit.com/)
136+
#
137+
# Permission is hereby granted, free of charge, to any person obtaining a copy
138+
# of this software and associated documentation files (the "Software"), to deal
139+
# in the Software without restriction, including without limitation the rights
140+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
141+
# copies of the Software, and to permit persons to whom the Software is
142+
# furnished to do so, subject to the following conditions:
143+
#
144+
# The above copyright notice and this permission notice shall be included in
145+
# all copies or substantial portions of the Software.
146+
#
147+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
148+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
149+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
150+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
151+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
152+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
153+
# SOFTWARE.

smspdu/__main__.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from .pdu import dump
2+
3+
if __name__ == '__main__':
4+
import sys
5+
dump(sys.argv[1])
6+
7+
# Copyright (c) 2011 eKit.com Inc (http://www.ekit.com/)
8+
#
9+
# Permission is hereby granted, free of charge, to any person obtaining a copy
10+
# of this software and associated documentation files (the "Software"), to deal
11+
# in the Software without restriction, including without limitation the rights
12+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
# copies of the Software, and to permit persons to whom the Software is
14+
# furnished to do so, subject to the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be included in
17+
# all copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
# SOFTWARE.

0 commit comments

Comments
 (0)