def testPatchObj(self): # Patch Object. p = dmp_module.patch_obj() p.start1 = 20 p.start2 = 21 p.length1 = 18 p.length2 = 17 p.diffs = [(self.dmp.DIFF_EQUAL, "jump"), (self.dmp.DIFF_DELETE, "s"), (self.dmp.DIFF_INSERT, "ed"), (self.dmp.DIFF_EQUAL, " over "), (self.dmp.DIFF_DELETE, "the"), (self.dmp.DIFF_INSERT, "a"), (self.dmp.DIFF_EQUAL, "\nlaz")] strp = str(p) self.assertEquals("@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n %0Alaz\n", strp)
def testPatchObj(self): # Patch Object p = dmp_module.patch_obj() p.start1 = 20 p.start2 = 21 p.length1 = 18 p.length2 = 17 p.diffs = [(self.dmp.DIFF_EQUAL, "jump"), (self.dmp.DIFF_DELETE, "s"), (self.dmp.DIFF_INSERT, "ed"), (self.dmp.DIFF_EQUAL, " over "), (self.dmp.DIFF_DELETE, "the"), (self.dmp.DIFF_INSERT, "a"), (self.dmp.DIFF_EQUAL, "\nlaz")] strp = str(p) self.assertEquals("@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n %0Alaz\n", strp)
def from_dict(cls, dct): """ Creates an instance of revision from a dictionary serialization """ inst = cls() for item in dct['d']: p = patch_obj() p.diffs = item['d'] p.start1 = item['s1'] p.start2 = item['s2'] p.length1 = item['l1'] p.length2 = item['l2'] inst._diffs.append(p) inst._hash = dct['h'] return inst
def invert(patch: patch_obj) -> patch_obj: new_patch = patch_obj() new_patch.start1, new_patch.start2 = patch.start2, patch.start1 new_patch.length1, new_patch.length2 = patch.length2, patch.length1 for op, data in patch.diffs: if op == diff_match_patch.DIFF_INSERT: new_patch.diffs.append((diff_match_patch.DIFF_DELETE, data)) elif op == diff_match_patch.DIFF_DELETE: new_patch.diffs.append((diff_match_patch.DIFF_INSERT, data)) else: new_patch.diffs.append((op, data)) return new_patch