extmod/moduwebsocket: Refactor `websocket` to `uwebsocket`.

As mentioned in #4450, `websocket` was experimental with a single intended
user, `webrepl`. Therefore, we'll make this change without a weak
link `websocket` -> `uwebsocket`.
pull/4570/head^2
Yonatan Goldschmidt 2019-02-10 22:35:18 +02:00 zatwierdzone przez Damien George
rodzic d1acca3c71
commit bc4f8b438b
13 zmienionych plików z 36 dodań i 36 usunięć

Wyświetl plik

@ -30,9 +30,9 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/stream.h" #include "py/stream.h"
#include "extmod/modwebsocket.h" #include "extmod/moduwebsocket.h"
#if MICROPY_PY_WEBSOCKET #if MICROPY_PY_UWEBSOCKET
enum { FRAME_HEADER, FRAME_OPT, PAYLOAD, CONTROL }; enum { FRAME_HEADER, FRAME_OPT, PAYLOAD, CONTROL };
@ -299,16 +299,16 @@ STATIC const mp_obj_type_t websocket_type = {
.locals_dict = (void*)&websocket_locals_dict, .locals_dict = (void*)&websocket_locals_dict,
}; };
STATIC const mp_rom_map_elem_t websocket_module_globals_table[] = { STATIC const mp_rom_map_elem_t uwebsocket_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_websocket) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uwebsocket) },
{ MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&websocket_type) }, { MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&websocket_type) },
}; };
STATIC MP_DEFINE_CONST_DICT(websocket_module_globals, websocket_module_globals_table); STATIC MP_DEFINE_CONST_DICT(uwebsocket_module_globals, uwebsocket_module_globals_table);
const mp_obj_module_t mp_module_websocket = { const mp_obj_module_t mp_module_uwebsocket = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&websocket_module_globals, .globals = (mp_obj_dict_t*)&uwebsocket_module_globals,
}; };
#endif // MICROPY_PY_WEBSOCKET #endif // MICROPY_PY_UWEBSOCKET

Wyświetl plik

@ -0,0 +1,10 @@
#ifndef MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H
#define MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H
#define FRAME_OPCODE_MASK 0x0f
enum {
FRAME_CONT, FRAME_TXT, FRAME_BIN,
FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG
};
#endif // MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H

Wyświetl plik

@ -34,7 +34,7 @@
#ifdef MICROPY_PY_WEBREPL_DELAY #ifdef MICROPY_PY_WEBREPL_DELAY
#include "py/mphal.h" #include "py/mphal.h"
#endif #endif
#include "extmod/modwebsocket.h" #include "extmod/moduwebsocket.h"
#if MICROPY_PY_WEBREPL #if MICROPY_PY_WEBREPL

Wyświetl plik

@ -1,10 +0,0 @@
#ifndef MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
#define MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
#define FRAME_OPCODE_MASK 0x0f
enum {
FRAME_CONT, FRAME_TXT, FRAME_BIN,
FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG
};
#endif // MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H

Wyświetl plik

@ -146,7 +146,7 @@
#define MICROPY_PY_USSL (1) #define MICROPY_PY_USSL (1)
#define MICROPY_SSL_MBEDTLS (1) #define MICROPY_SSL_MBEDTLS (1)
#define MICROPY_PY_USSL_FINALISER (1) #define MICROPY_PY_USSL_FINALISER (1)
#define MICROPY_PY_WEBSOCKET (1) #define MICROPY_PY_UWEBSOCKET (1)
#define MICROPY_PY_WEBREPL (1) #define MICROPY_PY_WEBREPL (1)
#define MICROPY_PY_FRAMEBUF (1) #define MICROPY_PY_FRAMEBUF (1)
#define MICROPY_PY_USOCKET_EVENTS (MICROPY_PY_WEBREPL) #define MICROPY_PY_USOCKET_EVENTS (MICROPY_PY_WEBREPL)

Wyświetl plik

@ -2,7 +2,7 @@
import socket import socket
import uos import uos
import network import network
import websocket import uwebsocket
import websocket_helper import websocket_helper
import _webrepl import _webrepl
@ -40,7 +40,7 @@ def accept_conn(listen_sock):
print("\nWebREPL connection from:", remote_addr) print("\nWebREPL connection from:", remote_addr)
client_s = cl client_s = cl
websocket_helper.server_handshake(cl) websocket_helper.server_handshake(cl)
ws = websocket.websocket(cl, True) ws = uwebsocket.websocket(cl, True)
ws = _webrepl._webrepl(ws) ws = _webrepl._webrepl(ws)
cl.setblocking(False) cl.setblocking(False)
# notify REPL on socket incoming data # notify REPL on socket incoming data

Wyświetl plik

@ -87,7 +87,7 @@
#define MICROPY_PY_MACHINE_I2C (1) #define MICROPY_PY_MACHINE_I2C (1)
#define MICROPY_PY_MACHINE_SPI (1) #define MICROPY_PY_MACHINE_SPI (1)
#define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hspi_make_new #define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hspi_make_new
#define MICROPY_PY_WEBSOCKET (1) #define MICROPY_PY_UWEBSOCKET (1)
#define MICROPY_PY_WEBREPL (1) #define MICROPY_PY_WEBREPL (1)
#define MICROPY_PY_WEBREPL_DELAY (20) #define MICROPY_PY_WEBREPL_DELAY (20)
#define MICROPY_PY_FRAMEBUF (1) #define MICROPY_PY_FRAMEBUF (1)

Wyświetl plik

@ -136,7 +136,7 @@
#ifndef MICROPY_PY_USELECT_POSIX #ifndef MICROPY_PY_USELECT_POSIX
#define MICROPY_PY_USELECT_POSIX (1) #define MICROPY_PY_USELECT_POSIX (1)
#endif #endif
#define MICROPY_PY_WEBSOCKET (1) #define MICROPY_PY_UWEBSOCKET (1)
#define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_PY_MACHINE_PULSE (1)
#define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr #define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr

Wyświetl plik

@ -118,7 +118,7 @@ extern const mp_obj_module_t mp_module_ussl;
extern const mp_obj_module_t mp_module_utimeq; extern const mp_obj_module_t mp_module_utimeq;
extern const mp_obj_module_t mp_module_machine; extern const mp_obj_module_t mp_module_machine;
extern const mp_obj_module_t mp_module_lwip; extern const mp_obj_module_t mp_module_lwip;
extern const mp_obj_module_t mp_module_websocket; extern const mp_obj_module_t mp_module_uwebsocket;
extern const mp_obj_module_t mp_module_webrepl; extern const mp_obj_module_t mp_module_webrepl;
extern const mp_obj_module_t mp_module_framebuf; extern const mp_obj_module_t mp_module_framebuf;
extern const mp_obj_module_t mp_module_btree; extern const mp_obj_module_t mp_module_btree;

Wyświetl plik

@ -1316,8 +1316,8 @@ typedef double mp_float_t;
#define MICROPY_PY_USSL_FINALISER (0) #define MICROPY_PY_USSL_FINALISER (0)
#endif #endif
#ifndef MICROPY_PY_WEBSOCKET #ifndef MICROPY_PY_UWEBSOCKET
#define MICROPY_PY_WEBSOCKET (0) #define MICROPY_PY_UWEBSOCKET (0)
#endif #endif
#ifndef MICROPY_PY_FRAMEBUF #ifndef MICROPY_PY_FRAMEBUF

Wyświetl plik

@ -211,8 +211,8 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
#if MICROPY_PY_LWIP #if MICROPY_PY_LWIP
{ MP_ROM_QSTR(MP_QSTR_lwip), MP_ROM_PTR(&mp_module_lwip) }, { MP_ROM_QSTR(MP_QSTR_lwip), MP_ROM_PTR(&mp_module_lwip) },
#endif #endif
#if MICROPY_PY_WEBSOCKET #if MICROPY_PY_UWEBSOCKET
{ MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&mp_module_websocket) }, { MP_ROM_QSTR(MP_QSTR_uwebsocket), MP_ROM_PTR(&mp_module_uwebsocket) },
#endif #endif
#if MICROPY_PY_WEBREPL #if MICROPY_PY_WEBREPL
{ MP_ROM_QSTR(MP_QSTR__webrepl), MP_ROM_PTR(&mp_module_webrepl) }, { MP_ROM_QSTR(MP_QSTR__webrepl), MP_ROM_PTR(&mp_module_webrepl) },

Wyświetl plik

@ -256,7 +256,7 @@ PY_EXTMOD_O_BASENAME = \
extmod/modussl_mbedtls.o \ extmod/modussl_mbedtls.o \
extmod/modurandom.o \ extmod/modurandom.o \
extmod/moduselect.o \ extmod/moduselect.o \
extmod/modwebsocket.o \ extmod/moduwebsocket.o \
extmod/modwebrepl.o \ extmod/modwebrepl.o \
extmod/modframebuf.o \ extmod/modframebuf.o \
extmod/vfs.o \ extmod/vfs.o \

Wyświetl plik

@ -1,20 +1,20 @@
try: try:
import uio import uio
import uerrno import uerrno
import websocket import uwebsocket
except ImportError: except ImportError:
print("SKIP") print("SKIP")
raise SystemExit raise SystemExit
# put raw data in the stream and do a websocket read # put raw data in the stream and do a websocket read
def ws_read(msg, sz): def ws_read(msg, sz):
ws = websocket.websocket(uio.BytesIO(msg)) ws = uwebsocket.websocket(uio.BytesIO(msg))
return ws.read(sz) return ws.read(sz)
# do a websocket write and then return the raw data from the stream # do a websocket write and then return the raw data from the stream
def ws_write(msg, sz): def ws_write(msg, sz):
s = uio.BytesIO() s = uio.BytesIO()
ws = websocket.websocket(s) ws = uwebsocket.websocket(s)
ws.write(msg) ws.write(msg)
s.seek(0) s.seek(0)
return s.read(sz) return s.read(sz)
@ -36,7 +36,7 @@ print(ws_read(b"\x81\x84maskmask", 4))
# close control frame # close control frame
s = uio.BytesIO(b'\x88\x00') # FRAME_CLOSE s = uio.BytesIO(b'\x88\x00') # FRAME_CLOSE
ws = websocket.websocket(s) ws = uwebsocket.websocket(s)
print(ws.read(1)) print(ws.read(1))
s.seek(2) s.seek(2)
print(s.read(4)) print(s.read(4))
@ -46,11 +46,11 @@ print(ws_read(b"\x89\x00\x81\x04ping", 4)) # FRAME_PING
print(ws_read(b"\x8a\x00\x81\x04pong", 4)) # FRAME_PONG print(ws_read(b"\x8a\x00\x81\x04pong", 4)) # FRAME_PONG
# close method # close method
ws = websocket.websocket(uio.BytesIO()) ws = uwebsocket.websocket(uio.BytesIO())
ws.close() ws.close()
# ioctl # ioctl
ws = websocket.websocket(uio.BytesIO()) ws = uwebsocket.websocket(uio.BytesIO())
print(ws.ioctl(8)) # GET_DATA_OPTS print(ws.ioctl(8)) # GET_DATA_OPTS
print(ws.ioctl(9, 2)) # SET_DATA_OPTS print(ws.ioctl(9, 2)) # SET_DATA_OPTS
print(ws.ioctl(9)) print(ws.ioctl(9))