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

Fixing pdu.generate() encoding by vazir · Pull Request #132 · python-smpplib/python-smpplib · GitHub

Fixing pdu.generate() encoding - #132

Open
vazir wants to merge 2 commits into
python-smpplib:masterfrom
vazir:master
Open

Fixing pdu.generate() encoding#132
vazir wants to merge 2 commits into
python-smpplib:masterfrom
vazir:master

Conversation

vazir commented Feb 1, 2021

Copy link
Copy Markdown

pdu.generate()
will lead to the following exception, so this is the proposed fix for it.

      File "/opt/smpp_proxy_server/smpplib/pdu.py", line 136, in generate
        body = self.generate_params()
      File "/opt/smpp_proxy_server/smpplib/command.py", line 144, in generate_params
        value = self._generate_string(field)
      File "/opt/smpp_proxy_server/smpplib/command.py", line 180, in _generate_string
        value = field_value + chr(0)
    TypeError: can't concat str to bytes

Copy link
Copy Markdown
Member

I think, all chr calls should be replaced with six.b(chr(...)), all isinstance checks are redundant.

Good catch anyway! Perhaps add a test for that?

Comment thread smpplib/command.py Outdated
value = chr(0).encode()

setattr(self, field, field_value)
if isinstance(value, bytes):

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
Suggested change
if isinstance(value, bytes):
if isinstance(value, six.binary_type):

hm, this check is required though

Copy link
Copy Markdown
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

Probably right :) You are trying to keep compatibility with 2.7

vazir Feb 2, 2021
edited
Loading

Copy link
Copy Markdown
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

for the test that was happening for me for every received pdu, as I was testing the generated PDU equals to the received.

pdu = parse_pdu(raw_pdu, client=self)
gen_bin = pdu.generate()

And so, the exception occurs. Seems nobody had long not using that part, as I was fixing that over a year ago for myself and realized the bug is still there just yesterday after checking in a new version :)

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

can you please add a new function or a new file with a new function to the tests/ directory?

Co-authored-by: Konstantin <kpp.live+github@gmail.com>

code-of-kpp left a comment

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

It also worth looking on line 174 and in general, why field_value is ever not bytes. Looks like the bug is actually happens because self contains a string in the field-attribute, while it should have bytes

Comment thread smpplib/command.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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL