예제 #1
0
    def format(self, undo, do, prev):
        """Format the given translations.

        This duplicates Formatter's logic - it would be better if
        there was a render(old, new) method that could be overridden.
        """
        for t in do:
            last_action = _get_last_action(prev.formatting if prev else None)
            if t.english:
                t.formatting = _translation_to_actions(t.english, last_action, False)
            else:
                t.formatting = _raw_to_actions(t.rtfcre[0], last_action, False)
            prev = t

        old = [a for t in undo for a in t.formatting]
        new = [a for t in do for a in t.formatting]
        print "old:", old
        print "new:", new

        min_length = min(len(old), len(new))
        for i in xrange(min_length):
            if old[i] != new[i]:
                break
        else:
            i = min_length

        self.render(old[i:], new[i:])
예제 #2
0
    def format(self, undo, do, prev):
        """Format the given translations.

        This duplicates Formatter's logic - it would be better if
        there was a render(old, new) method that could be overridden.
        """
        for t in do:
            last_action = _get_last_action(prev.formatting if prev else None)
            if t.english:
                t.formatting = _translation_to_actions(t.english, last_action,
                                                       False)
            else:
                t.formatting = _raw_to_actions(t.rtfcre[0], last_action, False)
            prev = t

        old = [a for t in undo for a in t.formatting]
        new = [a for t in do for a in t.formatting]
        print "old:", old
        print "new:", new

        min_length = min(len(old), len(new))
        for i in xrange(min_length):
            if old[i] != new[i]:
                break
        else:
            i = min_length

        self.render(old[i:], new[i:])
예제 #3
0
 def test_get_last_action(self):
     self.assertEqual(formatting._get_last_action(None), action())
     self.assertEqual(formatting._get_last_action([]), action())
     actions = [action(text='hello'), action(text='world')]
     self.assertEqual(formatting._get_last_action(actions), actions[-1])