extmod/webrepl: Fix setting password in foreground mode and factor code.

The password was not being set when running in foreground mode.  Duplicate
code has been removed.
pull/8695/head
iabdalkader 2022-05-14 15:00:20 +02:00 zatwierdzone przez Damien George
rodzic 5fa8ea1b8b
commit 6b6ceafe1a
1 zmienionych plików z 15 dodań i 11 usunięć

Wyświetl plik

@ -59,24 +59,28 @@ def stop():
listen_s.close() listen_s.close()
def start(port=8266, password=None): def start(port=8266, password=None, accept_handler=accept_conn):
stop() stop()
if password is None: webrepl_pass = password
if webrepl_pass is None:
try: try:
import webrepl_cfg import webrepl_cfg
_webrepl.password(webrepl_cfg.PASS) webrepl_pass = webrepl_cfg.PASS
setup_conn(port, accept_conn)
print("Started webrepl in normal mode")
except: except:
print("WebREPL is not configured, run 'import webrepl_setup'") print("WebREPL is not configured, run 'import webrepl_setup'")
_webrepl.password(webrepl_pass)
s = setup_conn(port, accept_handler)
if accept_handler is None:
print("Starting webrepl in foreground mode")
accept_conn(s)
elif password is None:
print("Started webrepl in normal mode")
else: else:
_webrepl.password(password)
setup_conn(port, accept_conn)
print("Started webrepl in manual override mode") print("Started webrepl in manual override mode")
def start_foreground(port=8266): def start_foreground(port=8266, password=None):
stop() start(port, password, None)
s = setup_conn(port, None)
accept_conn(s)