Ejemplo n.º 1
0
    def __init__(self, maxsize=sys.maxint):
        """maxsize -- maximum size of undo list"""

        # stacks maintaining (undo,redo) pairs
        self._undo_actions = LinkedList()
        self._redo_actions = []

        # grouping several actions into one
        self._group_counter = 0
        self._pending_actions = []

        # suppress undo/redo while counter > 0
        self._suppress_counter = 0

        # maximum size undo stack
        self._maxsize = maxsize

        self._in_progress = False
Ejemplo n.º 2
0
def normalize_tags(contents, is_stable_tag=lambda tag: False):
    """Normalize open and close tags to ensure proper nesting
       This is especially useful for saving to HTML

       is_stable_tag -- a function that returns True iff a tag should not
       be touched (``stable'').

       NOTE: All iterators will be turned to None's.  Since were are changing
       tag order, iterators no longer make sense

       NOTE: assumes we do not have any 'beginstr' and 'endstr' items
    """

    open_stack = []
    contents = PushIter(contents)

    for item in contents:
        kind, it, param = item

        if kind == "begin":

            if is_stable_tag(param):
                # if stable tag, skim ahead to see its closing tag
                stable_span = LinkedList()
                within_closes = set()
                for item2 in contents:
                    stable_span.append(item2)
                    if item2[0] == "end":
                        # look at closing tags
                        if item2[2] == param:
                            # found matching stable close
                            break

                        else:
                            # record tags that close within the stable_span
                            within_closes.add(item2[2])

                # push items back on contents stream
                for item2 in reversed(stable_span):
                    contents.push(item2)

                # define tag classes
                # preopen = open_stack

                # preopen_inside = preopen's with a close in stable_span
                preopen_inside = []
                for tag in open_stack:
                    if tag in within_closes:
                        preopen_inside.append(tag)

                # close preopen_inside
                for item2 in _normalize_close(open_stack, preopen_inside):
                    yield item2

                # yield stable open
                open_stack.append(param)
                yield ("begin", None, param)

                # reopen preopen_inside
                for tag in preopen_inside:
                    open_stack.append(tag)
                    yield ("begin", None, tag)

            else:
                # yield item unchanged
                open_stack.append(param)
                yield ("begin", None, param)

        elif kind == "end":

            for item2 in _normalize_close(open_stack, [param]):
                yield item2

        else:
            yield (kind, None, param)