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

rosnode: Minor fixes for compatibility with both Python 2 & 3 #1166

Merged
merged 1 commit into from
Sep 15, 2017
Merged
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
3 changes: 1 addition & 2 deletions tools/rosnode/src/rosnode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def get_nodes_by_machine(machine):
@raise ROSNodeException: if machine name cannot be resolved to an address
@raise ROSNodeIOException: if unable to communicate with master
"""
import urlparse
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already imported at the top of the file so no need to import here. Moreover there is no urlparse module in Python 3.


master = rosgraph.Master(ID)
try:
Expand Down Expand Up @@ -338,7 +337,7 @@ def rosnode_ping(node_name, max_count=None, verbose=False):
# 3786: catch ValueError on unpack as socket.error is not always a tuple
try:
# #3659
errnum, msg = e
errnum, msg = e.args
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This way allows it to work for both Python 2 & 3. socket.error is just an alias of OSError in Python 3.

if errnum == -2: #name/service unknown
p = urlparse.urlparse(node_api)
print("ERROR: Unknown host [%s] for node [%s]"%(p.hostname, node_name), file=sys.stderr)
Expand Down