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

WIP: Python3 migration #156

Open
wants to merge 1 commit into
base: noetic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cmake/gendeps
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#
# Revision $Id$

from __future__ import print_function


import sys
import inspect
Expand Down
8 changes: 4 additions & 4 deletions scripts/dynparam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python
#! /usr/bin/env python3
#
# Software License Agreement (BSD License)
#
Expand Down Expand Up @@ -33,7 +33,7 @@
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id$
from __future__ import print_function


NAME='dynparam'
import roslib; roslib.load_manifest('dynamic_reconfigure')
Expand Down Expand Up @@ -156,7 +156,7 @@ def do_load():
parser.error("too many arguments")
node, path = args[0], args[1]

f = file(path, 'r')
f = open(path, 'r')
try:
params = {}
for doc in yaml.load_all(f.read()):
Expand Down Expand Up @@ -184,7 +184,7 @@ def do_dump():
connect()
params = get_params(node, timeout=options.timeout)
if params is not None:
f = file(path, 'w')
f = open(path, 'w')
try:
yaml.dump(params, f)
return
Expand Down
2 changes: 1 addition & 1 deletion scripts/reconfigure_gui
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
from __future__ import print_function


if __name__ == '__main__':
print('\033[91m' + "reconfigure_gui has moved!\n" + '\033[0m')
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic_reconfigure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def find_reconfigure_services():


def get_parameter_names(descr):
return descr.defaults.keys()
return list(descr.defaults.keys())
10 changes: 5 additions & 5 deletions src/dynamic_reconfigure/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
example server implementation (L{DynamicReconfigureServer}).
"""

from __future__ import print_function, with_statement


try:
import roslib; roslib.load_manifest('dynamic_reconfigure')
Expand Down Expand Up @@ -203,8 +203,8 @@ def update_configuration(self, changes):
found = True
if not found:
if sys.version_info.major < 3:
if type(value) is unicode:
changes[name] = unicode(value)
if type(value) is str:
changes[name] = str(value)
else:
changes[name] = dest_type(value)
else:
Expand All @@ -213,7 +213,7 @@ def update_configuration(self, changes):
except ValueError as e:
raise DynamicReconfigureParameterException('can\'t set parameter \'%s\' of %s: %s' % (name, str(dest_type), e))

if 'groups' in changes.keys():
if 'groups' in list(changes.keys()):
changes['groups'] = self.update_groups(changes['groups'])

config = encode_config(changes)
Expand All @@ -240,7 +240,7 @@ def update_groups(self, changes):
descr = self.get_group_descriptions()

def update_state(group, description):
for p, g in description['groups'].items():
for p, g in list(description['groups'].items()):
if g['name'] == group:
description['groups'][p]['state'] = changes[group]
else:
Expand Down
22 changes: 11 additions & 11 deletions src/dynamic_reconfigure/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)

def __getstate__(self):
return self.__dict__.items()
return list(self.__dict__.items())

def __setstate__(self, items):
for key, val in items:
Expand All @@ -75,7 +75,7 @@ def copy(self):

def __deepcopy__(self, memo):
c = type(self)({})
for key, value in self.items():
for key, value in list(self.items()):
c[copy.deepcopy(key)] = copy.deepcopy(value)

return c
Expand Down Expand Up @@ -112,23 +112,23 @@ def encode_groups(parent, group):

def encode_config(config, flat=True):
msg = ConfigMsg()
for k, v in config.items():
for k, v in list(config.items()):
## @todo add more checks here?
if type(v) == int:
msg.ints.append(IntParameter(k, v))
elif type(v) == bool:
msg.bools.append(BoolParameter(k, v))
elif type(v) == str:
msg.strs.append(StrParameter(k, v))
elif sys.version_info.major < 3 and isinstance(v, unicode):
elif sys.version_info.major < 3 and isinstance(v, str):
msg.strs.append(StrParameter(k, v))
elif type(v) == float:
msg.doubles.append(DoubleParameter(k, v))
elif type(v) == dict or isinstance(v, Config):
if flat is True:
def flatten(g):
groups = []
for _name, group in g['groups'].items():
for _name, group in list(g['groups'].items()):
groups.extend(flatten(group))
groups.append(GroupState(group['name'], group['state'], group['id'], group['parent']))
return groups
Expand Down Expand Up @@ -277,7 +277,7 @@ def find_state(gr, dr):
def add_params(group, descr):
for param in descr['parameters']:
group['parameters'][param['name']] = d[param['name']]
for _n, g in group['groups'].items():
for _n, g in list(group['groups'].items()):
for dr in descr['groups']:
if dr['name'] == g['name']:
add_params(g, dr)
Expand All @@ -290,7 +290,7 @@ def add_params(group, descr):
def decode_config(msg, description=None):
if sys.version_info.major < 3:
for s in msg.strs:
if not isinstance(s.value, unicode):
if not isinstance(s.value, str):
try:
s.value.decode('ascii')
except UnicodeDecodeError:
Expand All @@ -302,10 +302,10 @@ def decode_config(msg, description=None):

def add_params(group, descr):
for param in descr['parameters']:
if param['name'] in d.keys():
if param['name'] in list(d.keys()):
group[param['name']] = d[param['name']]
for _n, g in group['groups'].items():
for _nr, dr in descr['groups'].items():
for _n, g in list(group['groups'].items()):
for _nr, dr in list(descr['groups'].items()):
if dr['name'] == g['name']:
add_params(g, dr)

Expand All @@ -318,7 +318,7 @@ def extract_params(group):
params = []
params.extend(group['parameters'])
try:
for _n, g in group['groups'].items():
for _n, g in list(group['groups'].items()):
params.extend(extract_params(g))
except AttributeError:
for g in group['groups']:
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic_reconfigure/parameter_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
## @todo
# Need to check types of min max and default
# Need to put sane error on exceptions
from __future__ import print_function


import roslib; roslib.load_manifest("dynamic_reconfigure")
import roslib.packages
Expand Down
4 changes: 2 additions & 2 deletions src/dynamic_reconfigure/parameter_generator_catkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# Need to check types of min max and default
# Need to put sane error on exceptions

from __future__ import print_function


import inspect
import os
Expand Down Expand Up @@ -560,7 +560,7 @@ def write_params(group):

def _rreplace_str_with_val_in_dict(self, orig_dict, old_str, new_val):
# Recursively replace any match of old_str by new_val in a dictionary
for k, v in orig_dict.items():
for k, v in list(orig_dict.items()):
if isinstance(v, dict):
self._rreplace_str_with_val_in_dict(v, old_str, new_val)
elif isinstance(v, list):
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic_reconfigure/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
example server implementation (L{DynamicReconfigureServer}).
"""

from __future__ import with_statement


try:
import roslib; roslib.load_manifest('dynamic_reconfigure')
Expand Down
16 changes: 8 additions & 8 deletions test/simple_python_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def testmultibytestring(self):
self.assertEqual('bar', config['mstr_'])

# Kanji for konnichi wa (hello)
str_ = u"今日は"
str_ = "今日は"

client.update_configuration(
{"mstr_": str_}
Expand All @@ -91,12 +91,12 @@ def testmultibytestring(self):

config = client.get_configuration(timeout=5)

self.assertEqual(u"今日は", config['mstr_'])
self.assertEqual(type(u"今日は"), type(config['mstr_']))
self.assertEqual(u"今日は", rospy.get_param('/ref_server/mstr_'))
self.assertEqual("今日は", config['mstr_'])
self.assertEqual(type("今日は"), type(config['mstr_']))
self.assertEqual("今日は", rospy.get_param('/ref_server/mstr_'))

# Hiragana for konnichi wa (hello)
str_ = u"こんにちは"
str_ = "こんにちは"

client.update_configuration(
{"mstr_": str_}
Expand All @@ -106,9 +106,9 @@ def testmultibytestring(self):

config = client.get_configuration(timeout=5)

self.assertEqual(u"こんにちは", config['mstr_'])
self.assertEqual(type(u"こんにちは"), type(config['mstr_']))
self.assertEqual(u"こんにちは", rospy.get_param('/ref_server/mstr_'))
self.assertEqual("こんにちは", config['mstr_'])
self.assertEqual(type("こんにちは"), type(config['mstr_']))
self.assertEqual("こんにちは", rospy.get_param('/ref_server/mstr_'))


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions test/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function


import roslib; roslib.load_manifest('dynamic_reconfigure')
import rospy
Expand All @@ -54,8 +54,8 @@


def print_config(config):
for k, v in config.items():
print(k, ":", v)
for k, v in list(config.items()):
print((k, ":", v))
print('')


Expand Down Expand Up @@ -105,7 +105,7 @@ def new_config_callback(config):

# You can access constants defined in Test.cfg file in the following way:
import dynamic_reconfigure.cfg.TestConfig as Config
print("Medium is a constant that is set to 1:", Config.Test_Medium)
print(("Medium is a constant that is set to 1:", Config.Test_Medium))

# This is useful for setting enums:
print("Configuration after setting int_enum_ to Medium:")
Expand Down
2 changes: 1 addition & 1 deletion test/testserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#********************************************************************/
from __future__ import print_function


import roslib; roslib.load_manifest('dynamic_reconfigure')
import rospy
Expand Down
2 changes: 1 addition & 1 deletion test/testserver_multiple_ns.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#********************************************************************/
from __future__ import print_function


import roslib; roslib.load_manifest('dynamic_reconfigure')
import rospy
Expand Down