FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow defining default generator's first sequence by Lynesth · Pull Request #91 · python-smpplib/python-smpplib · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 10 additions & 3 deletions README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,23 @@ t = Thread(target=client.listen)
t.start()
```

The client supports setting a custom generator that produces sequence numbers for the PDU packages. Per default a simple in memory generator is used which in conclusion is reset on (re)instantiation of the client, e.g. by an application restart. If you want to keep the sequence number to be persisted across restarts you can implement your own storage backed generator.
A simple in memory generator that produces sequence numbers for the PDU packages is used, which is reset on (re)instantiation of the client, e.g. by an application restart. It starts by default with sequence number 0x00000001 but you may set the starting sequence yourself by declaring the generator beforehand and passing it to the Client:
```python
import smpplib.client

generator = smpplib.client.SimpleSequenceGenerator(start_sequence=1234)
client = smpplib.client.Client('example.com', SOMEPORTNUMBER, sequence_generator=generator)
...
```

Example:

The client supports setting a custom generator, so if you need more/different features associated with it, you can implement your own:
```python
import smpplib.client

import mymodule

generator = mymodule.PersistentSequenceGenerator()
generator = mymodule.MyAwesomeSequenceGenerator()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please elaborate a little about the interface such a Generator has to have

code-of-kpp Aug 6, 2019
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If you don't have time for this, also please let us know and @eigenein will merge it as is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@podshumok @eigenein Feel free to add this info to the readme if you wish, I don't think I will have time to.

client = smpplib.client.Client('example.com', SOMEPORTNUMBER, sequence_generator=generator)
...
```
15 changes: 13 additions & 2 deletions smpplib/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ class SimpleSequenceGenerator(object):
MIN_SEQUENCE = 0x00000001
MAX_SEQUENCE = 0x7FFFFFFF

def __init__(self):
self._sequence = self.MIN_SEQUENCE
def __init__(self, start_sequence=None):
if start_sequence is not None:
if not isinstance(start_sequence, int):
raise TypeError('start_sequence must be an int, {} provided'.format(
type(start_sequence)
))
if start_sequence < self.MIN_SEQUENCE or start_sequence > self.MAX_SEQUENCE:
raise ValueError('start_sequence must be between {} and {}'.format(
self.MIN_SEQUENCE, self.MAX_SEQUENCE
))
self._sequence = start_sequence
else:
self._sequence = self.MIN_SEQUENCE

@property
def sequence(self):
Expand Down

Back | FazBrowse Home | New Git URL