diff options
| author | Paul Sokolovsky | 2014-05-19 20:59:13 +0300 |
|---|---|---|
| committer | Paul Sokolovsky | 2014-05-19 21:56:07 +0300 |
| commit | 9e29666bf99c5e5f1cb0246d420b207aacfdf408 (patch) | |
| tree | 9d18b149aa3efe878f5b833fd66beade944e6dc7 /stmhal | |
| parent | 52386cafa0b3d6715f208a1dc36f149e615363d4 (diff) | |
py: Implement proper separation between io.FileIO and io.TextIOWrapper.
io.FileIO is binary I/O, ans actually optional. Default file type is
io.TextIOWrapper, which provides str results. CPython3 explicitly describes
io.TextIOWrapper as buffered I/O, but we don't have buffering support yet
anyway.
Diffstat (limited to 'stmhal')
| -rw-r--r-- | stmhal/file.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/stmhal/file.c b/stmhal/file.c index 93bd49e66..3fea95653 100644 --- a/stmhal/file.c +++ b/stmhal/file.c @@ -41,7 +41,7 @@ typedef struct _pyb_file_obj_t { } pyb_file_obj_t; void file_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { - printf("<io.FileIO %p>", self_in); + printf("<io.%s %p>", mp_obj_get_type_str(self_in), self_in); } STATIC machine_int_t file_read(mp_obj_t self_in, void *buf, machine_uint_t size, int *errcode) { @@ -94,7 +94,7 @@ STATIC const mp_stream_p_t file_obj_stream_p = { .write = file_write, }; -STATIC const mp_obj_type_t file_obj_type = { +const mp_obj_type_t mp_type_textio = { { &mp_type_type }, .name = MP_QSTR_FileIO, .make_new = file_obj_make_new, @@ -113,7 +113,7 @@ STATIC mp_obj_t file_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, cons mode = mp_obj_str_get_str(args[1]); } pyb_file_obj_t *self = m_new_obj_with_finaliser(pyb_file_obj_t); - self->base.type = &file_obj_type; + self->base.type = &mp_type_textio; if (mode[0] == 'r') { // open for reading FRESULT res = f_open(&self->fp, filename, FA_READ); @@ -138,7 +138,7 @@ STATIC mp_obj_t file_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, cons // Factory function for I/O stream classes STATIC mp_obj_t pyb_io_open(uint n_args, const mp_obj_t *args) { // TODO: analyze mode and buffering args and instantiate appropriate type - return file_obj_make_new((mp_obj_t)&file_obj_type, n_args, 0, args); + return file_obj_make_new((mp_obj_t)&mp_type_textio, n_args, 0, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_open_obj, 1, 2, pyb_io_open); |
