Beispiel #1
0
    def push(self, data, allow_none=False):
        if data is None and allow_none is False:
            raise ValueError(
                "Code push has no data (use allow_none=True to push empty data)"
            )

        # Checks the hex-digest of the current iteration to see if anything changes
        # and will not update if nothing has occurred to the output
        if md5sum(getattr(self.current, 'code', None)) == md5sum(data):
            return self.current

        # Build the new item
        next = Iteration(data, from_id=self.active_iteration)
        self.iterations.append(next)

        to_id = len(self.iterations) - 1

        # Update to "to_id" for our old iteration to point to the new one
        # but only do this if we had an old iteration
        if bound_check(self.iterations, self.active_iteration):
            self.iterations[self.active_iteration].branch(to_id)

        # Update our active iteration tracker
        self.active_iteration = to_id

        # Returns the current item (added from this push)
        return self.current
Beispiel #2
0
    def back(self, count=1):
        if count >= 1 and bound_check(self.iterations, current.from_id):
            self.jump(current.from_id)
            return self.back(count - 1)

        # Count = 0 here (we no longer go back - just return the current iteration
        return self.current
Beispiel #3
0
    def current(self):
        if bound_check(self.iterations, self.active_iteration):
            return self.iterations[self.active_iteration]

        return None
Beispiel #4
0
    def get_line(self, line_no):
        if bound_check(self.data, line_no):
            return ' '.join([tok.__str__() for tok in self.data[line_no]])

        return None
Beispiel #5
0
    def jump(self, iteration):
        if bound_check(self.iterations, iteration):
            self.active_iteration = iteration

        return self.get_code()
Beispiel #6
0
    def peek(self):
        if bound_check(self.iterations, self.active_iteration):
            return self.current.get_branches()

        return None
Beispiel #7
0
    def get_code(self, iteration=-1):
        if bound_check(self.iterations, iteration):
            return self.iterations[iteration]

        return self.current