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

Remove unnecessary calls to str.encode() now that the package is Python 3; Fix deprecation warning #1260

Merged
merged 2 commits into from
Nov 22, 2020
Merged
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
6 changes: 3 additions & 3 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 1 addition & 19 deletions fwutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions scripts/decode-syseeprom
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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']))

Expand Down