def patch_fromText(self, textline):
    """Parse a textual representation of patches and return a list of patch
    objects.

    Args:
      textline: Text representation of patches.

    Returns:
      Array of Patch objects.

    Raises:
      ValueError: If invalid input.
    """
    if type(textline) == unicode:
      # Patches should be composed of a subset of ascii chars, Unicode not
      # required.  If this encode raises UnicodeEncodeError, patch is invalid.
      textline = textline.encode("ascii")
    patches = []
    if not textline:
      return patches
    text = textline.split('\n')
    while len(text) != 0:
      m = re.match("^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$", text[0])
      if not m:
        raise ValueError("Invalid patch string: " + text[0])
      patch = patch_obj()
      patches.append(patch)
      patch.start1 = int(m.group(1))
      if m.group(2) == '':
        patch.start1 -= 1
        patch.length1 = 1
      elif m.group(2) == '0':
        patch.length1 = 0
      else:
        patch.start1 -= 1
        patch.length1 = int(m.group(2))

      patch.start2 = int(m.group(3))
      if m.group(4) == '':
        patch.start2 -= 1
        patch.length2 = 1
      elif m.group(4) == '0':
        patch.length2 = 0
      else:
        patch.start2 -= 1
        patch.length2 = int(m.group(4))

      del text[0]

      while len(text) != 0:
        if text[0]:
          sign = text[0][0]
        else:
          sign = ''
        line = urllib.unquote(text[0][1:])
        line = line.decode("utf-8")
        if sign == '+':
          # Insertion.
          patch.diffs.append((self.DIFF_INSERT, line))
        elif sign == '-':
          # Deletion.
          patch.diffs.append((self.DIFF_DELETE, line))
        elif sign == ' ':
          # Minor equality.
          patch.diffs.append((self.DIFF_EQUAL, line))
        elif sign == '@':
          # Start of next patch.
          break
        elif sign == '':
          # Blank line?  Whatever.
          pass
        else:
          # WTF?
          raise ValueError((sign, line) % "Invalid patch mode: '%s'\n%s")
        del text[0]
    return patches
dataset/ETHPy150Open JT5D/Alfred-Popclip-Sublime/Sublime Text 2/JsFormat/libs/diff_match_patch/python2/diff_match_patch.py/diff_match_patch.patch_fromText/swapped operands of `%`