From 612045f53f7e5edf9faa359ee9ee52d490d58000 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 17 Sep 2014 22:56:34 +0100 Subject: py: Add native json printing using existing print framework. Also add start of ujson module with dumps implemented. Enabled in unix and stmhal ports. Test passes on both. --- py/objtuple.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'py/objtuple.c') diff --git a/py/objtuple.c b/py/objtuple.c index 6abe7d2c6..2793e4838 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -43,17 +43,26 @@ STATIC mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, mp_uint_t cur); void mp_obj_tuple_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_tuple_t *o = o_in; - print(env, "("); + if (MICROPY_PY_UJSON && kind == PRINT_JSON) { + print(env, "["); + } else { + print(env, "("); + kind = PRINT_REPR; + } for (mp_uint_t i = 0; i < o->len; i++) { if (i > 0) { print(env, ", "); } - mp_obj_print_helper(print, env, o->items[i], PRINT_REPR); + mp_obj_print_helper(print, env, o->items[i], kind); } - if (o->len == 1) { - print(env, ","); + if (MICROPY_PY_UJSON && kind == PRINT_JSON) { + print(env, "]"); + } else { + if (o->len == 1) { + print(env, ","); + } + print(env, ")"); } - print(env, ")"); } STATIC mp_obj_t mp_obj_tuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { -- cgit v1.2.3