Skip to content

Commit 32da7ad

Browse files
committed
Python3 (#1)
1 parent 8c62c14 commit 32da7ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+946
-824
lines changed

.github/workflows/pythontest.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python Test
5+
6+
on:
7+
push:
8+
branches:
9+
- '**'
10+
pull_request:
11+
branches: [ master ]
12+
13+
jobs:
14+
build:
15+
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
python-version: [3.5, 3.6, 3.7, 3.8]
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v1
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
- name: Lint
31+
run: |
32+
pip install pylint
33+
pylint -rn --errors-only ./messaging
34+
- name: Test
35+
env:
36+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
37+
run: |
38+
pip install coveralls pytest-cov
39+
pytest --cov=messaging tests/
40+
coveralls

README renamed to README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
What is python-messaging?
2-
=========================
1+
# python-messaging
2+
3+
[![Python Test](https://github.com/DomAmato/python-messaging/workflows/Python%20Test/badge.svg)](https://github.com/DomAmato/python-messaging/actions)
4+
[![Coverage Status](https://coveralls.io/repos/github/DomAmato/python-messaging/badge.svg?branch=master)](https://coveralls.io/github/DomAmato/python-messaging?branch=master)
35

46
A SMS/MMS encoder/decoder written 100% in Python.
57

doc/conf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
master_doc = 'index'
2121

2222
# General information about the project.
23-
project = u'python-messaging'
24-
copyright = u'2010, Pablo Martí'
23+
project = 'python-messaging'
24+
copyright = '2010, Pablo Martí'
2525

2626
# The short X.Y version.
2727
version = '0.5.9'
@@ -150,8 +150,8 @@
150150
# Grouping the document tree into LaTeX files. List of tuples
151151
# (source start file, target name, title, author, documentclass [howto/manual]).
152152
latex_documents = [
153-
('index', 'python-messaging.tex', u'python-messaging Documentation',
154-
u'Pablo Martí', 'manual'),
153+
('index', 'python-messaging.tex', 'python-messaging Documentation',
154+
'Pablo Martí', 'manual'),
155155
]
156156

157157
# The name of an image file (relative to this directory) to place at the top of
@@ -183,6 +183,6 @@
183183
# One entry per manual page. List of tuples
184184
# (source start file, name, description, authors, manual section).
185185
man_pages = [
186-
('index', 'python-messaging', u'python-messaging Documentation',
187-
[u'Pablo Martí'], 1)
186+
('index', 'python-messaging', 'python-messaging Documentation',
187+
['Pablo Martí'], 1)
188188
]

doc/modules/utils.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ Functions
1515

1616
.. autofunction:: bytes_to_str
1717

18-
.. autofunction:: to_array
19-
20-
.. autofunction:: to_bytes
18+
.. autofunction:: hex_to_int_array
2119

2220
.. autofunction:: swap
2321

doc/tutorial/mms.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ for a plain HTTP POST::
7575
data = buf.getvalue()
7676
buf.close()
7777

78-
print "PROXY RESPONSE", data
78+
print("PROXY RESPONSE", data)
7979

8080

8181
Encoding a m-notifyresp-ind PDU
@@ -110,8 +110,8 @@ MMS, you just need to::
110110
# data is an array.array("B") instance
111111
mms = MMSMessage.from_data(data)
112112

113-
print mms.headers['Message-Type'] # m-send-req
114-
print mms.headers['To'] # '+34231342234/TYPE=PLMN'
113+
print(mms.headers['Message-Type'] # m-send-req)
114+
print(mms.headers['To'] # '+34231342234/TYPE=PLMN')
115115

116116

117117
Decoding from a file
@@ -125,8 +125,8 @@ need the path to the file and::
125125
path = '/tmp/binary-mms.bin'
126126
mms = MMSMessage.from_file(path)
127127

128-
print mms.headers['Message-Type'] # m-send-req
129-
print mms.headers['To'] # '+34231342234/TYPE=PLMN'
128+
print(mms.headers['Message-Type'] # m-send-req)
129+
print(mms.headers['To'] # '+34231342234/TYPE=PLMN')
130130

131131

132132
Obtaining a MMS from a WAP push notification
@@ -144,7 +144,7 @@ headers::
144144
"0791447758100650400E80885810000000810004016082415464408C0C08049F8E020105040B8423F00106226170706C69636174696F6E2F766E642E7761702E6D6D732D6D65737361676500AF848C82984E4F4B3543694B636F544D595347344D4253774141734B7631344655484141414141414141008D908919802B3434373738353334323734392F545950453D504C4D4E008A808E0274008805810301194083687474703A2F",
145145
"0791447758100650440E8088581000000081000401608241547440440C08049F8E020205040B8423F02F70726F6D6D732F736572766C6574732F4E4F4B3543694B636F544D595347344D4253774141734B763134465548414141414141414100",
146146
]
147-
data = ""
147+
data = b""
148148

149149
sms = SmsDeliver(pdus[0])
150150
data += sms.text
@@ -154,7 +154,7 @@ headers::
154154

155155
mms = extract_push_notification(data)
156156
url = mms.headers['Content-Location']
157-
print url
157+
print(url)
158158

159159

160160
Once you have the content location, you need to do a HTTP GET to retrieve
@@ -184,4 +184,4 @@ the MMS payload::
184184
buf.close()
185185

186186
mms = MMSMessage.from_data(data)
187-
print mms
187+
print(mms)

doc/tutorial/sms.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ How to encode a single part SMS ready to be sent::
3636
sms = SmsSubmit("+44123231231", "hey how's it going?")
3737
pdu = sms.to_pdu()[0]
3838

39-
print pdu.length, pdu.pdu
39+
print(pdu.length, pdu.pdu)
4040

4141

4242
How to encode a concatenated SMS ready to be sent::
@@ -45,7 +45,7 @@ How to encode a concatenated SMS ready to be sent::
4545

4646
sms = SmsSubmit("+44123231231", "hey " * 50)
4747
for pdu in sms.to_pdu():
48-
print pdu.length, pdu.pdu
48+
print(pdu.length, pdu.pdu)
4949

5050

5151
Setting class
@@ -59,7 +59,7 @@ Setting the SMS class (0-3) is a no brainer::
5959
sms.class = 0
6060
pdu = sms.to_pdu()[0]
6161

62-
print pdu.length, pdu.pdu
62+
print(pdu.length, pdu.pdu)
6363

6464

6565
Setting validity
@@ -78,7 +78,7 @@ Setting absolute validity::
7878
sms.validity = datetime(2010, 12, 31, 23, 59, 59)
7979
pdu = sms.to_pdu()[0]
8080

81-
print pdu.length, pdu.pdu
81+
print(pdu.length, pdu.pdu)
8282

8383

8484
Setting relative validity::
@@ -90,7 +90,7 @@ Setting relative validity::
9090
sms.validity = timedelta(hours=5)
9191
pdu = sms.to_pdu()[0]
9292

93-
print pdu.length, pdu.pdu
93+
print(pdu.length, pdu.pdu)
9494

9595

9696
Decoding
@@ -103,10 +103,10 @@ term:`PDU` decoding is really simple with :class:`~messaging.sms.SmsDeliver`::
103103
pdu = "0791447758100650040C914497726247010000909010711423400A2050EC468B81C4733A"
104104
sms = SmsDeliver(pdu)
105105

106-
print sms.data
106+
print(sms.data)
107107
# {'csca': '+447785016005', 'type': None,
108108
# 'date': datetime.datetime(2009, 9, 1, 16, 41, 32),
109-
# 'text': u' 1741 bst', 'fmt': 0, 'pid': 0,
109+
# 'text': ' 1741 bst', 'fmt': 0, 'pid': 0,
110110
# 'dcs': 0, 'number': '+447927267410'}
111111

112112
Apart from the pdu, the :py:meth:`messaging.sms.SmsDeliver.__init__` accepts a
@@ -135,7 +135,7 @@ registered::
135135
# prompt appears (a more robust implementation
136136
# would wait till the prompt appeared)
137137
ser.write('AT+CMGS=%d\r' % pdu.length)
138-
print ser.readlines()
138+
print(ser.readlines())
139139
# write the PDU and send a Ctrl+z escape
140140
ser.write('%s\x1a' % pdu.pdu)
141141
ser.close()

messaging/mms/iterator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"""Iterator with "value preview" capability."""
1616

1717

18-
class PreviewIterator(object):
18+
class PreviewIterator:
1919
"""An ``iter`` wrapper class providing a "previewable" iterator.
2020
2121
This "preview" functionality allows the iterator to return successive
22-
values from its ``iterable`` object, without actually mvoving forward
22+
values from its ``iterable`` object, without actually moving forward
2323
itself. This is very usefuly if the next item(s) in an iterator must
2424
be used for something, after which the iterator should "undo" those
2525
read operations, so that they can be read again by another function.
@@ -32,15 +32,15 @@ def __init__(self, data):
3232
self._cached_values = []
3333
self._preview_pos = 0
3434

35+
#pylint: disable=non-iterator-returned
3536
def __iter__(self):
3637
return self
3738

38-
def next(self):
39+
def __next__(self):
3940
self.reset_preview()
4041
if len(self._cached_values) > 0:
4142
return self._cached_values.pop(0)
42-
else:
43-
return self._it.next()
43+
return next(self._it)
4444

4545
def preview(self):
4646
"""
@@ -61,7 +61,7 @@ def preview(self):
6161
if self._preview_pos < len(self._cached_values):
6262
value = self._cached_values[self._preview_pos]
6363
else:
64-
value = self._it.next()
64+
value = next(self._it)
6565
self._cached_values.append(value)
6666

6767
self._preview_pos += 1

messaging/mms/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def set_duration(self, duration):
430430
self.duration = duration
431431

432432

433-
class DataPart(object):
433+
class DataPart:
434434
"""
435435
I am a data entry in the MMS body
436436
@@ -544,7 +544,7 @@ def data(self):
544544
"""A buffer containing the binary data of this part"""
545545
if self._data is not None:
546546
if type(self._data) == array.array:
547-
self._data = self._data.tostring()
547+
self._data = self._data.tobytes()
548548
return self._data
549549

550550
elif self._filename is not None:

0 commit comments

Comments
 (0)