def parse(self, key, value):
        ref = self.result
        tokens = self.tokens(key)

        for token in tokens:
            token_type, key = token

            if token_type == QueryStringToken.ARRAY:
                if key not in ref:
                    ref[key] = []
                ref = ref[key]

            elif token_type == QueryStringToken.OBJECT:
                if key not in ref:
                    ref[key] = {}
                ref = ref[key]

            elif token_type == QueryStringToken.KEY:
                try:
                    ref = ref[key]
                    next(tokens)
                # TypeError is for pet[]=lucy&pet[]=ollie
                # if the array key is empty a type error will be raised
                except (IndexError, __HOLE__, TypeError):
                    # the index didn't exist
                    # so we look ahead to see what we are setting
                    # there is not a next token
                    # set the value
                    try:

                        next_token = next(tokens)

                        if next_token[0] == QueryStringToken.ARRAY:
                            ref.append([])
                            ref = ref[key]
                        elif next_token[0] == QueryStringToken.OBJECT:

                            try:
                                ref[key] = {}
                            except IndexError:
                                ref.append({})

                            ref = ref[key]
                    except StopIteration:
                        try:
                            ref.append(value)
                        except AttributeError:
                            ref[key] = value
                        return
dataset/ETHPy150Open circuits/circuits/circuits/web/parsers/querystring.py/QueryStringParser.parse