summaryrefslogtreecommitdiffstatshomepage
path: root/py/objexcept.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-13 19:19:16 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-15 02:15:38 +0200
commit76d982ef343dcadd35355aed9c568984c850fb7b (patch)
tree1ded5f199ce740d3b72c00cc1e9c2b402936632f /py/objexcept.c
parent24224d7c72e1d6572ef0d24f08eb882dcac8dc50 (diff)
downloadmicropython-76d982ef343dcadd35355aed9c568984c850fb7b.tar.gz
micropython-76d982ef343dcadd35355aed9c568984c850fb7b.zip
type->print(): Distinguish str() and repr() variety by passing extra param.
Diffstat (limited to 'py/objexcept.c')
-rw-r--r--py/objexcept.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/py/objexcept.c b/py/objexcept.c
index f083e61e52..67e6d63155 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);
}
}