From 72292a72ab3a72134405ee21ab4ebd8740250560 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Mon, 11 Dec 2017 15:12:22 +0100 Subject: [PATCH] some simple python syntax fixes --- main.py | 16 ++++++++-------- networkconfig.py | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 6c359ac..d44cb3e 100644 --- a/main.py +++ b/main.py @@ -18,17 +18,17 @@ def do_connect(ntwrk_ssid, netwrk_pass): print('.', end='') if sta_if.isconnected(): print('\nConnected. Network config: ', sta_if.ifconfig()) - return (True) + return True else: print('\nFailed. Not Connected to: ' + ntwrk_ssid) - return (False) + return False def check_connection(): global wlan_sta # First check if there already is any connection: if wlan_sta.isconnected(): - return (True) + return True try: # ESP connecting to WiFi takes time, wait a bit and try again: time.sleep(3) @@ -48,20 +48,20 @@ def check_connection(): if ssid_list[0] in i[0]: print("OK. WiFi found.") if do_connect(ssid_list[0], ssid_list[1]): - return (True) + return True if not wlan_sta.isconnected(): if networkconfig.start(): - return (True) + return True else: - return (True) + return True except OSError: # start web server for connection manager: if networkconfig.start(): - return (True) + return True - return (False) + return False if check_connection(): diff --git a/networkconfig.py b/networkconfig.py index 4b75a33..4e2c90e 100644 --- a/networkconfig.py +++ b/networkconfig.py @@ -27,10 +27,10 @@ def do_connect(ntwrk_ssid, netwrk_pass): print('.', end='') if sta_if.isconnected(): print('\nConnected. Network config: ', sta_if.ifconfig()) - return (True) + return True else: print('\nFailed. Not Connected to: ' + ntwrk_ssid) - return (False) + return False def send_response(client, payload, status_code=200): @@ -85,7 +85,7 @@ def handle_configure(client, request): if match is None: send_response(client, "Parameters not found", status_code=400) - return (False) + return False # version 1.9 compatibility try: ssid = match.group(1).decode("utf-8").replace("%3F", "?").replace("%21", "!") @@ -96,7 +96,7 @@ def handle_configure(client, request): if len(ssid) == 0: send_response(client, "SSID must be provided", status_code=400) - return (False) + return False if do_connect(ssid, password): response_footer = """ @@ -117,7 +117,7 @@ def handle_configure(client, request): fo = open("passwd.dat", "w") fo.write(ssid + ";" + password + "\n") fo.close() - return (True) + return True else: response_footer = """ @@ -129,7 +129,7 @@ def handle_configure(client, request): """ send_response(client, response_footer) - return (False) + return False def handle_not_found(client, url): @@ -170,7 +170,7 @@ def start(port=80): if wlan_sta.isconnected(): client.close - return (True) + return True client, addr = server_socket.accept() client.settimeout(5.0) @@ -179,7 +179,7 @@ def start(port=80): request = b"" try: - while not "\r\n\r\n" in request: + while "\r\n\r\n" not in request: request += client.recv(512) except OSError: pass