From 1adc83f209f1212fc9ee8f9385b652b7289ab4b0 Mon Sep 17 00:00:00 2001 From: Enam Mijbah Noor Date: Thu, 14 Apr 2022 20:36:13 +0600 Subject: [PATCH 01/14] Added python 3.10 tests to CircleCI --- .circleci/config.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d7d80ca..65a3521 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,7 @@ workflows: version: 2 test: jobs: + - test-3.10 - test-3.9 - test-3.8 - test-3.7 @@ -13,9 +14,9 @@ workflows: - test-pypy3 - test-pypy2 jobs: - test-3.9: &test-template + test-3.10: &test-template docker: - - image: python:3.9 # We run one test in non-alpine environment, just in case + - image: python:3.10 # We run one test in non-alpine environment, just in case working_directory: ~/work steps: - checkout @@ -36,6 +37,10 @@ jobs: command: | . venv/bin/activate pytest -v + test-3.9: + <<: *test-template + docker: + - image: python:3.9-alpine test-3.8: <<: *test-template docker: From 9ca29cfa88bb9fa159b6dc52839ffd5482f8ac0e Mon Sep 17 00:00:00 2001 From: Enam Mijbah Noor Date: Fri, 15 Apr 2022 15:15:18 +0600 Subject: [PATCH 02/14] fix socket recv error being silently ignored --- smpplib/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smpplib/client.py b/smpplib/client.py index bb44b04..5b10fcd 100644 --- a/smpplib/client.py +++ b/smpplib/client.py @@ -256,7 +256,7 @@ def read_pdu(self): except socket.error as e: self.logger.warning(e) raise exceptions.ConnectionError() - if not raw_pdu: + if not raw_pdu_part: raise exceptions.ConnectionError() raw_pdu += raw_pdu_part From b9ec1fc99646e64a15427c5735a42a4ad1415672 Mon Sep 17 00:00:00 2001 From: Enam Mijbah Noor Date: Fri, 15 Apr 2022 21:43:07 +0600 Subject: [PATCH 03/14] refactored Client.read_pdu() read exact number of bytes in separate method (_recv_exact) --- smpplib/client.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/smpplib/client.py b/smpplib/client.py index 5b10fcd..4d0dda5 100644 --- a/smpplib/client.py +++ b/smpplib/client.py @@ -226,20 +226,32 @@ def send_pdu(self, p): return True + def _recv_exact(self, exact_size): + """ + Keep reading from self._socket until exact_size bytes have been read + """ + parts = [] + received = 0 + while received < exact_size: + try: + part = self._socket.recv(exact_size - received) + except socket.timeout: + raise + except socket.error as e: + self.logger.warning(e) + raise exceptions.ConnectionError() + if not part: + raise exceptions.ConnectionError() + received += len(part) + parts.append(part) + return b"".join(parts) + def read_pdu(self): """Read PDU from the SMSC""" self.logger.debug('Waiting for PDU...') - try: - raw_len = self._socket.recv(4) - except socket.timeout: - raise - except socket.error as e: - self.logger.warning(e) - raise exceptions.ConnectionError() - if not raw_len: - raise exceptions.ConnectionError() + raw_len = self._recv_exact(4) try: length = struct.unpack('>L', raw_len)[0] @@ -247,18 +259,7 @@ def read_pdu(self): self.logger.warning('Receive broken pdu... %s', repr(raw_len)) raise exceptions.PDUError('Broken PDU') - raw_pdu = raw_len - while len(raw_pdu) < length: - try: - raw_pdu_part = self._socket.recv(length - len(raw_pdu)) - except socket.timeout: - raise - except socket.error as e: - self.logger.warning(e) - raise exceptions.ConnectionError() - if not raw_pdu_part: - raise exceptions.ConnectionError() - raw_pdu += raw_pdu_part + raw_pdu = raw_len + self._recv_exact(length - 4) self.logger.debug('<<%s (%d bytes)', binascii.b2a_hex(raw_pdu), len(raw_pdu)) From df39439730f533817a090c7bd8345fe3f722fb74 Mon Sep 17 00:00:00 2001 From: Enam Mijbah Noor Date: Fri, 15 Apr 2022 17:24:47 +0600 Subject: [PATCH 04/14] refactored Client.send_pdu() use socket.sendall instead of socket.send in a loop --- smpplib/client.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/smpplib/client.py b/smpplib/client.py index 4d0dda5..ebad492 100644 --- a/smpplib/client.py +++ b/smpplib/client.py @@ -207,22 +207,14 @@ def send_pdu(self, p): )) self.logger.debug('Sending %s PDU', p.command) - generated = p.generate() - self.logger.debug('>>%s (%d bytes)', binascii.b2a_hex(generated), len(generated)) - sent = 0 - - while sent < len(generated): - try: - sent_last = self._socket.send(generated[sent:]) - except socket.error as e: - self.logger.warning(e) - raise exceptions.ConnectionError() - if sent_last == 0: - raise exceptions.ConnectionError() - sent += sent_last + try: + self._socket.sendall(generated) + except socket.error as e: + self.logger.warning(e) + raise exceptions.ConnectionError() return True From ab70a51633db04f57f046ab90af3929577be9230 Mon Sep 17 00:00:00 2001 From: Pavel Perestoronin Date: Thu, 7 Jul 2022 12:56:56 +0200 Subject: [PATCH 05/14] Fix: PyPI URL pointing to the fork #45 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index eb6371f..51f188d 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name='smpplib', version='2.2.1', - url='https://github.com/podshumok/python-smpplib', + url='https://github.com/python-smpplib/python-smpplib', description='SMPP library for python', packages=find_packages(), install_requires=['six'], From df9c9dbdcebc585bbfcc6e960175298730b29955 Mon Sep 17 00:00:00 2001 From: Enam Mijbah Noor Date: Sun, 5 Mar 2023 14:03:18 +0600 Subject: [PATCH 06/14] increment sequence of commands as spec made need_sequence=True for the following commands: - BindTransmitter - BindReceiver - BindTransceiver - Unbind - DeliverySM - EnquireLink --- smpplib/command.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/smpplib/command.py b/smpplib/command.py index b19b0c6..e635fd8 100644 --- a/smpplib/command.py +++ b/smpplib/command.py @@ -410,7 +410,7 @@ class BindTransmitter(Command): ) def __init__(self, command, **kwargs): - super(BindTransmitter, self).__init__(command, need_sequence=False, **kwargs) + super(BindTransmitter, self).__init__(command, need_sequence=True, **kwargs) self._set_vars(**(dict.fromkeys(self.params))) self.interface_version = consts.SMPP_VERSION_34 @@ -817,7 +817,7 @@ class DeliverSM(SubmitSM): ) def __init__(self, command, **kwargs): - super(DeliverSM, self).__init__(command, need_sequence=False, **kwargs) + super(DeliverSM, self).__init__(command, need_sequence=True, **kwargs) self._set_vars(**(dict.fromkeys(self.params))) @@ -900,7 +900,7 @@ class Unbind(Command): params_order = () def __init__(self, command, **kwargs): - super(Unbind, self).__init__(command, need_sequence=False, **kwargs) + super(Unbind, self).__init__(command, need_sequence=True, **kwargs) class UnbindResp(Command): @@ -919,7 +919,7 @@ class EnquireLink(Command): params_order = () def __init__(self, command, **kwargs): - super(EnquireLink, self).__init__(command, need_sequence=False, **kwargs) + super(EnquireLink, self).__init__(command, need_sequence=True, **kwargs) class EnquireLinkResp(Command): From cd555903d0f3360131502cb1092a35e99e796acd Mon Sep 17 00:00:00 2001 From: Enam Mijbah Noor Date: Sun, 5 Mar 2023 14:17:19 +0600 Subject: [PATCH 07/14] fix tests --- smpplib/tests/test_command.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/smpplib/tests/test_command.py b/smpplib/tests/test_command.py index a0e2433..0c47891 100644 --- a/smpplib/tests/test_command.py +++ b/smpplib/tests/test_command.py @@ -1,11 +1,13 @@ from smpplib import consts, exceptions +from smpplib.client import Client from smpplib.command import DeliverSM import pytest def test_parse_deliver_sm(): - pdu = DeliverSM('deliver_sm') + client = Client("localhost", 5679) + pdu = DeliverSM('deliver_sm', client=client) pdu.parse( b"\x00\x00\x00\xcb\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x01\x00" b"\x01\x0131600000000\x00\x05\x00XXX YYYY\x00\x04\x00\x00\x00\x00\x00" @@ -26,7 +28,8 @@ def test_parse_deliver_sm(): def test_unrecognised_optional_parameters(): - pdu = DeliverSM("deliver_sm", allow_unknown_opt_params=True) + client = Client("localhost", 5679) + pdu = DeliverSM("deliver_sm", client=client, allow_unknown_opt_params=True) pdu.parse(b'\x00\x00\x00\xa8\x00\x00\x00\x05\x00\x00\x00\x00/p\xc6' b'\x9a\x00\x00\x0022549909028\x00\x01\x00\x00\x04\x00\x00' b'\x00\x00\x00\x00\x00\x00iid:795920026 sub:001 dlvrd:001 ' @@ -37,7 +40,7 @@ def test_unrecognised_optional_parameters(): # This is only to avoid a breaking change, at some point the other behaviour # should become the default. with pytest.raises(exceptions.UnknownCommandError): - pdu2 = DeliverSM("deliver_sm") + pdu2 = DeliverSM("deliver_sm", client=client) pdu2.parse(b'\x00\x00\x00\xa8\x00\x00\x00\x05\x00\x00\x00\x00/p\xc6' b'\x9a\x00\x00\x0022549909028\x00\x01\x00\x00\x04\x00\x00' b'\x00\x00\x00\x00\x00\x00iid:795920026 sub:001 dlvrd:001 ' From 4ddadc72901ea96295ac0dfe89b0a4b95d7cd026 Mon Sep 17 00:00:00 2001 From: Enam Mijbah Noor Date: Sun, 5 Mar 2023 17:24:37 +0600 Subject: [PATCH 08/14] remove redundant arguments --- smpplib/command.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/smpplib/command.py b/smpplib/command.py index e635fd8..bde5840 100644 --- a/smpplib/command.py +++ b/smpplib/command.py @@ -410,7 +410,7 @@ class BindTransmitter(Command): ) def __init__(self, command, **kwargs): - super(BindTransmitter, self).__init__(command, need_sequence=True, **kwargs) + super(BindTransmitter, self).__init__(command, **kwargs) self._set_vars(**(dict.fromkeys(self.params))) self.interface_version = consts.SMPP_VERSION_34 @@ -817,7 +817,7 @@ class DeliverSM(SubmitSM): ) def __init__(self, command, **kwargs): - super(DeliverSM, self).__init__(command, need_sequence=True, **kwargs) + super(DeliverSM, self).__init__(command, **kwargs) self._set_vars(**(dict.fromkeys(self.params))) @@ -900,7 +900,7 @@ class Unbind(Command): params_order = () def __init__(self, command, **kwargs): - super(Unbind, self).__init__(command, need_sequence=True, **kwargs) + super(Unbind, self).__init__(command, **kwargs) class UnbindResp(Command): @@ -919,7 +919,7 @@ class EnquireLink(Command): params_order = () def __init__(self, command, **kwargs): - super(EnquireLink, self).__init__(command, need_sequence=True, **kwargs) + super(EnquireLink, self).__init__(command, **kwargs) class EnquireLinkResp(Command): From 388bb28fc5f8acded4561516b2e2463534d5fec7 Mon Sep 17 00:00:00 2001 From: Pavel Perestoronin Date: Mon, 24 Apr 2023 18:51:12 +0200 Subject: [PATCH 09/14] Fix: correct UCS2 part length following #184, fixes #216 --- smpplib/consts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smpplib/consts.py b/smpplib/consts.py index 2987354..8218d93 100644 --- a/smpplib/consts.py +++ b/smpplib/consts.py @@ -6,7 +6,7 @@ # SMPP 3.4, 2.2.1.2 SEVENBIT_LENGTH = 160 EIGHTBIT_LENGTH = 140 -UCS2_LENGTH = 70 +UCS2_LENGTH = 140 MULTIPART_HEADER_SIZE = 6 From 97ec04cd3e188e757717141018d428c346d86795 Mon Sep 17 00:00:00 2001 From: Pavel Perestoronin Date: Mon, 24 Apr 2023 18:53:25 +0200 Subject: [PATCH 10/14] Cut `2.2.3` --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 51f188d..36420e9 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='smpplib', - version='2.2.1', + version='2.2.3', url='https://github.com/python-smpplib/python-smpplib', description='SMPP library for python', packages=find_packages(), From 196c799db364195d472308e60310fbd4b4bf926d Mon Sep 17 00:00:00 2001 From: Pavel Perestoronin Date: Tue, 25 Apr 2023 16:41:19 +0200 Subject: [PATCH 11/14] Opt: add `CODEOWNERS` --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..8fb6a51 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @eigenein @code-of-kpp From e037bfebf091415c88983bf54a395d56f82e230f Mon Sep 17 00:00:00 2001 From: Pavel Perestoronin Date: Tue, 6 Jun 2023 16:26:58 +0200 Subject: [PATCH 12/14] Opt: create `FUNDING.yml` --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..7dd9a76 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: ["code-of-kpp", "eigenein"] From 57ad3ae9b8fbda21540a2b5eacf290f95c22b9cc Mon Sep 17 00:00:00 2001 From: Krasimir Mikov <91935581+kmikov@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:15:27 +0200 Subject: [PATCH 13/14] Do not create socket on __init__ I don't think it is ok to create the socket outside of connect() when the only way to close it is in disconnect(). It leads to unnecessary warnings on object destruction. --- smpplib/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smpplib/client.py b/smpplib/client.py index ebad492..a335d15 100644 --- a/smpplib/client.py +++ b/smpplib/client.py @@ -92,7 +92,7 @@ def __init__( self.allow_unknown_opt_params = allow_unknown_opt_params - self._socket = self._create_socket() + self._socket = None def __enter__(self): return self From 1add0a017b112f166b8906e83692e6d24a75f9fc Mon Sep 17 00:00:00 2001 From: Konstantin <314085+code-of-kpp@users.noreply.github.com> Date: Fri, 17 Jan 2025 03:35:25 +0100 Subject: [PATCH 14/14] Add SSH client to the CI --- .circleci/config.yml | 44 ++++++++++++++++++++------------------------ setup.py | 11 ++++++----- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 65a3521..eca5107 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,22 +3,26 @@ workflows: version: 2 test: jobs: + - test-3.13 + - test-3.12 + - test-3.11 - test-3.10 - test-3.9 - - test-3.8 - - test-3.7 - - test-3.6 - - test-3.5 - - test-3.4 - test-2.7 - test-pypy3 - test-pypy2 jobs: - test-3.10: &test-template + test-3.13: &test-template docker: - - image: python:3.10 # We run one test in non-alpine environment, just in case + - image: python:3.13 # We run one test in non-alpine environment, just in case working_directory: ~/work steps: + - run: + name: Ensure SSH + command: | + apk add --update openssh-client git || { + apt-get update && apt-get install -y openssh-client git + } - checkout - run: name: Install dependencies @@ -31,36 +35,28 @@ jobs: name: Install project command: | . venv/bin/activate - pip install -e .[tests] + pip install -e '.[tests]' - run: name: Run tests command: | . venv/bin/activate pytest -v - test-3.9: + test-3.12: <<: *test-template docker: - - image: python:3.9-alpine - test-3.8: + - image: python:3.12-alpine + test-3.11: <<: *test-template docker: - - image: python:3.8-alpine - test-3.7: + - image: python:3.11-alpine + test-3.10: <<: *test-template docker: - - image: python:3.7-alpine - test-3.6: - <<: *test-template - docker: - - image: python:3.6-alpine - test-3.5: - <<: *test-template - docker: - - image: python:3.5-alpine - test-3.4: + - image: python:3.10-alpine + test-3.9: <<: *test-template docker: - - image: python:3.4-alpine + - image: python:3.9-alpine test-2.7: <<: *test-template docker: diff --git a/setup.py b/setup.py index 36420e9..b12fc31 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='smpplib', - version='2.2.3', + version='2.2.4', url='https://github.com/python-smpplib/python-smpplib', description='SMPP library for python', packages=find_packages(), @@ -29,10 +29,11 @@ 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', 'Programming Language :: Python', 'Topic :: Communications :: Telephony', 'Topic :: Communications',