py/modio: Remove io.resource_stream function.
This feature is not enabled on any port, it's not in CPython's io module, and functionality is better suited to the micropython-lib implementation of pkg_resources.
This commit is contained in:
committed by
Damien George
parent
d6dc4cb65a
commit
cc23e99f32
47
py/modio.c
47
py/modio.c
@@ -204,50 +204,6 @@ STATIC const mp_obj_type_t mp_type_bufwriter = {
|
||||
};
|
||||
#endif // MICROPY_PY_IO_BUFFEREDWRITER
|
||||
|
||||
#if MICROPY_PY_IO_RESOURCE_STREAM
|
||||
STATIC mp_obj_t resource_stream(mp_obj_t package_in, mp_obj_t path_in) {
|
||||
VSTR_FIXED(path_buf, MICROPY_ALLOC_PATH_MAX);
|
||||
size_t len;
|
||||
|
||||
// As an extension to pkg_resources.resource_stream(), we support
|
||||
// package parameter being None, the path_in is interpreted as a
|
||||
// raw path.
|
||||
if (package_in != mp_const_none) {
|
||||
// Pass "True" as sentinel value in fromlist to force returning of leaf module
|
||||
mp_obj_t pkg = mp_import_name(mp_obj_str_get_qstr(package_in), mp_const_true, MP_OBJ_NEW_SMALL_INT(0));
|
||||
|
||||
mp_obj_t dest[2];
|
||||
mp_load_method_maybe(pkg, MP_QSTR___path__, dest);
|
||||
if (dest[0] == MP_OBJ_NULL) {
|
||||
mp_raise_TypeError(NULL);
|
||||
}
|
||||
|
||||
const char *path = mp_obj_str_get_data(dest[0], &len);
|
||||
vstr_add_strn(&path_buf, path, len);
|
||||
vstr_add_byte(&path_buf, '/');
|
||||
}
|
||||
|
||||
const char *path = mp_obj_str_get_data(path_in, &len);
|
||||
vstr_add_strn(&path_buf, path, len);
|
||||
|
||||
len = path_buf.len;
|
||||
const char *data = mp_find_frozen_str(path_buf.buf, &len);
|
||||
if (data != NULL) {
|
||||
mp_obj_stringio_t *o = m_new_obj(mp_obj_stringio_t);
|
||||
o->base.type = &mp_type_bytesio;
|
||||
o->vstr = m_new_obj(vstr_t);
|
||||
vstr_init_fixed_buf(o->vstr, len + 1, (char *)data);
|
||||
o->vstr->len = len;
|
||||
o->pos = 0;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
mp_obj_t path_out = mp_obj_new_str(path_buf.buf, path_buf.len);
|
||||
return mp_builtin_open(1, &path_out, (mp_map_t *)&mp_const_empty_map);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(resource_stream_obj, resource_stream);
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_io_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uio) },
|
||||
// Note: mp_builtin_open_obj should be defined by port, it's not
|
||||
@@ -256,9 +212,6 @@ STATIC const mp_rom_map_elem_t mp_module_io_globals_table[] = {
|
||||
#if MICROPY_PY_IO_IOBASE
|
||||
{ MP_ROM_QSTR(MP_QSTR_IOBase), MP_ROM_PTR(&mp_type_iobase) },
|
||||
#endif
|
||||
#if MICROPY_PY_IO_RESOURCE_STREAM
|
||||
{ MP_ROM_QSTR(MP_QSTR_resource_stream), MP_ROM_PTR(&resource_stream_obj) },
|
||||
#endif
|
||||
#if MICROPY_PY_IO_FILEIO
|
||||
{ MP_ROM_QSTR(MP_QSTR_FileIO), MP_ROM_PTR(&mp_type_fileio) },
|
||||
#if MICROPY_CPYTHON_COMPAT
|
||||
|
||||
Reference in New Issue
Block a user