gen_print.py python3 changes
- Modify use of "long" which is not supported in python3
- Modify use of "unicode" which is not supported in python3
- Use list() on filter() output
- Use items() on dict rather than iteritems()
Change-Id: Ib300dbd78a304a30046a12b0fa2e195a2b6696b1
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/gen_print.py b/lib/gen_print.py
index 9b877dd..70ccb8b 100755
--- a/lib/gen_print.py
+++ b/lib/gen_print.py
@@ -367,7 +367,7 @@
if lvalue_string == composite_line:
# i.e. the regex did not match so there are no lvalues.
lvalue_string = ""
- lvalues_list = filter(None, map(str.strip, lvalue_string.split(",")))
+ lvalues_list = list(filter(None, map(str.strip, lvalue_string.split(","))))
try:
lvalues = collections.OrderedDict()
except AttributeError:
@@ -779,7 +779,16 @@
"""
# Determine the type
- if type(var_value) in (int, long, float, bool, str, unicode) \
+ try:
+ int_types = (int, long)
+ except NameError:
+ int_types = (int,)
+ try:
+ string_types = (str, unicode)
+ except NameError:
+ string_types = (str,)
+ simple_types = int_types + string_types + (float, bool)
+ if type(var_value) in simple_types \
or var_value is None:
# The data type is simple in the sense that it has no subordinate
# parts.
@@ -787,7 +796,7 @@
loc_col1_width = loc_col1_width - loc_col1_indent
# See if the user wants the output in hex format.
if hex:
- if type(var_value) not in (int, long):
+ if type(var_value) not in int_types:
value_format = "%s"
if var_value == "":
var_value = "<blank>"
@@ -843,7 +852,7 @@
except NameError:
pass
if type_is_dict:
- for key, value in var_value.iteritems():
+ for key, value in var_value.items():
if key_list is not None:
key_list_regex = "^" + "|".join(key_list) + "$"
if not re.match(key_list_regex, key):