Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Code to Python 3 #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/pythontest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python Test

on:
push:
branches:
- '**'
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Lint
run: |
pip install pylint
pylint -rn --errors-only ./messaging
- name: Test
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: |
pip install coveralls pytest-cov
pytest --cov=messaging tests/
coveralls
6 changes: 4 additions & 2 deletions README → README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
What is python-messaging?
=========================
# python-messaging

[![Python Test](https://github.com/DomAmato/python-messaging/workflows/Python%20Test/badge.svg)](https://github.com/DomAmato/python-messaging/actions)
[![Coverage Status](https://coveralls.io/repos/github/DomAmato/python-messaging/badge.svg?branch=master)](https://coveralls.io/github/DomAmato/python-messaging?branch=master)

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

Expand Down
12 changes: 6 additions & 6 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
master_doc = 'index'

# General information about the project.
project = u'python-messaging'
copyright = u'2010, Pablo Martí'
project = 'python-messaging'
copyright = '2010, Pablo Martí'

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

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -183,6 +183,6 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'python-messaging', u'python-messaging Documentation',
[u'Pablo Martí'], 1)
('index', 'python-messaging', 'python-messaging Documentation',
['Pablo Martí'], 1)
]
4 changes: 1 addition & 3 deletions doc/modules/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ Functions

.. autofunction:: bytes_to_str

.. autofunction:: to_array

.. autofunction:: to_bytes
.. autofunction:: hex_to_int_array

.. autofunction:: swap

Expand Down
16 changes: 8 additions & 8 deletions doc/tutorial/mms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ for a plain HTTP POST::
data = buf.getvalue()
buf.close()

print "PROXY RESPONSE", data
print("PROXY RESPONSE", data)


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

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


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

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


Obtaining a MMS from a WAP push notification
Expand All @@ -144,7 +144,7 @@ headers::
"0791447758100650400E80885810000000810004016082415464408C0C08049F8E020105040B8423F00106226170706C69636174696F6E2F766E642E7761702E6D6D732D6D65737361676500AF848C82984E4F4B3543694B636F544D595347344D4253774141734B7631344655484141414141414141008D908919802B3434373738353334323734392F545950453D504C4D4E008A808E0274008805810301194083687474703A2F",
"0791447758100650440E8088581000000081000401608241547440440C08049F8E020205040B8423F02F70726F6D6D732F736572766C6574732F4E4F4B3543694B636F544D595347344D4253774141734B763134465548414141414141414100",
]
data = ""
data = b""

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

mms = extract_push_notification(data)
url = mms.headers['Content-Location']
print url
print(url)


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

mms = MMSMessage.from_data(data)
print mms
print(mms)
16 changes: 8 additions & 8 deletions doc/tutorial/sms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ How to encode a single part SMS ready to be sent::
sms = SmsSubmit("+44123231231", "hey how's it going?")
pdu = sms.to_pdu()[0]

print pdu.length, pdu.pdu
print(pdu.length, pdu.pdu)


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

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


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

print pdu.length, pdu.pdu
print(pdu.length, pdu.pdu)


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

print pdu.length, pdu.pdu
print(pdu.length, pdu.pdu)


Setting relative validity::
Expand All @@ -90,7 +90,7 @@ Setting relative validity::
sms.validity = timedelta(hours=5)
pdu = sms.to_pdu()[0]

print pdu.length, pdu.pdu
print(pdu.length, pdu.pdu)


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

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

Apart from the pdu, the :py:meth:`messaging.sms.SmsDeliver.__init__` accepts a
Expand Down Expand Up @@ -135,7 +135,7 @@ registered::
# prompt appears (a more robust implementation
# would wait till the prompt appeared)
ser.write('AT+CMGS=%d\r' % pdu.length)
print ser.readlines()
print(ser.readlines())
# write the PDU and send a Ctrl+z escape
ser.write('%s\x1a' % pdu.pdu)
ser.close()
Expand Down
12 changes: 6 additions & 6 deletions messaging/mms/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"""Iterator with "value preview" capability."""


class PreviewIterator(object):
class PreviewIterator:
"""An ``iter`` wrapper class providing a "previewable" iterator.

This "preview" functionality allows the iterator to return successive
values from its ``iterable`` object, without actually mvoving forward
values from its ``iterable`` object, without actually moving forward
itself. This is very usefuly if the next item(s) in an iterator must
be used for something, after which the iterator should "undo" those
read operations, so that they can be read again by another function.
Expand All @@ -32,15 +32,15 @@ def __init__(self, data):
self._cached_values = []
self._preview_pos = 0

#pylint: disable=non-iterator-returned
def __iter__(self):
return self

def next(self):
def __next__(self):
self.reset_preview()
if len(self._cached_values) > 0:
return self._cached_values.pop(0)
else:
return self._it.next()
return next(self._it)

def preview(self):
"""
Expand All @@ -61,7 +61,7 @@ def preview(self):
if self._preview_pos < len(self._cached_values):
value = self._cached_values[self._preview_pos]
else:
value = self._it.next()
value = next(self._it)
self._cached_values.append(value)

self._preview_pos += 1
Expand Down
4 changes: 2 additions & 2 deletions messaging/mms/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def set_duration(self, duration):
self.duration = duration


class DataPart(object):
class DataPart:
"""
I am a data entry in the MMS body

Expand Down Expand Up @@ -544,7 +544,7 @@ def data(self):
"""A buffer containing the binary data of this part"""
if self._data is not None:
if type(self._data) == array.array:
self._data = self._data.tostring()
self._data = self._data.tobytes()
return self._data

elif self._filename is not None:
Expand Down
Loading