diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-15 22:39:03 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-15 22:39:03 +0000 |
commit | 4899ff9470734f0593bbe1f5272bc3d23facf7f7 (patch) | |
tree | 929b1674e445726b50e3ff2acc1e5706e9b8f5ea /py/objexcept.c | |
parent | 7a9d0c454076b6524f3f6f5af9a6b28bc35da2f9 (diff) | |
parent | 36c4499d36a36ab3e1a68545e613bce61fb15f3c (diff) |
Merge branch 'str-repr' of github.com:pfalcon/micropython into pfalcon-str-repr
Conflicts:
tests/basics/tests/exception1.py
Diffstat (limited to 'py/objexcept.c')
-rw-r--r-- | py/objexcept.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/py/objexcept.c b/py/objexcept.c index f083e61e5..67e6d6315 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -21,13 +21,25 @@ typedef struct mp_obj_exception_t { mp_obj_tuple_t args; } mp_obj_exception_t; -void exception_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in) { +void exception_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_exception_t *o = o_in; if (o->msg != 0) { print(env, "%s: %s", qstr_str(o->id), qstr_str(o->msg)); } else { - print(env, "%s", qstr_str(o->id)); - tuple_print(print, env, &o->args); + // Yes, that's how CPython has it + if (kind == PRINT_REPR) { + print(env, "%s", qstr_str(o->id)); + } + if (kind == PRINT_STR) { + if (o->args.len == 0) { + print(env, ""); + return; + } else if (o->args.len == 1) { + mp_obj_print_helper(print, env, o->args.items[0], PRINT_STR); + return; + } + } + tuple_print(print, env, &o->args, kind); } } |