Skip to content
Snippets Groups Projects
Select Git revision
  • d46ca25757b9021809946bb7274376c410b699eb
  • wip-bootstrap default
  • dualcore
  • ch3/leds
  • ch3/time
  • master
6 results

file.c

  • objtuple.c 11.08 KiB
    /*
     * This file is part of the MicroPython project, http://micropython.org/
     *
     * The MIT License (MIT)
     *
     * Copyright (c) 2013, 2014 Damien P. George
     * Copyright (c) 2014-2017 Paul Sokolovsky
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     * THE SOFTWARE.
     */
    
    #include <string.h>
    #include <assert.h>
    
    #include "py/objtuple.h"
    #include "py/runtime.h"
    
    // type check is done on getiter method to allow tuple, namedtuple, attrtuple
    #define mp_obj_is_tuple_compatible(o) (MP_OBJ_TYPE_GET_SLOT_OR_NULL(mp_obj_get_type(o), iter) == mp_obj_tuple_getiter)
    
    /******************************************************************************/
    /* tuple                                                                      */
    
    void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
        mp_obj_tuple_t *o = MP_OBJ_TO_PTR(o_in);
    
        const char *item_separator = ", ";
        if (MICROPY_PY_UJSON && kind == PRINT_JSON) {
            mp_print_str(print, "[");
            #if MICROPY_PY_UJSON_SEPARATORS
            item_separator = MP_PRINT_GET_EXT(print)->item_separator;
            #endif
        } else {
            mp_print_str(print, "(");
            kind = PRINT_REPR;
        }
        const char *indent_str = NULL;
        if(kind == PRINT_JSON){
            indent_str = MP_PRINT_GET_EXT(print)->indent;
        }
        if(kind == PRINT_JSON){
            MP_PRINT_GET_EXT(print)->indent_depth++;
        }
        for (size_t i = 0; i < o->len; i++) {
            if (i > 0) {
                mp_print_str(print, item_separator);
            }
            mp_print_indent(print, indent_str);
            mp_obj_print_helper(print, o->items[i], kind);
        }
        if(kind == PRINT_JSON){
            MP_PRINT_GET_EXT(print)->indent_depth--;
        }
        mp_print_indent(print, indent_str);