Commit 23b3b040 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

unix: Rename "microsocket" module to "usocket".

Per new conventions, we'd like to consistently use "u*" naming conventions
for modules which don't offer complete CPython compatibility, while offer
subset or similar API.
parent a2d8f98a
try: try:
import microsocket as _socket import usocket as _socket
except: except:
import _socket import _socket
......
try: try:
import microsocket as socket import usocket as socket
except: except:
import socket import socket
......
...@@ -64,10 +64,6 @@ mp_uint_t mp_verbose_flag = 0; ...@@ -64,10 +64,6 @@ mp_uint_t mp_verbose_flag = 0;
long heap_size = 128*1024 * (sizeof(mp_uint_t) / 4); long heap_size = 128*1024 * (sizeof(mp_uint_t) / 4);
#endif #endif
void microsocket_init();
void time_init();
void ffi_init();
#define FORCED_EXIT (0x100) #define FORCED_EXIT (0x100)
// returns standard error codes: 0 for success, 1 for all other errors // returns standard error codes: 0 for success, 1 for all other errors
// if FORCED_EXIT bit is set then script raised SystemExit and the // if FORCED_EXIT bit is set then script raised SystemExit and the
......
...@@ -53,11 +53,11 @@ ...@@ -53,11 +53,11 @@
/* /*
The idea of this module is to implement reasonable minimum of The idea of this module is to implement reasonable minimum of
socket-related functions to write typical clients and servers. socket-related functions to write typical clients and servers.
The module named "microsocket" on purpose, to allow to make The module named "usocket" on purpose, to allow to make
Python-level module more (or fully) compatible with CPython Python-level module more (or fully) compatible with CPython
"socket", e.g.: "socket", e.g.:
---- socket.py ---- ---- socket.py ----
from microsocket import * from usocket import *
from socket_more_funcs import * from socket_more_funcs import *
from socket_more_funcs2 import * from socket_more_funcs2 import *
------------------- -------------------
...@@ -72,7 +72,7 @@ typedef struct _mp_obj_socket_t { ...@@ -72,7 +72,7 @@ typedef struct _mp_obj_socket_t {
int fd; int fd;
} mp_obj_socket_t; } mp_obj_socket_t;
STATIC const mp_obj_type_t microsocket_type; STATIC const mp_obj_type_t usocket_type;
// Helper functions // Helper functions
#define RAISE_ERRNO(err_flag, error_val) \ #define RAISE_ERRNO(err_flag, error_val) \
...@@ -81,7 +81,7 @@ STATIC const mp_obj_type_t microsocket_type; ...@@ -81,7 +81,7 @@ STATIC const mp_obj_type_t microsocket_type;
STATIC mp_obj_socket_t *socket_new(int fd) { STATIC mp_obj_socket_t *socket_new(int fd) {
mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t); mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t);
o->base.type = &microsocket_type; o->base.type = &usocket_type;
o->fd = fd; o->fd = fd;
return o; return o;
} }
...@@ -284,7 +284,7 @@ STATIC mp_obj_t socket_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_ ...@@ -284,7 +284,7 @@ STATIC mp_obj_t socket_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_
return socket_new(fd); return socket_new(fd);
} }
STATIC const mp_map_elem_t microsocket_locals_dict_table[] = { STATIC const mp_map_elem_t usocket_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_fileno), (mp_obj_t)&socket_fileno_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_fileno), (mp_obj_t)&socket_fileno_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_makefile), (mp_obj_t)&socket_makefile_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_makefile), (mp_obj_t)&socket_makefile_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
...@@ -302,22 +302,22 @@ STATIC const mp_map_elem_t microsocket_locals_dict_table[] = { ...@@ -302,22 +302,22 @@ STATIC const mp_map_elem_t microsocket_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&socket_close_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&socket_close_obj },
}; };
STATIC MP_DEFINE_CONST_DICT(microsocket_locals_dict, microsocket_locals_dict_table); STATIC MP_DEFINE_CONST_DICT(usocket_locals_dict, usocket_locals_dict_table);
STATIC const mp_stream_p_t microsocket_stream_p = { STATIC const mp_stream_p_t usocket_stream_p = {
.read = socket_read, .read = socket_read,
.write = socket_write, .write = socket_write,
}; };
STATIC const mp_obj_type_t microsocket_type = { STATIC const mp_obj_type_t usocket_type = {
{ &mp_type_type }, { &mp_type_type },
.name = MP_QSTR_socket, .name = MP_QSTR_socket,
.print = socket_print, .print = socket_print,
.make_new = socket_make_new, .make_new = socket_make_new,
.getiter = NULL, .getiter = NULL,
.iternext = NULL, .iternext = NULL,
.stream_p = &microsocket_stream_p, .stream_p = &usocket_stream_p,
.locals_dict = (mp_obj_t)&microsocket_locals_dict, .locals_dict = (mp_obj_t)&usocket_locals_dict,
}; };
#if MICROPY_SOCKET_EXTRA #if MICROPY_SOCKET_EXTRA
...@@ -420,8 +420,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod ...@@ -420,8 +420,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod
extern mp_obj_type_t sockaddr_in_type; extern mp_obj_type_t sockaddr_in_type;
STATIC const mp_map_elem_t mp_module_socket_globals_table[] = { STATIC const mp_map_elem_t mp_module_socket_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_microsocket) }, { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usocket) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&microsocket_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&usocket_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&mod_socket_getaddrinfo_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&mod_socket_getaddrinfo_obj },
#if MICROPY_SOCKET_EXTRA #if MICROPY_SOCKET_EXTRA
{ MP_OBJ_NEW_QSTR(MP_QSTR_sockaddr_in), (mp_obj_t)&sockaddr_in_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_sockaddr_in), (mp_obj_t)&sockaddr_in_type },
...@@ -463,6 +463,6 @@ STATIC const mp_obj_dict_t mp_module_socket_globals = { ...@@ -463,6 +463,6 @@ STATIC const mp_obj_dict_t mp_module_socket_globals = {
const mp_obj_module_t mp_module_socket = { const mp_obj_module_t mp_module_socket = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_microsocket, .name = MP_QSTR_usocket,
.globals = (mp_obj_dict_t*)&mp_module_socket_globals, .globals = (mp_obj_dict_t*)&mp_module_socket_globals,
}; };
...@@ -99,7 +99,7 @@ extern const struct _mp_obj_module_t mp_module_ffi; ...@@ -99,7 +99,7 @@ extern const struct _mp_obj_module_t mp_module_ffi;
#define MICROPY_PORT_BUILTIN_MODULES \ #define MICROPY_PORT_BUILTIN_MODULES \
MICROPY_PY_FFI_DEF \ MICROPY_PY_FFI_DEF \
MICROPY_PY_TIME_DEF \ MICROPY_PY_TIME_DEF \
{ MP_OBJ_NEW_QSTR(MP_QSTR_microsocket), (mp_obj_t)&mp_module_socket }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_socket }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR__os), (mp_obj_t)&mp_module_os }, \ { MP_OBJ_NEW_QSTR(MP_QSTR__os), (mp_obj_t)&mp_module_os }, \
MICROPY_PY_TERMIOS_DEF \ MICROPY_PY_TERMIOS_DEF \
......
...@@ -58,7 +58,7 @@ Q(htons) ...@@ -58,7 +58,7 @@ Q(htons)
Q(inet_aton) Q(inet_aton)
Q(gethostbyname) Q(gethostbyname)
Q(getaddrinfo) Q(getaddrinfo)
Q(microsocket) Q(usocket)
Q(connect) Q(connect)
Q(bind) Q(bind)
Q(listen) Q(listen)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment