How to use the cup.util.conf.ConfDict function in cup

To help you get started, we’ve selected a few cup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github baidu / CUP / cup / util / conf.py View on Github external
elif '.' in key:  # conf_layer_stack back to [self._dict]
                    conf_layer_stack = [self._dict]
                    comments = self._handle_group_keys(
                        key, conf_dict_now, conf_layer_stack, comments
                    )
                elif level > len(conf_layer_stack) + 1:
                    raise ArrayFormatError(line)
                elif level == len(conf_layer_stack) + 1:
                    # new grou for
                    if key[0] == '@':
                        key = key[1:]
                        conflist = ConfList()
                        conflist.append(ConfDict())
                        conf_dict_now.set_ex(key, conflist, [])
                    else:
                        conf_dict_now.set_ex(key, ConfDict(), comments)
                        comments = []
                    conf_layer_stack.append(conf_dict_now[key])
                elif level == len(conf_layer_stack):
                    # -1 means the last item. -2 means the second from the end
                    conf_dict_now = conf_layer_stack[-2]   # back one
                    while isinstance(conf_dict_now, list):
                        conf_dict_now = conf_dict_now[-1]
                    if key[0] == '@':
                        tmpkey = key[1:]
                        if tmpkey in conf_dict_now:   # the same group
                            # pylint: disable=E1101
                            # conf_dict_now[tmpkey] = ConfDict()
                            if tmpkey != last_list_key:
                                conf_layer_stack[-1] = conf_dict_now[tmpkey]
                            conf_layer_stack[-1].append_ex(
                                ConfDict(), comments
github baidu / CUP / cup / util / conf.py View on Github external
else:
                        conf_dict_now.set_ex(key, ConfDict(), comments)
                        comments = []
                        conf_layer_stack[-1] = conf_dict_now[key]
                elif level < len(conf_layer_stack):
                    conf_dict_now = conf_layer_stack[level - 2]  # get back
                    while isinstance(conf_dict_now, list):
                        conf_dict_now = conf_dict_now[-1]
                    if key[0] == '@':
                        tmpkey = key[1:]
                        if tmpkey in conf_dict_now:  # the same group
                            tmpdict = ConfDict()
                            conf_layer_stack[level - 1].append(tmpdict)
                        else:  # different group
                            conflist = ConfList()
                            conflist.append(ConfDict())
                            conf_dict_now.set_ex(tmpkey, conflist, [])
                            conf_layer_stack[level - 1] = conf_dict_now[tmpkey]
                    else:
                        conf_dict_now.set_ex(key, ConfDict(), comments)
                        comments = []
                        conf_layer_stack[level - 1] = conf_dict_now[key]
                    conf_layer_stack = conf_layer_stack[:level]
                else:
                    raise UnknowConfError('exception occured')
            num += 1
        return self._dict
github baidu / CUP / cup / util / conf.py View on Github external
if tmpkey != last_list_key:
                                conf_layer_stack[-1] = conf_dict_now[tmpkey]
                            conf_layer_stack[-1].append_ex(
                                ConfDict(), comments
                            )
                            comments = []
                        else:  # different group
                            conflist = ConfList()
                            conflist.append(ConfDict())
                            conf_dict_now.set_ex(tmpkey, conflist, comments)
                            # conf_dict_now.set_ex(tmpkey, conflist, [])
                            comments = []
                            conf_layer_stack[-1] = conf_dict_now[tmpkey]
                        last_list_key = tmpkey
                    else:
                        conf_dict_now.set_ex(key, ConfDict(), comments)
                        comments = []
                        conf_layer_stack[-1] = conf_dict_now[key]
                elif level < len(conf_layer_stack):
                    conf_dict_now = conf_layer_stack[level - 2]  # get back
                    while isinstance(conf_dict_now, list):
                        conf_dict_now = conf_dict_now[-1]
                    if key[0] == '@':
                        tmpkey = key[1:]
                        if tmpkey in conf_dict_now:  # the same group
                            tmpdict = ConfDict()
                            conf_layer_stack[level - 1].append(tmpdict)
                        else:  # different group
                            conflist = ConfList()
                            conflist.append(ConfDict())
                            conf_dict_now.set_ex(tmpkey, conflist, [])
                            conf_layer_stack[level - 1] = conf_dict_now[tmpkey]
github baidu / CUP / cup / util / conf.py View on Github external
groupkey = groupkey[1:]
                    if groupkey in conf_dict_now:
                        conf_dict_now[groupkey].append_ex(
                            {}, comments
                        )
                        comments = []
                    else:
                        conflist = ConfList()
                        conf_dict_now.set_ex(
                            groupkey, conflist, comments
                        )
                        comments = []
                        conflist.append(ConfDict())
                else:
                    conf_dict_now.set_ex(
                        groupkey, ConfDict(), comments
                    )
                    comments = []
                conf_layer_stack.append(conf_dict_now[groupkey])
        return comments
github baidu / CUP / cup / util / conf.py View on Github external
comments = []
                    conf_layer_stack.append(conf_dict_now[key])
                elif level == len(conf_layer_stack):
                    # -1 means the last item. -2 means the second from the end
                    conf_dict_now = conf_layer_stack[-2]   # back one
                    while isinstance(conf_dict_now, list):
                        conf_dict_now = conf_dict_now[-1]
                    if key[0] == '@':
                        tmpkey = key[1:]
                        if tmpkey in conf_dict_now:   # the same group
                            # pylint: disable=E1101
                            # conf_dict_now[tmpkey] = ConfDict()
                            if tmpkey != last_list_key:
                                conf_layer_stack[-1] = conf_dict_now[tmpkey]
                            conf_layer_stack[-1].append_ex(
                                ConfDict(), comments
                            )
                            comments = []
                        else:  # different group
                            conflist = ConfList()
                            conflist.append(ConfDict())
                            conf_dict_now.set_ex(tmpkey, conflist, comments)
                            # conf_dict_now.set_ex(tmpkey, conflist, [])
                            comments = []
                            conf_layer_stack[-1] = conf_dict_now[tmpkey]
                        last_list_key = tmpkey
                    else:
                        conf_dict_now.set_ex(key, ConfDict(), comments)
                        comments = []
                        conf_layer_stack[-1] = conf_dict_now[key]
                elif level < len(conf_layer_stack):
                    conf_dict_now = conf_layer_stack[level - 2]  # get back
github baidu / CUP / cup / util / conf.py View on Github external
# conf_dict_now.set_ex(tmpkey, conflist, [])
                            comments = []
                            conf_layer_stack[-1] = conf_dict_now[tmpkey]
                        last_list_key = tmpkey
                    else:
                        conf_dict_now.set_ex(key, ConfDict(), comments)
                        comments = []
                        conf_layer_stack[-1] = conf_dict_now[key]
                elif level < len(conf_layer_stack):
                    conf_dict_now = conf_layer_stack[level - 2]  # get back
                    while isinstance(conf_dict_now, list):
                        conf_dict_now = conf_dict_now[-1]
                    if key[0] == '@':
                        tmpkey = key[1:]
                        if tmpkey in conf_dict_now:  # the same group
                            tmpdict = ConfDict()
                            conf_layer_stack[level - 1].append(tmpdict)
                        else:  # different group
                            conflist = ConfList()
                            conflist.append(ConfDict())
                            conf_dict_now.set_ex(tmpkey, conflist, [])
                            conf_layer_stack[level - 1] = conf_dict_now[tmpkey]
                    else:
                        conf_dict_now.set_ex(key, ConfDict(), comments)
                        comments = []
                        conf_layer_stack[level - 1] = conf_dict_now[key]
                    conf_layer_stack = conf_layer_stack[:level]
                else:
                    raise UnknowConfError('exception occured')
            num += 1
        return self._dict
github baidu / CUP / cup / util / conf.py View on Github external
conf_layer_stack.append(conf_dict_now)
            else:
                if groupkey[0] == '@':
                    groupkey = groupkey[1:]
                    if groupkey in conf_dict_now:
                        conf_dict_now[groupkey].append_ex(
                            {}, comments
                        )
                        comments = []
                    else:
                        conflist = ConfList()
                        conf_dict_now.set_ex(
                            groupkey, conflist, comments
                        )
                        comments = []
                        conflist.append(ConfDict())
                else:
                    conf_dict_now.set_ex(
                        groupkey, ConfDict(), comments
                    )
                    comments = []
                conf_layer_stack.append(conf_dict_now[groupkey])
        return comments