def patch_addPadding(self, patches):
    """Add some padding on text start and end so that edges can match
    something.  Intended to be called only from within patch_apply.

    Args:
      patches: Array of Patch objects.

    Returns:
      The padding string added to each side.
    """
    paddingLength = self.Patch_Margin
    nullPadding = ""
    for x in range(1, paddingLength + 1):
      nullPadding += chr(x)

    # Bump all the patches forward.
    for patch in patches:
      patch.start1 += paddingLength
      patch.start2 += paddingLength

    # Add some padding on start of first diff.
    patch = patches[0]
    diffs = patch.diffs
    if not diffs or diffs[0][0] != self.DIFF_EQUAL:
      # Add nullPadding equality.
      diffs.insert(0, (self.DIFF_EQUAL, nullPadding))
      patch.start1 -= paddingLength  # Should be 0.
      patch.start2 -= paddingLength  # Should be 0.
      patch.length1 += paddingLength
      patch.length2 += paddingLength
    elif paddingLength > len(diffs[0][1]):
      # Grow first equality.
      extraLength = paddingLength - len(diffs[0][1])
      newText = nullPadding[len(diffs[0][1]):] + diffs[0][1]
      diffs[0] = (diffs[0][0], newText)
      patch.start1 -= extraLength
      patch.start2 -= extraLength
      patch.length1 += extraLength
      patch.length2 += extraLength

    # Add some padding on end of last diff.
    patch = patches[-1]
    diffs = patch.diffs
    if not diffs or diffs[-1][0] != self.DIFF_EQUAL:
      # Add nullPadding equality.
      diffs.append((self.DIFF_EQUAL, nullPadding))
      patch.length1 += paddingLength
      patch.length2 += paddingLength
    elif paddingLength > len(diffs[-1][1]):
      # Grow last equality.
      extraLength = paddingLength - len(diffs[-1][1])
      newText = diffs[-1][1] + nullPadding[:extraLength]
      diffs[-1] = (diffs[-1][0], newText)
      patch.length1 += extraLength
      patch.length2 += extraLength

    return nullPadding
def patch_addPadding ( self , patches ) : paddingLength = self . Patch_Margin nullPadding = "" for x in range ( 1 , paddingLength + 1 ) : nullPadding += chr ( x ) for patch in patches : patch . start1 += paddingLength patch . start2 += paddingLength patch = patches [ 0 ] diffs = patch . diffs if not diffs or diffs [ 0 ] [ 0 ] != self . DIFF_EQUAL : diffs . insert ( 0 , ( self . DIFF_EQUAL , nullPadding ) ) patch . start1 -= paddingLength patch . start2 -= paddingLength patch . length1 += paddingLength patch . length2 += paddingLength elif paddingLength > len ( diffs [ 0 ] [ 1 ] ) : extraLength = paddingLength - len ( diffs [ 0 ] [ 1 ] ) newText = nullPadding [ len ( diffs [ 0 ] [ 1 ] ) : ] + diffs [ 0 ] [ 1 ] diffs [ 0 ] = ( diffs [ 0 ] [ 0 ] , newText ) patch . start1 -= extraLength patch . start2 -= extraLength patch . length1 += extraLength patch . length2 += extraLength patch = patches [ - 1 ] diffs = patch . diffs if not diffs or diffs [ - 1 ] [ 0 ] != self . DIFF_EQUAL : diffs . append ( ( self . DIFF_EQUAL , nullPadding ) ) patch . length1 += paddingLength patch . length2 += paddingLength elif paddingLength > len ( diffs [ - 1 ] [ 1 ] ) : extraLength = paddingLength - len ( diffs [ - 1 ] [ 1 ] ) newText = diffs [ - 1 ] [ 1 ] + nullPadding [ : extraLength ] diffs [ - 1 ] = ( diffs [ - 1 ] [ 0 ] , newText ) patch . length1 += extraLength patch . length2 += extraLength return nullPadding
Add some padding on text start and end so that edges can match
    something.  Intended to be called only from within patch_apply.

    Args:
      patches: Array of Patch objects.

    Returns:
      The padding string added to each side.