
    Jwg:                    V    d Z 	 dZddlZddlZddlZddlZ G d d      Z G d d      Zy)ax  Diff Match and Patch
Copyright 2018 The diff-match-patch Authors.
https://github.com/google/diff-match-patch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
zfraser@google.com (Neil Fraser)    Nc                   4   e Zd ZdZd ZdZdZdZd*dZd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Z ej,                  d      Z ej,                  d      Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d  Z#d! Z$d" Z%d+d#Z&d$ Z'd% Z(d& Z)d' Z*d( Z+d) Z,y),diff_match_patchzcClass containing the diff, match and patch methods.

    Also contains the behaviour settings.
    c                 f    d| _         d| _        d| _        d| _        d| _        d| _        d| _        y)zInits a diff_match_patch object with default settings.
        Redefine these in your program to override the defaults.
              ?   g      ?i      N)Diff_TimeoutDiff_EditCostMatch_ThresholdMatch_DistancePatch_DeleteThresholdPatch_MarginMatch_MaxBitsselfs    X/var/www/horilla/myenv/lib/python3.12/site-packages/diff_match_patch/diff_match_patch.py__init__zdiff_match_patch.__init__(   sB      " #
 &)"         r   Nc                 6   |dk(  rA| j                   dk  rt        j                  }n!t        j                         | j                   z   }|dk(  s|dk(  rt	        d      ||k(  r|r| j
                  |fgS g S | j                  ||      }|d| }||d }||d }| j                  ||      }|dk(  rd}n|| d }|d|  }|d|  }| j                  ||||      }|r| j
                  |fg|dd |r|j                  | j
                  |f       | j                  |       |S )a  Find the differences between two texts.  Simplifies the problem by
          stripping any common prefix or suffix off the texts before diffing.

        Args:
          text1: Old string to be diffed.
          text2: New string to be diffed.
          checklines: Optional speedup flag.  If present and false, then don't run
            a line-level diff first to identify the changed areas.
            Defaults to true, which does a faster, slightly less optimal diff.
          deadline: Optional time when the diff should be complete by.  Used
            internally for recursive calls.  Users should set DiffTimeout instead.

        Returns:
          Array of changes.
        Nr   zNull inputs. (diff_main) )r	   sysmaxsizetime
ValueError
DIFF_EQUALdiff_commonPrefixdiff_commonSuffixdiff_computeappenddiff_cleanupMerge)	r   text1text2
checklinesdeadlinecommonlengthcommonprefixcommonsuffixdiffss	            r   	diff_mainzdiff_match_patch.diff_mainN   sY   " t  A%;;99;):):: D=ETM788 E>%011I --eU;]l+lm$lm$ --eU;1L ,0L.L=)E.L=)E !!%
HE //<89E"1ILL$//<89u%r   c                 D   |s| j                   |fgS |s| j                  |fgS t        |      t        |      kD  r||}}n||}}|j                  |      }|dk7  r| j                   |d| f| j                  |f| j                   ||t        |      z   d fg}t        |      t        |      kD  r.| j                  |d   d   f|d<   | j                  |d   d   f|d<   |S t        |      dk(  r| j                  |f| j                   |fgS | j                  ||      }	|	rE|	\  }
}}}}| j                  |
|||      }| j                  ||||      }|| j                  |fgz   |z   S |r/t        |      dkD  r!t        |      dkD  r| j                  |||      S | j                  |||      S )a  Find the differences between two texts.  Assumes that the texts do not
          have any common prefix or suffix.

        Args:
          text1: Old string to be diffed.
          text2: New string to be diffed.
          checklines: Speedup flag.  If false, then don't run a line-level diff
            first to identify the changed areas.
            If true, then run a faster, slightly less optimal diff.
          deadline: Time when the diff should be complete by.

        Returns:
          Array of changes.
        r   Nr   r      d   )	DIFF_INSERTDIFF_DELETElenfindr   diff_halfMatchr+   diff_lineModediff_bisect)r   r#   r$   r%   r&   longtext	shorttextir*   hmtext1_atext1_btext2_atext2_b
mid_commondiffs_adiffs_bs                    r   r    zdiff_match_patch.diff_compute   s    %%u-..%%u-..u:E
"%*EyX%*EYMM)$7 !!8BQ<0),!!8AI,>,@#ABE 5zCJ& ,,eAhqk:a ,,eAhqk:aLy>Q %%u-0@0@%/HII   .?A<WgwnnWgz8LGnnWgz8LGt
;<<wFF#e*s*s5zC/?%%eUH==uh77r   c                    | j                  ||      \  }}}| j                  ||d|      }| j                  ||       | j                  |       |j	                  | j
                  df       d}d}d}d}	d}
|t        |      k  r||   d   | j                  k(  r|dz  }|
||   d   z  }
n||   d   | j                  k(  r|dz  }|	||   d   z  }	nZ||   d   | j
                  k(  rE|dk\  r8|dk\  r3| j                  |	|
d|      }||||z
  |z
  | ||z
  |z
  t        |      z   }d}d}d}	d}
|dz  }|t        |      k  r|j                          |S )ao  Do a quick line-level diff on both strings, then rediff the parts for
          greater accuracy.
          This speedup can produce non-minimal diffs.

        Args:
          text1: Old string to be diffed.
          text2: New string to be diffed.
          deadline: Time when the diff should be complete by.

        Returns:
          Array of changes.
        Fr   r   r   )
diff_linesToCharsr+   diff_charsToLinesdiff_cleanupSemanticr!   r   r1   r/   r0   pop)r   r#   r$   r&   	linearrayr*   pointercount_deletecount_inserttext_deletetext_insertsubDiffs               r   r4   zdiff_match_patch.diff_lineMode   s    %)$:$:5%$H!yueUH= 	ui0!!%( 	door*+E
"W~a D$4$44!uW~a00w"d&6&66!uW~a00w"doo51$):"nn[+uhWGMTE'L0<?'J%4|Cc'lRG    qLG' E
"* 			r   c           	         t        |      }t        |      }||z   dz   dz  }|}d|z  }dg|z  }	d|	|dz   <   |	dd }
||z
  }|dz  dk7  }d}d}d}d}t        |      D ]  }t        j                         |kD  r nt        | |z   |dz   |z
  d      D ]  }||z   }|| k(  s||k7  r|	|dz
     |	|dz      k  r	|	|dz      }n|	|dz
     dz   }||z
  }||k  r0||k  r+||   ||   k(  r |dz  }|dz  }||k  r||k  r||   ||   k(  r ||	|<   ||kD  r|dz  }||kD  r|dz  }|s||z   |z
  }|dk\  s||k  s|
|   dk7  s||
|   z
  }||k\  s| j                  |||||      c c S  t        | |z   |dz   |z
  d      D ]  }||z   }|| k(  s||k7  r|
|dz
     |
|dz      k  r	|
|dz      }n|
|dz
     dz   }||z
  }||k  r@||k  r;|| dz
     || dz
     k(  r(|dz  }|dz  }||k  r||k  r|| dz
     || dz
     k(  r(||
|<   ||kD  r|dz  }||kD  r|dz  }|r||z   |z
  }|dk\  s||k  s|	|   dk7  s|	|   }||z   |z
  }||z
  }||k\  s| j                  |||||      c c S   | j                  |f| j
                  |fgS )a  Find the 'middle snake' of a diff, split the problem in two
          and return the recursively constructed diff.
          See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.

        Args:
          text1: Old string to be diffed.
          text2: New string to be diffed.
          deadline: Time at which to bail if not yet complete.

        Returns:
          Array of diff tuples.
        r   r-   r   r   N)r1   ranger   diff_bisectSplitr0   r/   )r   r#   r$   r&   text1_lengthtext2_lengthmax_dv_offsetv_lengthv1v2deltafrontk1startk1endk2startk2enddk1	k1_offsetx1y1	k2_offsetx2k2y2s                             r   r5   zdiff_match_patch.diff_bisect  s    5z5z,q0Q6u9TH_8a<U|+ 	Q u A	YAyy{X% QBL!a%%-; Y$rM	!8aBy1},=9q=@Q,QIM*BIM*Q.B"W%"|*;b	USUY@V!GB!GB %"|*;b	USUY@V !#9$QJE,&qLG (5 02 5I A~)h*>2i=TVCV)ByM98#'#8#8r2x#XX5Y: QBL!a%%-; Y$rM	!8aBy1},=9q=@Q,QIM*BIM*Q.B"W%\)rcAg%a.8!GB!GB %\)rcAg%a.8 !#9$QJE,&qLG (5 02 5I A~)h*>2i=TVCV	]%]Y6)B.8#'#8#8r2x#XX=YGA	YJ !!5)D,<,<e+DEEr   c                     |d| }|d| }||d }||d }	| j                  ||d|      }
| j                  ||	d|      }|
|z   S )a  Given the location of the 'middle snake', split the diff in two parts
        and recurse.

        Args:
          text1: Old string to be diffed.
          text2: New string to be diffed.
          x: Index of split point in text1.
          y: Index of split point in text2.
          deadline: Time at which to bail if not yet complete.

        Returns:
          Array of diff tuples.
        NF)r+   )r   r#   r$   xyr&   text1atext2atext1btext2br*   diffsbs               r   rO   z!diff_match_patch.diff_bisectSpliti  sd     rrqrqr vvuh?x@v~r   c                 r    g i j                  d       fd}d ||      }d ||      }||fS )a  Split two texts into an array of strings.  Reduce the texts to a string
        of hashes where each Unicode character represents one line.

        Args:
          text1: First string.
          text2: Second string.

        Returns:
          Three element tuple, containing the encoded text1, the encoded text2 and
          the array of unique strings.  The zeroth element of the array of unique
          strings is intentionally blank.
        r   c                    g }d}d}|t        |       dz
  k  r| j                  d|      }|dk(  rt        |       dz
  }| ||dz    }|v r|j                  t        |                nft              k(  r| |d }t        |       }j                  |       t              dz
  |<   |j                  t        t              dz
               |dz   }|t        |       dz
  k  rdj	                  |      S )aK  Split a text into an array of strings.  Reduce the texts to a string
            of hashes where each Unicode character represents one line.
            Modifies linearray and linehash through being a closure.

            Args:
              text: String to encode.

            Returns:
              Encoded string.
            r   r   r   
Nr   )r1   r2   r!   chrjoin)textchars	lineStartlineEndline	lineArraylineHashmaxLiness        r   diff_linesToCharsMungezBdiff_match_patch.diff_linesToChars.<locals>.diff_linesToCharsMunge  s     E IGCIM)))D)4b=!$i!mGI!48#LLXd^!459~1#IJ/"%d)$$T*%(^a%7HTNLLS^a%7!89#aK	! CIM)" 775>!r   i*,
 i )r!   )	r   r#   r$   r{   chars1chars2rx   ry   rz   s	         @@@r   rB   z"diff_match_patch.diff_linesToChars  sR     	 	"	"J '.'.	**r   c                     t        t        |            D ]J  }g }||   d   D ]  }|j                  |t        |                ! ||   d   dj	                  |      f||<   L y)zRehydrate the text in a diff from a string of line hashes to real lines
        of text.

        Args:
          diffs: Array of diff tuples.
          lineArray: Array of unique strings.
        r   r   r   N)rN   r1   r!   ordrr   )r   r*   rx   r8   rs   chars         r   rC   z"diff_match_patch.diff_charsToLines  sk     s5z" 	4ADa 2Ic$i012aRWWT]3E!H		4r   c                     |r|r|d   |d   k7  ryd}t        t        |      t        |            }|}d}||k  r#||| ||| k(  r|}|}n|}||z
  dz  |z   }||k  r#|S )zDetermine the common prefix of two strings.

        Args:
          text1: First string.
          text2: Second string.

        Returns:
          The number of characters common to the start of each string.
        r   r-   minr1   )r   r#   r$   
pointermin
pointermax
pointermidpointerstarts          r   r   z"diff_match_patch.diff_commonPrefix  s     EU1Xq%9 
USZ0

:%\*-|J1OO'
)'
$z1a7*DJ :% r   c                     |r|r|d   |d   k7  ryd}t        t        |      t        |            }|}d}||k  r=|| t        |      |z
   || t        |      |z
   k(  r|}|}n|}||z
  dz  |z   }||k  r=|S )zDetermine the common suffix of two strings.

        Args:
          text1: First string.
          text2: Second string.

        Returns:
          The number of characters common to the end of each string.
        r   r   r-   r   )r   r#   r$   r   r   r   
pointerends          r   r   z"diff_match_patch.diff_commonSuffix  s     EU2Y%)%; 
USZ0


:%zkCJ$;<*s5zJ'>?@ (
'
'
$z1a7*DJ :% r   c                    t        |      }t        |      }|dk(  s|dk(  ry||kD  r|| d }n
||k  r|d| }t        ||      }||k(  r|S d}d}	 || d }|j                  |      }	|	dk(  r|S ||	z  }|	dk(  s|| d |d| k(  r|}|dz  }<)a  Determine if the suffix of one string is the prefix of another.

        Args:
          text1 First string.
          text2 Second string.

        Returns:
          The number of characters common to the end of the first
          string and the start of the second string.
        r   Nr   r   )r1   r   r2   )
r   r#   r$   rP   rQ   text_lengthbestlengthpatternfounds
             r   diff_commonOverlapz#diff_match_patch.diff_commonOverlap
  s     5z5z1 1,&<-.)EL(-<(E,5E>
 VGHoGJJw'E{eOFzUF78_gv>! r   c                      j                   dk  ryt        |      t        |      kD  r||}}n||}}t        |      dk  st        |      dz  t        |      k  ry fd} |||t        |      dz   dz        } |||t        |      dz   dz        }|s|sy|s|}n'|s|}n"t        |d         t        |d         kD  r|}n|}t        |      t        |      kD  r	|\  }	}
}}}n|\  }}}	}
}|	|
|||fS )a  Do the two texts share a substring which is at least half the length of
        the longer text?
        This speedup can produce non-minimal diffs.

        Args:
          text1: First string.
          text2: Second string.

        Returns:
          Five element Array, containing the prefix of text1, the suffix of text1,
          the prefix of text2, the suffix of text2 and the common middle.  Or None
          if there was no match.
        r   Nr   r-   c                    | ||t        |       dz  z    }d}|j                  |      }|dk7  rj                  | |d ||d       }j                  | d| |d|       }t        |      ||z   k  r1|||z
  | ||||z    z   }| d||z
   }| ||z   d }	|d||z
   }
|||z   d }|j                  ||dz         }|dk7  rt        |      dz  t        |       k\  r	
|fS y)au  Does a substring of shorttext exist within longtext such that the
            substring is at least half the length of longtext?
            Closure, but does not reference any external variables.

            Args:
              longtext: Longer string.
              shorttext: Shorter string.
              i: Start index of quarter length substring within longtext.

            Returns:
              Five element Array, containing the prefix of longtext, the suffix of
              longtext, the prefix of shorttext, the suffix of shorttext and the
              common middle.  Or None if there was no match.
            r   r   r   Nr   r-   )r1   r2   r   r   )r6   r7   r8   seedbest_commonjprefixLengthsuffixLengthbest_longtext_abest_longtext_bbest_shorttext_abest_shorttext_br   s               r   diff_halfMatchIz8diff_match_patch.diff_halfMatch.<locals>.diff_halfMatchIL  sN    ACMQ$6 67DKt$Ar'#55hqrlIabMR#55hrlIbqMR{#l\&AA!!l"2Q7#AL(89:   '//A\1A&BO&.q</?/A&BO'01C1|3C'D$'0\1A1C'D$NN4Q/ r' ;!#s8}4##$$  r      r   )r	   r1   )r   r#   r$   r6   r7   r   hm1hm2r9   r:   r;   r<   r=   r>   s   `             r   r3   zdiff_match_patch.diff_halfMatch4  s    !u:E
"%*EyX%*EYx=1I 2S] B)	X h	CMA4E!3KLh	CMA4E!3KL3BB 3q6{SQ[( u:E
"?A<Wgw?A<Wgw'7J??r   c                 `   d}g }d}d}d\  }}d\  }}	|t        |      k  rM||   d   | j                  k(  r#|j                  |       |d}}|	d}	}||   d   }n ||   d   | j                  k(  r|t        ||   d         z  }n|	t        ||   d         z  }	|rt        |      t	        ||      k  rt        |      t	        ||	      k  r|j                  |d   | j                  |f       | j                  ||d   dz      d   f||d   dz   <   |j                          t        |      r|j                          t        |      r|d   }nd}d\  }}d\  }}	d}d}|dz  }|t        |      k  rM|r| j                  |       | j                  |       d}|t        |      k  r||dz
     d   | j                  k(  r\||   d   | j                  k(  rF||dz
     d   }
||   d   }| j                  |
|      }| j                  ||
      }||k\  r|t        |
      dz  k\  s|t        |      dz  k\  r|j                  || j                  |d| f       | j                  |
dt        |
      |z
   f||dz
  <   | j                  ||d f||dz   <   |dz  }n|t        |
      dz  k\  s|t        |      dz  k\  r`|j                  || j                  |
d| f       | j                  |dt        |      |z
   f||dz
  <   | j                  |
|d f||dz   <   |dz  }|dz  }|dz  }|t        |      k  ryy)	zReduce the number of edits by eliminating semantically trivial
        equalities.

        Args:
          diffs: Array of diff tuples.
        FNr   )r   r   r   r   Tg       @)r1   r   r!   r/   maxinsertr0   rE   r"   diff_cleanupSemanticLosslessr   )r   r*   changes
equalitieslastEqualityrG   length_insertions1length_deletions1length_insertions2length_deletions2deletion	insertionoverlap_length1overlap_length2s                 r   rD   z%diff_match_patch.diff_cleanupSemantic  s    
04--04--E
"W~a DOO3!!'*9KQ$6"7H!#4!$W~a0>!$(8(88&#eGnQ.?*@@&%U7^A->)??% !L)S1CEV-WW L)S1CEV-WW LLB$2B2BL1QR ((jnq01!41E*R.1,-
 NN$:"(:",R."$<@9&(9<@9&(9#'L"GqLGW E
"\ ""5)))%0 E
"gk"1%)9)99'N1%)9)99 1-a0!'N1-	"&"9"9(I"N"&"9"9)X"N"o5'3x=3+>>*c)ns.BB #dooyAQ/7R%S !,,$%Fs8}'FG.gk*
 !,,%o&67.gk*  1 (3x=3+>>*c)ns.BB #doox@P7Q%R !,,%&HI(HI.gk*
 !,,$_%56.gk*  11qLG_ E
"r   c                       fd}d}|t        |      dz
  k  rd||dz
     d    j                  k(  r2||dz      d    j                  k(  r||dz
     d   }||   d   }||dz      d   } j                  ||      }|r|| d }|d|  }||d|  z   }||z   }|}	|}
|} |||       |||      z   }|rU|rS|d   |d   k(  rH||d   z  }|dd |d   z   }|dd } |||       |||      z   }||k\  r|}|}	|}
|}|r|r|d   |d   k(  rH||dz
     d   |	k7  rO|	r||dz
     d   |	f||dz
  <   n||dz
  = |dz  }||   d   |
f||<   |r||dz      d   |f||dz   <   n||dz   = |dz  }|dz  }|t        |      dz
  k  rcyy)a	  Look for single edits surrounded on both sides by equalities
        which can be shifted sideways to align the edit to a word boundary.
        e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.

        Args:
          diffs: Array of diff tuples.
        c                    | r|sy| d   }|d   }|j                          }|j                          }|xr |j                         }|xr |j                         }|xr |dk(  xs |dk(  }|xr |dk(  xs |dk(  }	|xr j                  j                  |       }
|	xr j                  j                  |      }|
s|ry|s|	ry|r|s|ry|s|ry	|s|ry
y)a  Given two strings, compute a score representing whether the
            internal boundary falls on logical boundaries.
            Scores range from 6 (best) to 0 (worst).
            Closure, but does not reference any external variables.

            Args:
              one: First string.
              two: Second string.

            Returns:
              The score.
               r   r   rp      r   r   r-   r   )isalnumisspaceBLANKLINEENDsearchBLANKLINESTARTmatch)onetwochar1char2nonAlphaNumeric1nonAlphaNumeric2whitespace1whitespace2
lineBreak1
lineBreak2
blankLine1
blankLine2r   s               r   diff_cleanupSemanticScorezPdiff_match_patch.diff_cleanupSemanticLossless.<locals>.diff_cleanupSemanticScore  s     c GEFE#(==?2#(==?2*>u}}K*>u}}K$I%4-*H5D=J$I%4-*H5D=J#E(9(9(@(@(EJ#F(;(;(A(A#(FJZz!++!%5r   r   r   N)r1   r   r   )r   r*   r   rG   	equality1edit	equality2commonOffsetcommonStringbestEquality1bestEditbestEquality2	bestScorescores   `             r   r   z-diff_match_patch.diff_cleanupSemanticLossless  s\   0	d E
Q&gk"1%8'A+&q)T__< "'A+.q1	W~a(!'A+.q1	  $55iF#'#7L ).L= 9I'$~*>>D ,y 8I !* )5t-dI>?	 yT!W	!-Da(I8il2D )!"I5!41$	BCE 	)$)	(1#'(1 yT!W	!-D 1%a(M9$.3GaK.@.C]-Sgk*!'A+.1&+GnQ&7%BE'N$.3GaK.@.C]-Sgk*!'A+.1qLGi E
Q&r   z\n\r?\n$z^\r?\n\r?\nc                    d}g }d}d}d}d}d}d}	|t        |      k  rU||   d   | j                  k(  rIt        ||   d         | j                  k  r"|s|	r|j                  |       |}|	}||   d   }ng }d}dx}}	n||   d   | j                  k(  rd}	nd}|r|r|r|r|	s)t        |      | j                  dz  k  r||z   |z   |	z   dk(  r|j                  |d   | j                  |f       | j                  ||d   dz      d   f||d   dz   <   |j                          d}|r	|rdx}}	g }n2t        |      r|j                          t        |      r|d   }nd}dx}}	d}|dz  }|t        |      k  rU|r| j                  |       yy)	zReduce the number of edits by eliminating operationally trivial
        equalities.

        Args:
          diffs: Array of diff tuples.
        FNr   r   Tr-   r   r   )	r1   r   r
   r!   r0   r   r/   rE   r"   )
r   r*   r   r   r   rG   pre_inspre_delpost_inspost_dels
             r   diff_cleanupEfficiencyz'diff_match_patch.diff_cleanupEfficiency  s    
E
"W~a DOO3uW~a()D,>,>> %%g.&G&G#(>!#4L "$J#'L&++8>!$(8(88#H#H  X(\*T-?-?!-CC$w.9HDJ LLB$2B2BL1QR ((jnq01!41E*R.1,- NN$#'L7.228%'
z?&NN,z?&0nG&(G.338"GqLGu E
"x ""5) r   c           	         |j                  | j                  df       d}d}d}d}d}|t        |      k  r$||   d   | j                  k(  r|dz  }|||   d   z  }|dz  }n||   d   | j                  k(  r|dz  }|||   d   z  }|dz  }n||   d   | j                  k(  r||z   dkD  rJ|dk7  r|dk7  r| j                  ||      }|dk7  ro||z
  |z
  dz
  }|dk\  r/||   d   | j                  k(  r||   d   ||   d   |d| z   f||<   n&|j                  d| j                  |d| f       |dz  }||d }||d }| j                  ||      }|dk7  r&||   d   || d ||   d   z   f||<   |d|  }|d|  }g }	t        |      dk7  r|	j                  | j                  |f       t        |      dk7  r|	j                  | j                  |f       |||z   z  }|	||||z   |z    |t        |	      dz   z  }nK|dk7  rA||dz
     d   | j                  k(  r)||dz
     d   ||dz
     d   ||   d   z   f||dz
  <   ||= n|dz  }d}d}d}d}|t        |      k  r$|d   d   dk(  r|j                          d}
d}|t        |      dz
  k  rb||dz
     d   | j                  k(  r1||dz      d   | j                  k(  r||   d   j                  ||dz
     d         rt||dz
     d   dk7  r]||   d   ||dz
     d   ||   d   dt        ||dz
     d           z   f||<   ||dz      d   ||dz
     d   ||dz      d   z   f||dz   <   ||dz
  = d}
n||   d   j                  ||dz      d         rd||dz
     d   ||dz
     d   ||dz      d   z   f||dz
  <   ||   d   ||   d   t        ||dz      d         d ||dz      d   z   f||<   ||dz   = d}
|dz  }|t        |      dz
  k  rb|
r| j                  |       yy)zReorder and merge like edit sections.  Merge equalities.
        Any edit section can move as long as it doesn't cross an equality.

        Args:
          diffs: Array of diff tuples.
        r   r   r   Nr   FT)r!   r   r1   r/   r0   r   r   r   rE   endswith
startswithr"   )r   r*   rG   rH   rI   rJ   rK   r'   rg   new_opsr   s              r   r"   z"diff_match_patch.diff_cleanupMerge  s    	door*+E
"W~a D$4$44!uW~a001w"d&6&66!uW~a001w"doo5,.2#q(\Q->'+'='=k;'W'1, ', 6 E IA Av%(1+*H$)!HQK$)!HQK+m|2L$L,"a
 !&$%]l9S'T!" !(1*5lm*DK*5lm*DK'+'='=k;'W'1, %gq 1 +\MN ;eGnQ>O O.E'N +6n}*EK*5n}*EK G;'1,(8(8+'FG;'1,(8(8+'FG|l::GMTE'Gl$:\$IJs7|a//G\eGaK&8&;t&N gk*1-gk*1-gq0AA*E'A+& gqLG    y E
"| 9Q<2IIK
 E
Q&gk"1%8'A+&q)T__< >!$--eGaK.@.CDWq[)!,2!'N1-!'A+.q1#GnQ/0M3uWq[7I!7L3M2MNO*g "'A+.q1!'A+.q1E'A+4Fq4II.gk* gk*"G7^A&11%!2DQ2GH gk*1-gk*1-gk0B10EE*E'A+&
 gq)gq)#eGaK.@.C*D*FG!,Q/0&E'N
 gk*"GqLGC E
Q&H ""5) r   c                 8   d}d}d}d}t        t        |            D ]O  }||   \  }}	|| j                  k7  r|t        |	      z  }|| j                  k7  r|t        |	      z  }||kD  r n|}|}Q t        |      k7  r||   d   | j                  k(  r|S |||z
  z   S )a  loc is a location in text1, compute and return the equivalent location
        in text2.  e.g. "The cat" vs "The big cat", 1->1, 5->8

        Args:
          diffs: Array of diff tuples.
          loc: Location within text1.

        Returns:
          Location within text2.
        r   )rN   r1   r/   r0   )
r   r*   locr|   r}   last_chars1last_chars2rg   oprs   s
             r   diff_xIndexzdiff_match_patch.diff_xIndexH  s     s5z" 		!AqJRT%%%#d)#T%%%#d)#| K K		! u:?uQx{d.>.>>cK/00r   c                    g }|D ]  \  }}dt        |      k(  r|j                  dd      j                  dd      j                  dd      j                  dd	      }|| j                  k(  r|j                  d
|z         {|| j                  k(  r|j                  d|z         || j
                  k(  s|j                  d|z          dj                  |      S )zConvert a diff array into a pretty HTML report.

        Args:
          diffs: Array of diff tuples.

        Returns:
          HTML representation.
        r   &z&amp;<z&lt;>z&gt;rp   z
&para;<br>z)<ins style="background:#e6ffe6;">%s</ins>z)<del style="background:#ffe6e6;">%s</del>z<span>%s</span>r   )r1   replacer/   r!   r0   r   rr   )r   r*   htmlr   datars   s         r   diff_prettyHtmlz diff_match_patch.diff_prettyHtmlh  s      	6HBCI~S'*f%f%|,	  T%%%G$NOt'''G$NOt&-45	6 wwt}r   c                 ~    g }|D ]&  \  }}|| j                   k7  s|j                  |       ( dj                  |      S )zCompute and return the source text (all equalities and deletions).

        Args:
          diffs: Array of diff tuples.

        Returns:
          Source text.
        r   )r/   r!   rr   r   r*   rs   r   r   s        r   
diff_text1zdiff_match_patch.diff_text1  F      	"HBT%%%D!	" wwt}r   c                 ~    g }|D ]&  \  }}|| j                   k7  s|j                  |       ( dj                  |      S )zCompute and return the destination text (all equalities and insertions).

        Args:
          diffs: Array of diff tuples.

        Returns:
          Destination text.
        r   )r0   r!   rr   r   s        r   
diff_text2zdiff_match_patch.diff_text2  r   r   c                    d}d}d}|D ]d  \  }}|| j                   k(  r|t        |      z  }$|| j                  k(  r|t        |      z  }B|| j                  k(  sR|t	        ||      z  }d}d}f |t	        ||      z  }|S )zCompute the Levenshtein distance; the number of inserted, deleted or
        substituted characters.

        Args:
          diffs: Array of diff tuples.

        Returns:
          Number of changes.
        r   )r/   r1   r0   r   r   )r   r*   levenshtein
insertions	deletionsr   r   s          r   diff_levenshteinz!diff_match_patch.diff_levenshtein  s     
	 		HBT%%%c$i'
t'''SY&	t&s:y99
			 	s:y11r   c           	         g }|D ]  \  }}|| j                   k(  rD|j                  d      }|j                  dt        j                  j                  |d      z          Y|| j                  k(  r0|j                  dt        |j                  d            dz  z         || j                  k(  s|j                  dt        |j                  d            dz  z          dj                  |      S )	aw  Crush the diff into an encoded string which describes the operations
        required to transform text1 into text2.
        E.g. =3	-2	+ing  -> Keep 3 chars, delete 2 chars, insert 'ing'.
        Operations are tab-separated.  Inserted text is escaped using %xx notation.

        Args:
          diffs: Array of diff tuples.

        Returns:
          Delta text.
        utf-8+!~*'();/?:@&=+$,# z-%d	utf-16-ber-   z=%d	)
r/   encoder!   urllibparsequoter0   r1   r   rr   r   s        r   diff_toDeltazdiff_match_patch.diff_toDelta  s      	JHBT%%%{{7+C&,,"4"4T;O"PPQt'''ES[)A%Ba%GHIt&ES[)A%Ba%GHI	J yyr   c                    g }|j                  d      }d}|j                  d      }|D ]  }|dk(  r	|dd }|d   dk(  r=t        j                  j	                  |      }|j                  | j                  |f       S|d   dk(  s|d   d	k(  r	 t        |      }	|	dk  rt        d|z         ||||	dz  z    j                  d      }
||	dz  z  }|d   d	k(  r|j                  | j                  |
f       |j                  | j                  |
f       t        d|d   z          |t        |      k7  rt        d|t        |      fz        |S # t        $ r t        d
|z         w xY w)ab  Given the original text1, and an encoded string which describes the
        operations required to transform text1 into text2, compute the full diff.

        Args:
          text1: Source string for the diff.
          delta: Delta text.

        Returns:
          Array of diff tuples.

        Raises:
          ValueError: If invalid input.
        r   r   r   r   r   Nr   -=z"Invalid number in diff_fromDelta: z#Negative number in diff_fromDelta: r-   z*Invalid diff operation in diff_fromDelta: z9Delta length (%d) does not equal source text length (%d).)r   splitr   r   unquoter!   r/   intr   decoder   r0   r1   )r   r#   rW   r*   as_utf16rG   tokenstokenparamnrs   s              r   diff_fromDeltazdiff_match_patch.diff_fromDelta  s    <<,T" 	E{ !"IEQx3,,U3d..67qSE!HOSE
A q5$%JU%RSS'AE/:AA+N1q5 8s?LL$//4!89LL$"2"2D!9: !@58K 3	8 c(m#KCM*+  ) " S$%IE%QRRSs   EE$c           	          |dk(  s|dk(  rt        d      t        dt        |t        |                  }||k(  ry|sy|||t        |      z    |k(  r|S | j	                  |||      }|S )a  Locate the best instance of 'pattern' in 'text' near 'loc'.

        Args:
          text: The text to search.
          pattern: The pattern to search for.
          loc: The location to search around.

        Returns:
          Best match index or -1.
        NzNull inputs. (match_main)r   r   )r   r   r   r1   match_bitap)r   rs   r   r   r   s        r   
match_mainzdiff_match_patch.match_main
  s|     4<7d?899!Sc$i()7?#c'l*+w6J $$T7C8ELr   c                 T     j                        } fd} j                  }|j                        }|dk7  rIt         |d|      |      }|j	                  t              z         }|dk7  rt         |d|      |      }dt              dz
  z  }d}t              t        |      z   }	d}
t        t                    D ]\  }d}|	}||k  r% |||z         |k  r|}n|}	|	|z
  dz  |z   }||k  r%|}	t        d|z
  dz         }t        |z   t        |            t              z   }dg|dz   z  }d|z  dz
  ||dz   <   t        ||dz
  d      D ]  }t        |      |dz
  k  rd}n|j                  ||dz
     d      }|dk(  r||dz      dz  dz  |z  ||<   n2||dz      dz  dz  |z  |
|dz      |
|   z  dz  dz  z  |
|dz      z  ||<   ||   |z  s |||dz
        }||k  s|}|dz
  }|kD  rt        ddz  |z
        } n  ||dz         |kD  r |S |}
_ |S )a)  Locate the best instance of 'pattern' in 'text' near 'loc' using the
        Bitap algorithm.

        Args:
          text: The text to search.
          pattern: The pattern to search for.
          loc: The location to search around.

        Returns:
          Best match index or -1.
        c                     t        |       t              z  }t        |z
        }j                  s
|xr dxs |S ||t        j                        z  z   S )aI  Compute and return the score for a match with e errors and x location.
            Accesses loc and pattern through being a closure.

            Args:
              e: Number of errors in match.
              x: Location of match.

            Returns:
              Overall score for match (0.0 = good, 1.0 = bad).
            r   )floatr1   absr   )erg   accuracy	proximityr   r   r   s       r   match_bitapScorez6diff_match_patch.match_bitap.<locals>.match_bitapScore;  sX     Qx#g,.HC!GI&& (S4H4y51D1D+EEFFr   r   r   r   Nr-   )	match_alphabetr   r2   r   rfindr1   rN   r   get)r   rs   r   r   sr  score_thresholdbest_loc	matchmaskbin_maxlast_rdr]   bin_minbin_midstartfinishrdr   	charMatchr   s   ` ``                r   r  zdiff_match_patch.match_bitap(  s   " (	G& ..99Wc*r>!"21h"?QOzz'3W+=>H2~"%&6q(&C_"U #g,*+	g,T*s7|$ 3	A GGG##AsW}5H%G%G"W,2W< G# G3=1,-EwD	2S\AF
#B1f\BvzN6519b1 "t9A% !I !d1q5k1 5I6 Qi1n1Y>BqE a!e9>Q.);$QU^gaj8Q>!CE!!a%.) qE
 a59$,QA6E /*/#$q5#c>$'1s7X+=$>E "7":  As+o= Gg3	h r   c                     i }|D ]  }d||<   	 t        t        |            D ]$  }|||   xx   dt        |      |z
  dz
  z  z  cc<   & |S )zInitialise the alphabet for the Bitap algorithm.

        Args:
          pattern: The text to encode.

        Returns:
          Hash of character locations.
        r   r   )rN   r1   )r   r   r  r   r8   s        r   r  zdiff_match_patch.match_alphabet  sc      	DAdG	s7|$ 	9AgajMQ3w<!#3a#788M	9r   c                    t        |      dk(  ry||j                  |j                  |j                  z    }d}|j                  |      |j	                  |      k7  r| j
                  dk(  s2t        |      | j
                  | j                  z
  | j                  z
  k  r|| j                  z  }|t        d|j                  |z
        |j                  |j                  z   |z    }|j                  |      |j	                  |      k7  rC| j
                  dk(  rxt        |      | j
                  | j                  z
  | j                  z
  k  r|| j                  z  }|t        d|j                  |z
        |j                   }|r| j                  |fg|j                  dd ||j                  |j                  z   |j                  |j                  z   |z    }|r'|j                  j                  | j                  |f       |xj                  t        |      z  c_        |xj                  t        |      z  c_        |xj                  t        |      t        |      z   z  c_        |xj                  t        |      t        |      z   z  c_        y)zIncrease the context until it is unique,
        but don't let the pattern expand beyond Match_MaxBits.

        Args:
          patch: The patch to grow.
          text: Source text.
        r   N)r1   start2length1r2   r  r   r   r   r   r*   r!   start1length2)r   patchrs   r   paddingprefixsuffixs          r   patch_addContextz!diff_match_patch.patch_addContext  s    t9>u||ellU]]&BC ii DJJw$77!#7|d0043D3DDtGXGXXXt(((GAu||g-.1MPW1WG ii DJJw$77!#7|d0043D3DDtGXGXXX 	4$$$ c!U\\G34u||D $89EKKOLL5==(5<<%--+G'+Q
 KK89 	F#F#Vs6{22Vs6{22r   c                    d}d}t        |t              rXt        |t              rH|F|}| j                  ||d      }t        |      dkD  r| j	                  |       | j                  |       nt        |t              r|||}| j                  |      }ngt        |t              rt        |t              r||}|}n@t        |t              r%t        |t              rt        |t              r|}|}nt        d      |sg S g }t               }d}d}	|}
|}t        t        |            D ]Z  }||   \  }}t        |j                        dk(  r|| j                  k7  r||_        |	|_        || j                  k(  rL|j                  j!                  ||          |xj"                  t        |      z  c_        |d|	 |z   ||	d z   }n|| j$                  k(  rT|xj&                  t        |      z  c_        |j                  j!                  ||          |d|	 ||	t        |      z   d z   }n|| j                  k(  rt        |      d| j(                  z  k  rt        |j                        dk7  rkt        |      |dz   k7  rZ|j                  j!                  ||          |xj&                  t        |      z  c_        |xj"                  t        |      z  c_        || j                  k(  rdt        |      d| j(                  z  k\  rIt        |j                        dk7  r1| j+                  ||
       |j!                  |       t               }|}
|	}|| j                  k7  r|t        |      z  }|| j$                  k7  sM|	t        |      z  }	] t        |j                        dk7  r#| j+                  ||
       |j!                  |       |S )a_  Compute a list of patches to turn text1 into text2.
        Use diffs if provided, otherwise compute it ourselves.
        There are four ways to call this function, depending on what data is
        available to the caller:
        Method 1:
        a = text1, b = text2
        Method 2:
        a = diffs
        Method 3 (optimal):
        a = text1, b = diffs
        Method 4 (deprecated, use method 3):
        a = text1, b = text2, c = diffs

        Args:
          a: text1 (methods 1,3,4) or Array of diff tuples for text1 to
              text2 (method 2).
          b: text2 (methods 1,4) or Array of diff tuples for text1 to
              text2 (method 3) or undefined (method 2).
          c: Array of diff tuples for text1 to text2 (method 4) or
              undefined (methods 1,2,3).

        Returns:
          Array of Patch objects.
        NTr-   z"Unknown call format to patch_make.r   r   )
isinstancestrr+   r1   rD   r   listr   r   	patch_objrN   r*   r   r*  r(  r/   r!   r+  r0   r)  r   r0  )r   abcr#   r*   patchesr,  char_count1char_count2prepatch_textpostpatch_textrg   	diff_type	diff_texts                  r   
patch_makezdiff_match_patch.patch_make  sj   2 a*Q"4 ENN5!T2E5zA~))%0++E24 QY19 EOOE*E3Jq$$7AIEE3Jq#$6:a;N EEABBIs5z" 3	.A%*1X"Y	5;;1$doo)E**D,,,""58,Y/"<K0 $[\23 
 d...Y/""58,"<K0$[3y>%A%CDE 
 T__,	Na$*;*;&;;$)J!a%' ""58,Y/Y/DOO+I!dFWFWBW0Wu{{#q())%?NN5)%KE
 %3M"-K D,,,s9~-D,,,s9~-g3	.l u{{q !!%7NN5!r   c                     g }|D ]u  }t               }|j                  dd |_        |j                  |_        |j                  |_        |j                  |_        |j
                  |_        |j                  |       w |S )zGiven an array of patches, return another array that is identical.

        Args:
          patches: Array of Patch objects.

        Returns:
          Array of Patch objects.
        N)r5  r*   r*  r(  r)  r+  r!   )r   r9  patchesCopyr,  	patchCopys        r   patch_deepCopyzdiff_match_patch.patch_deepCopyJ  st      	*E!I#kk!nIO$||I$||I %I %Iy)	* r   c                 
   |s|g fS | j                  |      }| j                  |      }||z   |z   }| j                  |       d}g }|D ]  }|j                  |z   }| j	                  |j
                        }d}	t        |      | j                  kD  rl| j                  ||d| j                   |      }
|
dk7  rZ| j                  ||| j                   d |t        |      z   | j                  z
        }	|	dk(  s|
|	k\  rd}
n| j                  |||      }
|
dk(  r.|j                  d       ||j                  |j                  z
  z  }|j                  d       |
|z
  }|	dk(  r||
|
t        |      z    }n||
|	| j                  z    }||k(  r5|d|
 | j                  |j
                        z   ||
t        |      z   d z   }s| j                  ||d      }t        |      | j                  kD  r:| j                  |      t        t        |            z  | j                   kD  rd|d<   | j#                  |       d}|j
                  D ]  \  }}|| j$                  k7  r| j'                  ||      }|| j(                  k(  r|d|
z    |z   ||
|z   d z   }n<|| j*                  k(  r-|d|
z    ||
| j'                  ||t        |      z         z   d z   }|| j*                  k7  s|t        |      z  }  |t        |      t        |        }||fS )aW  Merge a set of patches onto the text.  Return a patched text, as well
        as a list of true/false values indicating which patches were applied.

        Args:
          patches: Array of Patch objects.
          text: Old text.

        Returns:
          Two element Array, containing the new text and an array of boolean values.
        r   r   NFT)rD  patch_addPaddingpatch_splitMaxr(  r   r*   r1   r   r  r!   r+  r)  r   r+   r   r  r   r   r   r   r/   r0   )r   r9  rs   nullPaddingrW   resultsr,  expected_locr#   end_loc	start_locr$   r*   index1r   r   index2s                    r   patch_applyzdiff_match_patch.patch_apply_  ss    ": %%g.++G4T!K/G$  I	4E <<%/LOOEKK0EG5zD... !OO% 4$"4"45|	 ?"oot11134$s5z1D4F4FFG
 "}	W(<$&	 OOD%F	Bu%66 t$!L0b= YU-CDE Wt7I7I-IJEE> Zi(//%++67y3u:5789  !NN5%?EE
T%7%77 11%85U;LL445 ',99%@!"(- 4HB!T__4)-)9)9%)H!T%5%55$()=9v+=$>&*%+&*9v+=+?&@%A !%
 "$t'7'7!7$()=9v+=$>&*(1*.*:*:5&3t9BT*U)V )X'&%& !%  "T%5%55 &#d) 3%4oI	4V C$K(8'89gr   c                    | j                   }d}t        d|dz         D ]  }|t        |      z  } |D ],  }|xj                  |z  c_        |xj                  |z  c_        . |d   }|j
                  }|r|d   d   | j                  k7  rs|j                  d| j                  |f       |xj                  |z  c_        |xj                  |z  c_        |xj                  |z  c_        |xj                  |z  c_	        n|t        |d   d         kD  r|t        |d   d         z
  }|t        |d   d         d |d   d   z   }|d   d   |f|d<   |xj                  |z  c_        |xj                  |z  c_        |xj                  |z  c_        |xj                  |z  c_	        |d   }|j
                  }|r|d   d   | j                  k7  rI|j                  | j                  |f       |xj                  |z  c_        |xj                  |z  c_	        |S |t        |d   d         kD  rY|t        |d   d         z
  }|d   d   |d| z   }|d   d   |f|d<   |xj                  |z  c_        |xj                  |z  c_	        |S )a  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.
        r   r   r   Nr   )r   rN   rq   r*  r(  r*   r   r   r)  r+  r1   r!   )	r   r9  paddingLengthrH  rg   r,  r*   extraLengthnewTexts	            r   rF  z!diff_match_patch.patch_addPadding  sf    ))q-!+, 	"A3q6!K	"  	*ELLM)LLLM)L	*
 
at6LLT__k:;LLM)LLLM)LMM]*MMM]*MSq!--'#eAhqk*::K!#eAhqk"2"45aCGaW-E!HLLK'LLLK'LMM[(MMM[(M b	!7LL$//;78MM]*MMM]*M  Sr1..'#eBil*;;KBil[+%>>Gr1w/E"IMM[(MMM[(Mr   c                 	   | j                   }|dk(  ryt        t        |            D ]  }||   j                  |k  r||   }||= |dz  }|j                  }|j
                  }d}t        |j                        dk7  sWt               }d}	|t        |      z
  |_        |t        |      z
  |_        |r>t        |      x|_        |_        |j                  j                  | j                  |f       t        |j                        dk7  r|j                  || j                  z
  k  rr|j                  d   \  }
}|
| j                  k(  rd|xj                  t        |      z  c_        |t        |      z  }|j                  j                  |j                  j                  d             d}	n|
| j                  k(  rt        |j                        dk(  r|j                  d   d   | j                  k(  rkt        |      d|z  kD  rZ|xj                  t        |      z  c_        |t        |      z  }d}	|j                  j                  |
|f       |j                  d= n|d||j                  z
  | j                  z
   }|xj                  t        |      z  c_        |t        |      z  }|
| j                  k(  r-|xj                  t        |      z  c_        |t        |      z  }nd}	|j                  j                  |
|f       ||j                  d   d   k(  r|j                  d= n=|j                  d   d   |j                  d   d   t        |      d f|j                  d<   t        |j                        dk7  r|j                  || j                  z
  k  rr| j                  |j                        }|| j                   d }| j!                  |j                        d| j                   }|r|xj                  t        |      z  c_        |xj                  t        |      z  c_        t        |j                        dk7  rN|j                  d   d   | j                  k(  r/| j                  |j                  d   d   |z   f|j                  d<   n'|j                  j                  | j                  |f       |	s|dz  }|j#                  ||       t        |j                        dk7  rk y)	zLook through the patches and break up any which are longer than the
        maximum limit of the match algorithm.
        Intended to be called only from within patch_apply.

        Args:
          patches: Array of Patch objects.
        r   Nr   r   TFr-   r   )r   rN   r1   r)  r*  r(  r*   r5  r+  r!   r   r   r/   rE   r0   r   r   r   )r   r9  
patch_sizerg   bigpatchr*  r(  
precontextr,  emptyr>  r?  postcontexts                r   rG  zdiff_match_patch.patch_splitMax  s9    ''
? s7|$ S	-Aqz!!Z/qzH
FA__F__FJhnn%*!%J7%J747
OCEMEMKK&&'DE '1,
T5F5F(FF-5^^A->*Y	 D$4$44Y7#i.0**8>>+=+=a+@A %!T%5%55,1!KKN1-@	NQ^; Y7#i.0 %**Iy+AB$NN1- %.Lj5==84;L;LL%	 Y7#i.0$7!MMS^;M"c)n4F$)E**Iy+AB$q(9!(<< (q 1 !)q 1! 4 (q 1! 4S^5E F1HNN1-O '1,
T5F5F(FFX "__U[[9
'):):(:(<=
"oohnn=>Q@Q@QRMMS%55MMMS%55M5;;'1,R1Ct1V OO!KKOA.<+B
 **DOO[+IJFANN1e,S hnn%*S	-r   c                 j    g }|D ]  }|j                  t        |              dj                  |      S )zTake a list of patches and return a textual representation.

        Args:
          patches: Array of Patch objects.

        Returns:
          Text representation of patches.
        r   )r!   r3  rr   )r   r9  rs   r,  s       r   patch_toTextzdiff_match_patch.patch_toTextd  s6      	$EKKE
#	$wwt}r   c                 x   g }|s|S |j                  d      }t        |      dk7  rt        j                  d|d         }|st	        d|d   z         t               }|j                  |       t        |j                  d            |_	        |j                  d      dk(  r|xj                  dz  c_	        d|_
        nP|j                  d      dk(  rd|_
        n4|xj                  dz  c_	        t        |j                  d            |_
        t        |j                  d	            |_        |j                  d
      dk(  r|xj                  dz  c_        d|_        nP|j                  d
      dk(  rd|_        n4|xj                  dz  c_        t        |j                  d
            |_        |d= t        |      dk7  r|d   r	|d   d   }nd}t        j                  j                  |d   dd       }|dk(  r(|j                   j                  | j"                  |f       nw|dk(  r(|j                   j                  | j$                  |f       nJ|dk(  r(|j                   j                  | j&                  |f       n|dk(  rn)|dk(  rnt	        d|d|      |d= t        |      dk7  rt        |      dk7  r|S )a  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.
        rp   r   z$^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$zInvalid patch string: r   r-   r   0r   r   Nr   r    @zInvalid patch mode: 'z'
)r  r1   rer   r   r5  r!   r  groupr*  r)  r(  r+  r   r   r  r*   r/   r0   r   )r   textliner9  rs   mr,  signrw   s           r   patch_fromTextzdiff_match_patch.patch_fromTextr  sL    N~~d#$i1n@$q'JA !9DG!CDDKENN5!qwwqz?ELwwqzR! !s" !! #AGGAJqwwqz?ELwwqzR! !s" !! #AGGAJQd)q.771:DD||++DGABK83;KK&&(8(8$'?@S[KK&&(8(8$'?@S[KK&&'>?S[RZ %tT%RSSG1 d)q.9 $i1nj r   )TN)NN)-__name__
__module____qualname____doc__r   r0   r/   r   r+   r    r4   r5   rO   rB   rC   r   r   r   r3   rD   r   r`  compiler   r   r   r"   r   r   r   r   r   r   r  r  r  r  r0  r@  rD  rO  rF  rG  r[  re   r   r   r   r   "   s   
 D KKJ:x<8|7rfFP2=+~48>(TY@vwrqh 2::k*LRZZ/NL*\y*v1@6403n<kZ$*3Xun*gR8t`-DFr   r   c                       e Zd ZdZd Zd Zy)r5  z'Class representing one patch operation.c                 J    g | _         d| _        d| _        d| _        d| _        y)z(Initializes with an empty list of diffs.Nr   )r*   r*  r(  r)  r+  r   s    r   r   zpatch_obj.__init__  s%    
r   c                    | j                   dk(  rt        | j                        dz   }nY| j                   dk(  rt        | j                  dz         }n1t        | j                  dz         dz   t        | j                         z   }| j                  dk(  rt        | j                        dz   }nY| j                  dk(  rt        | j                  dz         }n1t        | j                  dz         dz   t        | j                        z   }d|d|dg}| j
                  D ]  \  }}|t        j                  k(  r|j                  d       nI|t        j                  k(  r|j                  d	       n$|t        j                  k(  r|j                  d
       |j                  d      }|j                  t        j                  j                  |d      dz           dj                  |      S )zEmulate GNU diff's format.
        Header: @@ -382,8 +481,9 @@
        Indices are printed as 1-based, not 0-based.

        Returns:
          The GNU diff string.
        r   z,0r   ,z@@ -z +z @@
r   r   r^  r   r   rp   r   )r)  r3  r*  r+  r(  r*   r   r/   r!   r0   r   r   r   r   r   rr   )r   coords1coords2rs   r   r   s         r   __str__zpatch_obj.__str__  s    <<1$++&-G\\Q$++/*G$++/*S03t||3DDG<<1$++&-G\\Q$++/*G$++/*S03t||3DDGw8

 		OHB%111C '333C '222C ;;w'DKK**41EFMN		O wwt}r   N)rf  rg  rh  ri  r   rr  rk  r   r   r5  r5    s    1 r   r5  )	ri  
__author__r`  r   r   urllib.parser   r   r5  rk  r   r   <module>ru     s9   " /
 	 
  V Vr<+ +r   