From a80ff04fe7458b8ed8e948619b3700b720832ec2 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 20 Jan 2014 20:32:50 +0200 Subject: Add dummy bytes() constructor. Currently, MicroPython strings are mix between CPython byte and unicode strings. So, conversion is null so far. This dummy implementation is intended for compatibility with CPython (so, same code can run on both). --- py/builtin.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'py/builtin.c') diff --git a/py/builtin.c b/py/builtin.c index f102aa588..13463ada6 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -347,3 +347,15 @@ static mp_obj_t mp_builtin_str(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_str_obj, mp_builtin_str); + +// TODO: This should be type, this is just quick CPython compat hack +static mp_obj_t mp_builtin_bytes(uint n_args, const mp_obj_t *args) { + if (!MP_OBJ_IS_QSTR(args[0]) && !MP_OBJ_IS_TYPE(args[0], &str_type)) { + assert(0); + } + // Currently, MicroPython strings are mix between CPython byte and unicode + // strings. So, conversion is null so far. + return args[0]; +} + +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_bytes_obj, 1, 3, mp_builtin_bytes); -- cgit v1.2.3