Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

Fix str conversion in encode_ros_handshake_header#789

Closed
benureau wants to merge 1 commit intoros:kinetic-develfrom
benureau:fixstrconv
Closed

Fix str conversion in encode_ros_handshake_header#789
benureau wants to merge 1 commit intoros:kinetic-develfrom
benureau:fixstrconv

Conversation

@benureau
Copy link
Copy Markdown
Contributor

The previous code was not properly filtering unicode/str
out of the header. Added the corresponding unit test.

The previous code was not properly filtering unicode/str
out of the header. Added the corresponding unit test.
@benureau
Copy link
Copy Markdown
Contributor Author

Was PR #786, before I messed up with git push trying to remove whitespace changes. I opened this new one in its own branch.

@eric-wieser
Copy link
Copy Markdown
Contributor

Darn, that was careless of me

@dirk-thomas
Copy link
Copy Markdown
Member

Thank you for the patch. I have slightly updated it in #792 (while keep the commit in your name) to make it a bit simpler and easier to read.

@eric-wieser
Copy link
Copy Markdown
Contributor

It would make more sense here to define the API (at least for py3) as taking either bytes or str but not both. Which choice makes more sense? Should headers ever contain non-ascii characters?

@dirk-thomas
Copy link
Copy Markdown
Member

I would rather not spend time on revising the specified API. The current code should handle both input well.

@eric-wieser
Copy link
Copy Markdown
Contributor

I'd argue that the API is currently underspecified, especially for python 3. Python 3 makes a big point about enforcing the deliberate use of either str or bytes, and them not being interchangeable. Therefore, a python3 api should be strict about this distinction also.

Having said that, I get the impression that python3 support is not a big item on the roadmap, and so by association nor is being picky about the str/bytes distinction.

@dirk-thomas
Copy link
Copy Markdown
Member

I think it is "good" API even in Python 3 to allow passing in either bytes or str which will then be UTF-8 encoded for the user.

Yes, there is currently no roadmap about Python 3 in ROS 1. We have made a significant push on that topic a year and a half ago. But then it was decided to not spend further resources on it. But any pull request improving Python 3 support (especially since some platforms use it by default) are highly appreciated.

@benureau
Copy link
Copy Markdown
Contributor Author

Having trudged through the installation of MORSE/ROS with python 3 (and on OS X, to make matters worse), I can definitely say that python 3 support is not a big item on the roadmap. But with packages such as the MORSE simulator that only support python 3, it should be. In the meantime, I'll keep posting patches for bugs I encounter and understand.

Thanks for all the attention and reactivity you brought to this PR.

@eric-wieser
Copy link
Copy Markdown
Contributor

ROS 2 is jumping ship to python 3 only, right?

@dirk-thomas
Copy link
Copy Markdown
Member

Yes, ROS 2 is Python 3 only.

@eric-wieser
Copy link
Copy Markdown
Contributor

I think it is "good" API even in Python 3 to allow passing in either bytes or str which will then be UTF-8 encoded for the user.

I don't agree. Python 3 makes a big distinction between these two types

Python 3.0 uses the concepts of text and (binary) data instead of Unicode strings and 8-bit strings. All text is Unicode; however encoded Unicode is represented as binary data. The type used to hold text is str, the type used to hold data is bytes.

Are headers text or data? Should I be able to put a binary string in the header?

  • If they're data, then we have to commit to the api using bytes, otherwise decode_ros_handshake_header will raise a UnicodeDecodeError (this happens currently if you pass binary data in python 3).
  • If they're text, then we should commit to using str, to prevent the user from being able to try to send binary data.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants