Skip to content

Commit be63918

Browse files
authored
Remove unnecessary calls to str.decode() now that the package is Python 3 (sonic-net#1255)
Now that the package is built as Python 3, all strings are unicode by default and `str.decode()` no longer exists.
1 parent 0d1d6e1 commit be63918

File tree

5 files changed

+7
-12
lines changed

5 files changed

+7
-12
lines changed

scripts/natshow

+1-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ class NatShow(object):
125125
if not nat_str:
126126
return
127127

128-
for s in nat_str:
129-
nat_entry = s.decode()
128+
for nat_entry in nat_str:
130129
nat = json.loads(nat_entry .split(":", 2)[-1])
131130
if not nat:
132131
continue

scripts/route_check.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ def add_prefix_ifnot(ip):
6767

6868

6969
def is_local(ip):
70-
t = ipaddress.ip_address(ip.split("/")[0].decode('utf-8'))
70+
t = ipaddress.ip_address(ip.split("/")[0])
7171
return t.is_link_local
7272

7373

7474
def is_default_route(ip):
75-
t = ipaddress.ip_address(ip.split("/")[0].decode('utf-8'))
75+
t = ipaddress.ip_address(ip.split("/")[0])
7676
return t.is_unspecified and ip.split("/")[1] == "0"
7777

7878

scripts/sonic-kdump-config

+2-6
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,8 @@ def run_command(cmd, use_shell=False):
6565
shcmd = cmd
6666
proc = subprocess.Popen(shcmd, shell=use_shell, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, close_fds=True)
6767
output_stdout, output_stderr = proc.communicate()
68-
list_stdout = []
69-
for l in output_stdout.splitlines():
70-
list_stdout.append(str(l.decode()))
71-
list_stderr = []
72-
for l in output_stderr.splitlines():
73-
list_stderr.append(str(l.decode()))
68+
list_stdout = output_stdout.splitlines()
69+
list_stderr = output_stderr.splitlines()
7470
return (proc.returncode, list_stdout, list_stderr)
7571
except (OSError, ValueError) as e:
7672
print("!Exception [%s] encountered while processing the command : %s" % (str(e), str(cmd)))

show/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run_command(command, display_cmd=False, return_cmd=False):
8282

8383
while True:
8484
if return_cmd:
85-
output = proc.communicate()[0].decode("utf-8")
85+
output = proc.communicate()[0]
8686
return output
8787
output = proc.stdout.readline()
8888
if output == "" and proc.poll() is not None:

utilities_common/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def run_command(command, display_cmd=False, ignore_error=False, return_cmd=False
476476
proc = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE)
477477

478478
if return_cmd:
479-
output = proc.communicate()[0].decode("utf-8")
479+
output = proc.communicate()[0]
480480
return output
481481

482482
if not interactive_mode:

0 commit comments

Comments
 (0)