@@ -194,6 +194,7 @@ def run(cmd, exit_on_error = False):
194
194
stdout = subprocess .PIPE ,
195
195
stderr = subprocess .PIPE ,
196
196
shell = True ,
197
+ text = True ,
197
198
)
198
199
o , e = p .communicate ()
199
200
status = p .poll ()
@@ -268,7 +269,7 @@ def expand(path):
268
269
269
270
def become_root ():
270
271
if os .getuid () != 0 :
271
- os .execlp ('sudo' , 'sudo' , 'python2 ' , * sys .argv )
272
+ os .execlp ('sudo' , 'sudo' , 'python3 ' , * sys .argv )
272
273
273
274
def write_root_file (path , mode , data ):
274
275
with open (path , 'w' ) as fd :
@@ -557,21 +558,24 @@ def read_config(reraise = False):
557
558
continue
558
559
conn = {}
559
560
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')
563
567
if key == 'wpa' :
564
568
val = parse_wpa_conf (val )
565
569
if key not in KNOWN_KEYS :
566
570
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')
575
579
conn [key ] = val
576
580
if name == 'common' :
577
581
COMMON = conn
@@ -620,7 +624,7 @@ def do_list():
620
624
def unescape_c_str (data ):
621
625
return re .sub (
622
626
r'\\x([0-9a-f]{2})' ,
623
- lambda x : x .group (1 ).decode ('hex ' ),
627
+ lambda x : bytes . fromhex ( x .group (1 )) .decode ('latin1 ' ),
624
628
data
625
629
)
626
630
@@ -1224,7 +1228,7 @@ def do_connect(conn, psk=None):
1224
1228
else :
1225
1229
ssid = conn
1226
1230
1227
- wpa ['network' ]['ssid' ] = ssid .encode ('hex' )
1231
+ wpa ['network' ]['ssid' ] = ssid .encode ('latin-1' ). hex ( )
1228
1232
wpa ['network' ].setdefault ('scan_ssid' , '0' )
1229
1233
wpa ['ctrl_interface' ] = '/var/run/wpa_supplicant'
1230
1234
wpa ['ctrl_interface_group' ] = '0'
@@ -1298,7 +1302,7 @@ def do_connect(conn, psk=None):
1298
1302
# If Open WiFi with fallthrough--always use wpa_supplicant
1299
1303
if not wpa :
1300
1304
wpa = {'network' : {'key_mgmt' : 'NONE' }}
1301
- wpa ['network' ]['ssid' ] = ssid .encode ('hex' )
1305
+ wpa ['network' ]['ssid' ] = ssid .encode ('latin1' ). hex ( )
1302
1306
wpa ['network' ].setdefault ('scan_ssid' , '0' )
1303
1307
wpa ['ctrl_interface' ] = '/var/run/wpa_supplicant'
1304
1308
wpa ['ctrl_interface_group' ] = '0'
0 commit comments