aboutsummaryrefslogtreecommitdiff
path: root/extmod/webrepl
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-02-27 15:36:53 +1100
committerDamien George <damien.p.george@gmail.com>2020-02-28 10:33:03 +1100
commit69661f3343bedf86e514337cff63d96cc42f8859 (patch)
treeaf5dfb380ffdb75dda84828f63cf9d840d992f0f /extmod/webrepl
parent3f39d18c2b884d32f0443e2e8114ff9d7a14d718 (diff)
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
Diffstat (limited to 'extmod/webrepl')
-rw-r--r--extmod/webrepl/manifest.py2
-rw-r--r--extmod/webrepl/webrepl.py4
-rw-r--r--extmod/webrepl/webrepl_setup.py12
-rw-r--r--extmod/webrepl/websocket_helper.py24
4 files changed, 29 insertions, 13 deletions
diff --git a/extmod/webrepl/manifest.py b/extmod/webrepl/manifest.py
index 0f2b44005..6ce7d8546 100644
--- a/extmod/webrepl/manifest.py
+++ b/extmod/webrepl/manifest.py
@@ -1 +1 @@
-freeze('.', ('webrepl.py', 'webrepl_setup.py', 'websocket_helper.py',))
+freeze(".", ("webrepl.py", "webrepl_setup.py", "websocket_helper.py",))
diff --git a/extmod/webrepl/webrepl.py b/extmod/webrepl/webrepl.py
index 24c63299d..8ddf56143 100644
--- a/extmod/webrepl/webrepl.py
+++ b/extmod/webrepl/webrepl.py
@@ -9,6 +9,7 @@ import _webrepl
listen_s = None
client_s = None
+
def setup_conn(port, accept_handler):
global listen_s
listen_s = socket.socket()
@@ -44,7 +45,7 @@ def accept_conn(listen_sock):
ws = _webrepl._webrepl(ws)
cl.setblocking(False)
# notify REPL on socket incoming data (ESP32/ESP8266-only)
- if hasattr(uos, 'dupterm_notify'):
+ if hasattr(uos, "dupterm_notify"):
cl.setsockopt(socket.SOL_SOCKET, 20, uos.dupterm_notify)
uos.dupterm(ws)
@@ -63,6 +64,7 @@ def start(port=8266, password=None):
if password is None:
try:
import webrepl_cfg
+
_webrepl.password(webrepl_cfg.PASS)
setup_conn(port, accept_conn)
print("Started webrepl in normal mode")
diff --git a/extmod/webrepl/webrepl_setup.py b/extmod/webrepl/webrepl_setup.py
index 129313a21..ffc9c77fc 100644
--- a/extmod/webrepl/webrepl_setup.py
+++ b/extmod/webrepl/webrepl_setup.py
@@ -1,20 +1,24 @@
import sys
-#import uos as os
+
+# import uos as os
import os
import machine
RC = "./boot.py"
CONFIG = "./webrepl_cfg.py"
+
def input_choice(prompt, choices):
while 1:
resp = input(prompt)
if resp in choices:
return resp
+
def getpass(prompt):
return input(prompt)
+
def input_pass():
while 1:
passwd1 = getpass("New password (4-9 chars): ")
@@ -77,7 +81,9 @@ def main():
if resp == "E":
if exists(CONFIG):
- resp2 = input_choice("Would you like to change WebREPL password? (y/n) ", ("y", "n", ""))
+ resp2 = input_choice(
+ "Would you like to change WebREPL password? (y/n) ", ("y", "n", "")
+ )
else:
print("To enable WebREPL, you must set password for it")
resp2 = "y"
@@ -87,7 +93,6 @@ def main():
with open(CONFIG, "w") as f:
f.write("PASS = %r\n" % passwd)
-
if resp not in ("D", "E") or (resp == "D" and not status) or (resp == "E" and status):
print("No further action required")
sys.exit()
@@ -99,4 +104,5 @@ def main():
if resp == "y":
machine.reset()
+
main()
diff --git a/extmod/webrepl/websocket_helper.py b/extmod/webrepl/websocket_helper.py
index 9c06db502..5ca80534e 100644
--- a/extmod/webrepl/websocket_helper.py
+++ b/extmod/webrepl/websocket_helper.py
@@ -1,4 +1,5 @@
import sys
+
try:
import ubinascii as binascii
except:
@@ -10,10 +11,11 @@ except:
DEBUG = 0
+
def server_handshake(sock):
clr = sock.makefile("rwb", 0)
l = clr.readline()
- #sys.stdout.write(repr(l))
+ # sys.stdout.write(repr(l))
webkey = None
@@ -23,11 +25,11 @@ def server_handshake(sock):
raise OSError("EOF in headers")
if l == b"\r\n":
break
- # sys.stdout.write(l)
+ # sys.stdout.write(l)
h, v = [x.strip() for x in l.split(b":", 1)]
if DEBUG:
print((h, v))
- if h == b'Sec-WebSocket-Key':
+ if h == b"Sec-WebSocket-Key":
webkey = v
if not webkey:
@@ -43,11 +45,13 @@ def server_handshake(sock):
if DEBUG:
print("respkey:", respkey)
- sock.send(b"""\
+ sock.send(
+ b"""\
HTTP/1.1 101 Switching Protocols\r
Upgrade: websocket\r
Connection: Upgrade\r
-Sec-WebSocket-Accept: """)
+Sec-WebSocket-Accept: """
+ )
sock.send(respkey)
sock.send("\r\n\r\n")
@@ -57,18 +61,22 @@ Sec-WebSocket-Accept: """)
# servers.
def client_handshake(sock):
cl = sock.makefile("rwb", 0)
- cl.write(b"""\
+ cl.write(
+ b"""\
GET / HTTP/1.1\r
Host: echo.websocket.org\r
Connection: Upgrade\r
Upgrade: websocket\r
Sec-WebSocket-Key: foo\r
\r
-""")
+"""
+ )
l = cl.readline()
-# print(l)
+ # print(l)
while 1:
l = cl.readline()
if l == b"\r\n":
break
+
+
# sys.stdout.write(l)