diff --git a/acl_loader/main.py b/acl_loader/main.py index 667e4497f8f2..cbaea686e82c 100644 --- a/acl_loader/main.py +++ b/acl_loader/main.py @@ -429,14 +429,14 @@ def convert_ip(self, table_name, rule_idx, rule): rule_props["IP_PROTOCOL"] = rule.ip.config.protocol if rule.ip.config.source_ip_address: - source_ip_address = rule.ip.config.source_ip_address.encode("ascii") + source_ip_address = rule.ip.config.source_ip_address if ipaddress.ip_network(source_ip_address).version == 4: rule_props["SRC_IP"] = source_ip_address else: rule_props["SRC_IPV6"] = source_ip_address if rule.ip.config.destination_ip_address: - destination_ip_address = rule.ip.config.destination_ip_address.encode("ascii") + destination_ip_address = rule.ip.config.destination_ip_address if ipaddress.ip_network(destination_ip_address).version == 4: rule_props["DST_IP"] = destination_ip_address else: @@ -550,7 +550,7 @@ def convert_rules(self): :return: """ for acl_set_name in self.yang_acl.acl.acl_sets.acl_set: - table_name = acl_set_name.replace(" ", "_").replace("-", "_").upper().encode('ascii') + table_name = acl_set_name.replace(" ", "_").replace("-", "_").upper() acl_set = self.yang_acl.acl.acl_sets.acl_set[acl_set_name] if not self.is_table_valid(table_name): diff --git a/fwutil/lib.py b/fwutil/lib.py index eecebde11da2..19d613cf77d7 100755 --- a/fwutil/lib.py +++ b/fwutil/lib.py @@ -417,24 +417,6 @@ def __parse_module_section(self, module): self.__module_component_map[key] = OrderedDict() self.__parse_component_section(key, value[self.COMPONENT_KEY], True) - # TODO: This function should not be necessary once we no longer support Python 2 - def __deunicodify_hook(self, pairs): - new_pairs = [ ] - - for key, value in pairs: - try: - key = key.encode(self.UTF8_ENCODING) - except Exception: - pass - - try: - value = value.encode(self.UTF8_ENCODING) - except Exception: - pass - - new_pairs.append((key, value)) - - return OrderedDict(new_pairs) def get_chassis_component_map(self): return self.__chassis_component_map @@ -451,7 +433,7 @@ def parse_platform_components(self, root_path=None): platform_components_path = self.__get_platform_components_path(root_path) with open(platform_components_path) as platform_components: - data = json.load(platform_components, object_pairs_hook=self.__deunicodify_hook) + data = json.load(platform_components) if not self.__is_dict(data): self.__parser_platform_fail("dictionary is expected: key=root") diff --git a/scripts/decode-syseeprom b/scripts/decode-syseeprom index 581edd84477d..ed9fd00f69e0 100755 --- a/scripts/decode-syseeprom +++ b/scripts/decode-syseeprom @@ -6,11 +6,11 @@ # try: import glob - import imp import optparse import os import sys import warnings + from importlib.machinery import SourceFileLoader from sonic_py_common import device_info except ImportError as e: @@ -39,7 +39,7 @@ def main(): # load the target class file and instantiate the object # try: - m = imp.load_source('eeprom','/'.join([platform_path, 'plugins', 'eeprom.py'])) + m = SourceFileLoader('eeprom','/'.join([platform_path, 'plugins', 'eeprom.py'])).load_module() except IOError: raise IOError("cannot load module: " + '/'.join([platform_path, 'plugins', 'eeprom.py']))