Skip to content

Commit 66ff173

Browse files
committedNov 20, 2021
Bugfixes: conversion from Python 2 to 3 was not as easy as expected. Remaining bugs will be fixed as they show up.
1 parent 94e2a66 commit 66ff173

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed
 

‎net

+19-15
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def run(cmd, exit_on_error = False):
194194
stdout = subprocess.PIPE,
195195
stderr = subprocess.PIPE,
196196
shell = True,
197+
text = True,
197198
)
198199
o, e = p.communicate()
199200
status = p.poll()
@@ -268,7 +269,7 @@ def expand(path):
268269

269270
def become_root():
270271
if os.getuid() != 0:
271-
os.execlp('sudo', 'sudo', 'python2', *sys.argv)
272+
os.execlp('sudo', 'sudo', 'python3', *sys.argv)
272273

273274
def write_root_file(path, mode, data):
274275
with open(path, 'w') as fd:
@@ -557,21 +558,24 @@ def read_config(reraise = False):
557558
continue
558559
conn = {}
559560
for key, val in (raw_conn or {}).items():
560-
# Assume UTF-8 encoding
561-
if isinstance(val, str):
562-
val = val.encode('utf8')
561+
# FIXME: the change from Python 2 to 3 may have introduced all sorts
562+
# of encoding errors
563+
564+
# # Assume UTF-8 encoding
565+
# if isinstance(val, str):
566+
# val = val.encode('utf8')
563567
if key == 'wpa':
564568
val = parse_wpa_conf(val)
565569
if key not in KNOWN_KEYS:
566570
die('Unknown key: %s' % key)
567-
if isinstance(val, str):
568-
# The yaml decoder will convert
569-
# non-ascii strings into unicode
570-
# This is not what we want. We want
571-
# e.g. '\xc3' in the yaml file to become b'\xc3',
572-
# not u'\xc3'.
573-
# This is an ugly hack to fix it.
574-
val = val.encode('iso-8859-1')
571+
# if isinstance(val, str):
572+
# # The yaml decoder will convert
573+
# # non-ascii strings into unicode
574+
# # This is not what we want. We want
575+
# # e.g. '\xc3' in the yaml file to become b'\xc3',
576+
# # not u'\xc3'.
577+
# # This is an ugly hack to fix it.
578+
# val = val.encode('iso-8859-1')
575579
conn[key] = val
576580
if name == 'common':
577581
COMMON = conn
@@ -620,7 +624,7 @@ def do_list():
620624
def unescape_c_str(data):
621625
return re.sub(
622626
r'\\x([0-9a-f]{2})',
623-
lambda x: x.group(1).decode('hex'),
627+
lambda x: bytes.fromhex(x.group(1)).decode('latin1'),
624628
data
625629
)
626630

@@ -1224,7 +1228,7 @@ def do_connect(conn, psk=None):
12241228
else:
12251229
ssid = conn
12261230

1227-
wpa['network']['ssid'] = ssid.encode('hex')
1231+
wpa['network']['ssid'] = ssid.encode('latin-1').hex()
12281232
wpa['network'].setdefault('scan_ssid', '0')
12291233
wpa['ctrl_interface'] = '/var/run/wpa_supplicant'
12301234
wpa['ctrl_interface_group'] = '0'
@@ -1298,7 +1302,7 @@ def do_connect(conn, psk=None):
12981302
# If Open WiFi with fallthrough--always use wpa_supplicant
12991303
if not wpa:
13001304
wpa = {'network': {'key_mgmt': 'NONE'}}
1301-
wpa['network']['ssid'] = ssid.encode('hex')
1305+
wpa['network']['ssid'] = ssid.encode('latin1').hex()
13021306
wpa['network'].setdefault('scan_ssid', '0')
13031307
wpa['ctrl_interface'] = '/var/run/wpa_supplicant'
13041308
wpa['ctrl_interface_group'] = '0'

0 commit comments

Comments
 (0)