Ë ‚Ö¦i¨Eãón—dZgd¢ZddlmZddlmZddlm Z edd«Z d„Z Gd „d «Z d$d „Z d „ZGd „d«ZddlZej"d«j$fd„Zd%d„Zd„Z d&d„Zd„Z d&d„Zd„Z d'd„Zdefd„Zddefd„ZdZdZdZdZ Gd„d e!«Z"[d!„Z#d"„Z$e%d#k(re$«yy)(ae Module difflib -- helpers for computing deltas between objects. Function get_close_matches(word, possibilities, n=3, cutoff=0.6): Use SequenceMatcher to return list of the best "good enough" matches. Function context_diff(a, b): For two lists of strings, return a delta in context diff format. Function ndiff(a, b): Return a delta: the difference between `a` and `b` (lists of strings). Function restore(delta, which): Return one of the two sequences that generated an ndiff delta. Function unified_diff(a, b): For two lists of strings, return a delta in unified diff format. Class SequenceMatcher: A flexible class for comparing pairs of sequences of any type. Class Differ: For producing human-readable deltas from sequences of lines of text. Class HtmlDiff: For producing HTML side by side comparison with change highlights. ) Úget_close_matchesÚndiffÚrestoreÚSequenceMatcherÚDifferÚIS_CHARACTER_JUNKÚ IS_LINE_JUNKÚ context_diffÚ unified_diffÚ diff_bytesÚHtmlDiffÚMatché)Únlargest)Ú namedtuple)Ú GenericAliasr za b sizecó—|rd|z|z Sy)Ng@çð?©)ÚmatchesÚlengths ú /usr/lib64/python3.12/difflib.pyÚ_calculate_ratior's€Ù Ø�W‰}˜vÑ%Ð%Ø ócón—eZdZdZdd„Zd„Zd„Zd„Zd„Zdd„Z d „Z d „Z dd „Z d „Z d „Zd„Zee«Zy)rao SequenceMatcher is a flexible class for comparing pairs of sequences of any type, so long as the sequence elements are hashable. The basic algorithm predates, and is a little fancier than, an algorithm published in the late 1980's by Ratcliff and Obershelp under the hyperbolic name "gestalt pattern matching". The basic idea is to find the longest contiguous matching subsequence that contains no "junk" elements (R-O doesn't address junk). The same idea is then applied recursively to the pieces of the sequences to the left and to the right of the matching subsequence. This does not yield minimal edit sequences, but does tend to yield matches that "look right" to people. SequenceMatcher tries to compute a "human-friendly diff" between two sequences. Unlike e.g. UNIX(tm) diff, the fundamental notion is the longest *contiguous* & junk-free matching subsequence. That's what catches peoples' eyes. The Windows(tm) windiff has another interesting notion, pairing up elements that appear uniquely in each sequence. That, and the method here, appear to yield more intuitive difference reports than does diff. This method appears to be the least vulnerable to syncing up on blocks of "junk lines", though (like blank lines in ordinary text files, or maybe "

" lines in HTML files). That may be because this is the only method of the 3 that has a *concept* of "junk" . Example, comparing two strings, and considering blanks to be "junk": >>> s = SequenceMatcher(lambda x: x == " ", ... "private Thread currentThread;", ... "private volatile Thread currentThread;") >>> .ratio() returns a float in [0, 1], measuring the "similarity" of the sequences. As a rule of thumb, a .ratio() value over 0.6 means the sequences are close matches: >>> print(round(s.ratio(), 3)) 0.866 >>> If you're only interested in where the sequences match, .get_matching_blocks() is handy: >>> for block in s.get_matching_blocks(): ... print("a[%d] and b[%d] match for %d elements" % block) a[0] and b[0] match for 8 elements a[8] and b[17] match for 21 elements a[29] and b[38] match for 0 elements Note that the last tuple returned by .get_matching_blocks() is always a dummy, (len(a), len(b), 0), and this is the only case in which the last tuple element (number of elements matched) is 0. If you want to know how to change the first sequence into the second, use .get_opcodes(): >>> for opcode in s.get_opcodes(): ... print("%6s a[%d:%d] b[%d:%d]" % opcode) equal a[0:8] b[0:8] insert a[8:8] b[8:17] equal a[8:29] b[17:38] See the Differ class for a fancy human-friendly file differencer, which uses SequenceMatcher both to compare sequences of lines, and to compare sequences of characters within similar (near-matching) lines. See also function get_close_matches() in this module, which shows how simple code building on SequenceMatcher can be used to do useful work. Timing: Basic R-O is cubic time worst case and quadratic time expected case. SequenceMatcher is quadratic time for the worst case and has expected-case behavior dependent in a complicated way on how many elements the sequences have in common; best case time is linear. Ncó`—||_dx|_|_||_|j ||«y)a!Construct a SequenceMatcher. Optional arg isjunk is None (the default), or a one-argument function that takes a sequence element and returns true iff the element is junk. None is equivalent to passing "lambda x: 0", i.e. no elements are considered to be junk. For example, pass lambda x: x in " \t" if you're comparing lines as sequences of characters, and don't want to synch up on blanks or hard tabs. Optional arg a is the first of two sequences to be compared. By default, an empty string. The elements of a must be hashable. See also .set_seqs() and .set_seq1(). Optional arg b is the second of two sequences to be compared. By default, an empty string. The elements of b must be hashable. See also .set_seqs() and .set_seq2(). Optional arg autojunk should be set to False to disable the "automatic junk heuristic" that treats popular elements as junk (see module documentation for more information). N)ÚisjunkÚaÚbÚautojunkÚset_seqs)Úselfrrrrs rÚ__init__zSequenceMatcher.__init__xs/€ðvˆŒ ØÐˆŒ�”Ø ˆŒ Ø � ‰ �a˜ÕrcóH—|j|«|j|«y)z›Set the two sequences to be compared. >>> s = SequenceMatcher() >>> s.set_seqs("abcd", "bcde") >>> s.ratio() 0.75 N)Úset_seq1Úset_seq2)r!rrs rr zSequenceMatcher.set_seqs¸s€ð � ‰ �aÔØ � ‰ �aÕrcóL—||jury||_dx|_|_y)aMSet the first sequence to be compared. The second sequence to be compared is not changed. >>> s = SequenceMatcher(None, "abcd", "bcde") >>> s.ratio() 0.75 >>> s.set_seq1("bcde") >>> s.ratio() 1.0 >>> SequenceMatcher computes and caches detailed information about the second sequence, so if you want to compare one sequence S against many sequences, use .set_seq2(S) once and call .set_seq1(x) repeatedly for each of the other sequences. See also set_seqs() and set_seq2(). N)rÚmatching_blocksÚopcodes)r!rs rr$zSequenceMatcher.set_seq1Äs(€ð* �—‘‰;Ø ØˆŒØ.2Ð2ˆÔ˜t�|rcóz—||jury||_dx|_|_d|_|j «y)aMSet the second sequence to be compared. The first sequence to be compared is not changed. >>> s = SequenceMatcher(None, "abcd", "bcde") >>> s.ratio() 0.75 >>> s.set_seq2("abcd") >>> s.ratio() 1.0 >>> SequenceMatcher computes and caches detailed information about the second sequence, so if you want to compare one sequence S against many sequences, use .set_seq2(S) once and call .set_seq1(x) repeatedly for each of the other sequences. See also set_seqs() and set_seq1(). N)rr'r(Ú fullbcountÚ_SequenceMatcher__chain_b)r!rs rr%zSequenceMatcher.set_seq2Þs9€ð* �—‘‰;Ø ØˆŒØ.2Ð2ˆÔ˜tœ|؈ŒØ �‰Õrcó<—|j}ix|_}t|«D](\}}|j|g«}|j |«Œ*t «x|_}|j}|r9|j«D]}||«sŒ |j|«Œ|D]}||=Œt «x|_ }t|«} |jrQ| dk\rK| dzdz} |j«D]%\}} t| «| kDsŒ|j|«Œ'|D]}||=Œyyy)NéÈédé)rÚb2jÚ enumerateÚ setdefaultÚappendÚsetÚbjunkrÚkeysÚaddÚbpopularÚlenrÚitems) r!rr0ÚiÚeltÚindicesÚjunkrÚpopularÚnÚntestÚidxss rÚ __chain_bzSequenceMatcher.__chain_b s€ð �F‰FˆØÐˆŒ�3ä –l‰FˆAˆsØ—n‘n S¨"Ó-ˆGØ �N‰N˜1Õ ð#ô  ›EÐ!ˆŒ �TØ—‘ˆÙ Ø—x‘x–z�Ù˜#•;Ø—H‘H˜S•Mð"ó�ؘ‘Hðô#&£%Ð'ˆŒ ˜Ü �‹FˆØ �=Š=˜Q #šXؘ‘H˜q‘LˆEØ ŸY™Yž[‘ ��TÜ�t“9˜uÓ$Ø—K‘K Õ$ð)ó�ؘ‘Hñð &ˆ=rcóÞ—|j|j|j|jjf\}}}}|€ t |«}|€ t |«}||d} } } i} g} t ||«D]e}| j}i}|j||| «D];}||krŒ ||k\rn.||dz d«dzx}||<|| kDsŒ*||z dz||z dz|} } } Œ=|} Œg| |kDr]| |kDrX||| dz «sJ|| dz || dz k(r9| dz | dz | dz} } } | |kDr%| |kDr ||| dz «s|| dz || dz k(rŒ9| | z|kr\| | z|krT||| | z«sF|| | z|| | zk(r5| dz } | | z|kr(| | z|kr ||| | z«s|| | z|| | zk(rŒ5| |kDr]| |kDrX||| dz «rJ|| dz || dz k(r9| dz | dz | dz} } } | |kDr%| |kDr ||| dz «r|| dz || dz k(rŒ9| | z|kr\| | z|krT||| | z«rF|| | z|| | zk(r5| dz} | | z|kr(| | z|kr ||| | z«r|| | z|| | zk(rŒ5t| | | «S)aAFind longest matching block in a[alo:ahi] and b[blo:bhi]. By default it will find the longest match in the entirety of a and b. If isjunk is not defined: Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where alo <= i <= i+k <= ahi blo <= j <= j+k <= bhi and for all (i',j',k') meeting those conditions, k >= k' i <= i' and if i == i', j <= j' In other words, of all maximal matching blocks, return one that starts earliest in a, and of all those maximal matching blocks that start earliest in a, return the one that starts earliest in b. >>> s = SequenceMatcher(None, " abcd", "abcd abcd") >>> s.find_longest_match(0, 5, 0, 9) Match(a=0, b=4, size=5) If isjunk is defined, first the longest matching block is determined as above, but with the additional restriction that no junk element appears in the block. Then that block is extended as far as possible by matching (only) junk elements on both sides. So the resulting block never matches on junk except as identical junk happens to be adjacent to an "interesting" match. Here's the same example as before, but considering blanks to be junk. That prevents " abcd" from matching the " abcd" at the tail end of the second sequence directly. Instead only the "abcd" can match, and matches the leftmost "abcd" in the second sequence: >>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd") >>> s.find_longest_match(0, 5, 0, 9) Match(a=1, b=0, size=4) If no blocks match, return (alo, blo, 0). >>> s = SequenceMatcher(None, "ab", "c") >>> s.find_longest_match(0, 2, 0, 1) Match(a=0, b=0, size=0) rr/) rrr0r5Ú __contains__r9ÚrangeÚgetr )r!ÚaloÚahiÚbloÚbhirrr0ÚisbjunkÚbestiÚbestjÚbestsizeÚj2lenÚnothingr;Új2lengetÚnewj2lenÚjÚks rÚfind_longest_matchz"SequenceMatcher.find_longest_match1s:€ðt"ŸV™V T§V¡V¨T¯X©X°t·z±z×7NÑ7NÐNшˆ1ˆc�7Ø ˆ;Ü�a“&ˆCØ ˆ;Ü�a“&ˆCØ!$ c¨1�hˆuˆðˆØˆÜ�s˜C–ˆAð—y‘yˆH؈HØ—W‘W˜Q˜q™T 7Ö+�à�s’7ØØ˜’8ÙÙ"*¨1¨Q©3°Ó"2°QÑ"6Ð6��H˜Q‘KØ�x“<Ø-.¨q©S°©U°A°a±C¸±E¸1 (˜5‘Eð,ð‰Eð!ð(�cŠk˜e cškÙ˜!˜E !™G™*Ô%Ø��a‘‰j˜A˜e A™g™JÒ&Ø%*¨1¡W¨e°A©g°xÀ±z˜(�5ˆEð�cŠk˜e cškÙ˜!˜E !™G™*Ô%Ø��a‘‰j˜A˜e A™g™JÓ&à�H‰n˜sÒ" u¨X¡~¸Ò';Ù˜!˜E (™NÑ+Ô,Ø��h‘Ñ 1 U¨8¡^Ñ#4Ò4Ø ˜‰MˆHð�H‰n˜sÒ" u¨X¡~¸Ò';Ù˜!˜E (™NÑ+Ô,Ø��h‘Ñ 1 U¨8¡^Ñ#4Ó4ð�cŠk˜e cškÙ�a˜˜a™‘jÔ!Ø��a‘‰j˜A˜e A™g™JÒ&Ø%*¨1¡W¨e°A©g°xÀ±z˜(�5ˆEð�cŠk˜e cškÙ�a˜˜a™‘jÔ!Ø��a‘‰j˜A˜e A™g™JÓ&à�H‰n˜sÒ" u¨X¡~¸Ò';Ù�a˜˜h™Ñ'Ô(Ø��h‘Ñ 1 U¨8¡^Ñ#4Ò4Ø !‘|ˆHð�H‰n˜sÒ" u¨X¡~¸Ò';Ù�a˜˜h™Ñ'Ô(Ø��h‘Ñ 1 U¨8¡^Ñ#4Ó4ô�U˜E 8Ó,Ð,rcó —|j� |jSt|j«t|j«}}d|d|fg}g}|r�|j «\}}}}|j ||||«x\} } } } | r[|j | «|| kr|| kr|j || || f«| | z|kr#| | z|kr|j | | z|| | z|f«|rŒ�|j«dx} x}}g}|D]8\}}}| |z|k(r||z|k(r||z }Œ|r|j | ||f«|||}}} Œ:|r|j | ||f«|j ||df«tttj|««|_|jS)aReturn list of triples describing matching subsequences. Each triple is of the form (i, j, n), and means that a[i:i+n] == b[j:j+n]. The triples are monotonically increasing in i and in j. New in Python 2.5, it's also guaranteed that if (i, j, n) and (i', j', n') are adjacent triples in the list, and the second is not the last triple in the list, then i+n != i' or j+n != j'. IOW, adjacent triples never describe adjacent equal blocks. The last triple is a dummy, (len(a), len(b), 0), and is the only triple with n==0. >>> s = SequenceMatcher(None, "abxcd", "abcd") >>> list(s.get_matching_blocks()) [Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)] r) r'r9rrÚpoprVr3ÚsortÚlistÚmapr Ú_make)r!ÚlaÚlbÚqueuer'rHrIrJrKr;rTrUÚxÚi1Új1Úk1Ú non_adjacentÚi2Új2Úk2s rÚget_matching_blocksz#SequenceMatcher.get_matching_blocks¥s»€ð& × Ñ Ð +Ø×'Ñ'Ð 'Ü�T—V‘V“œc $§&¡&›kˆBˆð�R˜˜B�Ð ˆØˆÙØ!&§¡£Ñ ˆC��c˜3Ø×1Ñ1°#°s¸CÀÓEÐ E‰GˆAˆq�!�añØ×&Ñ& qÔ)ؘ’7˜s QšwØ—L‘L # q¨#¨qÐ!1Ô2Ø�Q‘3˜’9  1¡ s¢Ø—L‘L ! A¡# s¨A¨a©C°Ð!5Ô6òð ×ÑÔð ЈЈR�"؈ Û)‰JˆB��Bà�B‰w˜"Š}  b¡¨B¢ð�b‘‘ñ Ø ×'Ñ'¨¨R°¨ Ô5Ø  R˜�B‘ð*ñ Ø × Ñ   R¨  Ô -à×јb " a˜[Ô*Ü#¤C¬¯ © °\Ó$BÓCˆÔØ×#Ñ#Ð#rcó4—|j� |jSdx}}gx|_}|j«D]_\}}}d}||kr||krd}n||krd}n||krd}|r|j|||||f«||z||z}}|sŒJ|jd||||f«Œa|S)a[Return list of 5-tuples describing how to turn a into b. Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the tuple preceding it, and likewise for j1 == the previous j2. The tags are strings, with these meanings: 'replace': a[i1:i2] should be replaced by b[j1:j2] 'delete': a[i1:i2] should be deleted. Note that j1==j2 in this case. 'insert': b[j1:j2] should be inserted at a[i1:i1]. Note that i1==i2 in this case. 'equal': a[i1:i2] == b[j1:j2] >>> a = "qabxcd" >>> b = "abycdf" >>> s = SequenceMatcher(None, a, b) >>> for tag, i1, i2, j1, j2 in s.get_opcodes(): ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" % ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2]))) delete a[0:1] (q) b[0:0] () equal a[1:3] (ab) b[0:2] (ab) replace a[3:4] (x) b[2:3] (y) equal a[4:6] (cd) b[3:5] (cd) insert a[6:6] () b[5:6] (f) rÚÚreplaceÚdeleteÚinsertÚequal)r(rhr3)r!r;rTÚanswerÚaiÚbjÚsizeÚtags rÚ get_opcodeszSequenceMatcher.get_opcodesìsÅ€ð: �<‰<Ð #Ø—<‘<Р؈ ˆˆAØ "Ð"ˆŒ �vØ ×4Ñ4Ö6‰LˆB��Dð ˆCØ�2Šv˜!˜bš&Ø‘Ø�R’Ø‘Ø�R’Ø�ÙØ— ‘   Q¨¨A¨rÐ2Ô4Ø�d‘7˜B˜t™GˆqˆAòØ— ‘  ¨¨Q°°AÐ6Õ8ð'7ð(ˆ rc #óvK—|j«}|sdg}|dddk(r/|d\}}}}}|t|||z «|t|||z «|f|d<|dddk(r/|d\}}}}}||t|||z«|t|||z«f|d<||z}g} |D]\}}}}}|dk(r\||z |kDrT| j||t|||z«|t|||z«f«| –—g} t|||z «t|||z «}}| j|||||f«Œ�| rt | «dk(r | dddk(s| –—yyy­w)aÚ Isolate change clusters by eliminating ranges with no changes. Return a generator of groups with up to n lines of context. Each group is in the same format as returned by get_opcodes(). >>> from pprint import pprint >>> a = list(map(str, range(1,40))) >>> b = a[:] >>> b[8:8] = ['i'] # Make an insertion >>> b[20] += 'x' # Make a replacement >>> b[23:28] = [] # Make a deletion >>> b[30] += 'y' # Make another replacement >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes())) [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)], [('equal', 16, 19, 17, 20), ('replace', 19, 20, 20, 21), ('equal', 20, 22, 21, 23), ('delete', 22, 27, 23, 23), ('equal', 27, 30, 23, 26)], [('equal', 31, 34, 27, 30), ('replace', 34, 35, 30, 31), ('equal', 35, 38, 31, 34)]] )rnrr/rr/rrnéÿÿÿÿr/N)rtÚmaxÚminr3r9) r!r@ÚcodesrsrarerbrfÚnnÚgroups rÚget_grouped_opcodesz#SequenceMatcher.get_grouped_opcodes#sƒèø€ð2× Ñ Ó"ˆÙØ*Ð+ˆEà �‰8�A‰;˜'Ò !Ø"'¨¡(Ñ ˆC��R˜˜RØœC  B q¡D›M¨2¬s°2°r¸!±t«}¸bÐ@ˆE�!‰HØ �‰9�Q‰<˜7Ò "Ø"'¨¡)Ñ ˆC��R˜˜RؘR¤ R¨¨A©£°´C¸¸B¸q¹D³MÐAˆE�"‰Ià �‰UˆØˆÛ#(Ñ ˆC��R˜˜Rð�gŠ~ " R¡%¨"¢*Ø— ‘ ˜c 2¤s¨2¨r°!©t£}°b¼#¸bÀ"ÀQÁ$»-ÐHÔIØ’ Ø�ܘR  A¡›¬¨B°°1±« �B�Ø �L‰L˜#˜r 2 r¨2Ð.Õ /ð$)ñ œ#˜e›* aš-¨E°!©H°Q©K¸7Ò,BØ‹Kð-Cˆ5ùs‚D7D9có¬—td„|j«D««}t|t|j«t|j «z«S)aÒReturn a measure of the sequences' similarity (float in [0,1]). Where T is the total number of elements in both sequences, and M is the number of matches, this is 2.0*M / T. Note that this is 1 if the sequences are identical, and 0 if they have nothing in common. .ratio() is expensive to compute if you haven't already computed .get_matching_blocks() or .get_opcodes(), in which case you may want to try .quick_ratio() or .real_quick_ratio() first to get an upper bound. >>> s = SequenceMatcher(None, "abcd", "bcde") >>> s.ratio() 0.75 >>> s.quick_ratio() 0.75 >>> s.real_quick_ratio() 1.0 c3ó&K—|] }|d–—Œ y­w)rvNr)Ú.0Útriples rÚ z(SequenceMatcher.ratio..ksèø€ÐJÑ/I V�f˜R•jÑ/Iùs‚)Úsumrhrr9rr)r!rs rÚratiozSequenceMatcher.ratioUs?€ô,ÑJ¨t×/GÑ/GÔ/IÓJÓJˆÜ ¬¨T¯V©V«´s¸4¿6¹6³{Ñ)BÓCÐCrcó¨—|j€2ix|_}|jD]}|j|d«dz||<Œ|j}i}|jd}}|jD]5}||«r||}n|j|d«}|dz ||<|dkDsŒ1|dz}Œ7t |t |j«t |j«z«S)z©Return an upper bound on ratio() relatively quickly. This isn't defined beyond that it is an upper bound on .ratio(), and is faster to compute. rr/)r*rrGrErrr9)r!r*r<ÚavailÚavailhasrÚnumbs rÚ quick_ratiozSequenceMatcher.quick_rationsÏ€ð �?‰?Ð "Ø+-Ð -ˆDŒO˜jØ—v”v�Ø",§.¡.°°aÓ"8¸1Ñ"<� ˜3’ðà—_‘_ˆ ðˆØ!×.Ñ.°�'ˆØ—6”6ˆCÙ˜Œ}ؘS‘z‘à!—~‘~ c¨1Ó-�Ø ™ˆE�#‰JØ�a‹xØ! A™+‘ðô  ¬¨T¯V©V«´s¸4¿6¹6³{Ñ)BÓCÐCrcóˆ—t|j«t|j«}}tt ||«||z«S)zÊReturn an upper bound on ratio() very quickly. This isn't defined beyond that it is an upper bound on .ratio(), and is faster to compute than either .ratio() or .quick_ratio(). )r9rrrrx)r!r]r^s rÚreal_quick_ratioz SequenceMatcher.real_quick_ratio‹s6€ô�T—V‘V“œc $§&¡&›kˆBˆô ¤ B¨£ ¨R°"©WÓ5Ð5r)NrjrjT)rNrN)é)Ú__name__Ú __module__Ú __qualname__Ú__doc__r"r r$r%r+rVrhrtr|rƒrˆrŠÚ classmethodrÚ__class_getitem__rrrrr,s]„ñHóT>ò@ ò3ò4òX%óNr-òhE$òN5ón0òdDò2Dò: 6ñ$ LÓ1ÑrrcóЗ|dkDstd|›�«‚d|cxkrdksntd|›�«‚g}t«}|j|«|D]p}|j|«|j «|k\sŒ(|j «|k\sŒ<|j «|k\sŒP|j|j «|f«Œrt||«}|D��cgc]\}}|‘Œ c}}Scc}}w)aÇUse SequenceMatcher to return list of the best "good enough" matches. word is a sequence for which close matches are desired (typically a string). possibilities is a list of sequences against which to match word (typically a list of strings). Optional arg n (default 3) is the maximum number of close matches to return. n must be > 0. Optional arg cutoff (default 0.6) is a float in [0, 1]. Possibilities that don't score at least that similar to word are ignored. The best (no more than n) matches among the possibilities are returned in a list, sorted by similarity score, most similar first. >>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"]) ['apple', 'ape'] >>> import keyword as _keyword >>> get_close_matches("wheel", _keyword.kwlist) ['while'] >>> get_close_matches("Apple", _keyword.kwlist) [] >>> get_close_matches("accept", _keyword.kwlist) ['except'] rzn must be > 0: grzcutoff must be in [0.0, 1.0]: ) Ú ValueErrorrr%r$rŠrˆrƒr3Ú _nlargest)ÚwordÚ possibilitiesr@ÚcutoffÚresultÚsr`Úscores rrršsÏ€ð: �Š6ݱÐ3Ó4Ð4Ø �&Ô ˜CÔ Ý¹vÐGÓHÐHØ €FÜÓ€A؇J�JˆtÔÛ ˆØ � ‰ �1Œ Ø × Ñ Ó  6Ó )Ø �=‰=‹?˜fÓ $Ø �7‰7‹9˜Ó Ø �M‰M˜1Ÿ7™7›9 a˜.Õ )ð ô�q˜&Ó !€Fá$Ô %™f‘(�%˜ŠA˜fÒ %Ð%ùÓ %sà C"cóF—djd„t||«D««S)zAReplace whitespace with the original whitespace characters in `s`rjc3óTK—|] \}}|dk(r|j«r|n|–—Œ"y­w)Ú N)Úisspace)rÚcÚtag_cs rr�z$_keep_original_ws..Ís/èø€ðá%‰HˆAˆuð�cŠ\˜aŸi™iœk‰¨uÓ4Ù%ùs‚&()ÚjoinÚzip)r™Útag_ss rÚ_keep_original_wsr¤Ës&€à �7‰7ñä˜A˜uœ óó ðrcó<—eZdZdZd d„Zd„Zd„Zd„Zd„Zd„Z d „Z y) raµ Differ is a class for comparing sequences of lines of text, and producing human-readable differences or deltas. Differ uses SequenceMatcher both to compare sequences of lines, and to compare sequences of characters within similar (near-matching) lines. Each line of a Differ delta begins with a two-letter code: '- ' line unique to sequence 1 '+ ' line unique to sequence 2 ' ' line common to both sequences '? ' line not present in either input sequence Lines beginning with '? ' attempt to guide the eye to intraline differences, and were not present in either input sequence. These lines can be confusing if the sequences contain tab characters. Note that Differ makes no claim to produce a *minimal* diff. To the contrary, minimal diffs are often counter-intuitive, because they synch up anywhere possible, sometimes accidental matches 100 pages apart. Restricting synch points to contiguous matches preserves some notion of locality, at the occasional cost of producing a longer diff. Example: Comparing two texts. First we set up the texts, sequences of individual single-line strings ending with newlines (such sequences can also be obtained from the `readlines()` method of file-like objects): >>> text1 = ''' 1. Beautiful is better than ugly. ... 2. Explicit is better than implicit. ... 3. Simple is better than complex. ... 4. Complex is better than complicated. ... '''.splitlines(keepends=True) >>> len(text1) 4 >>> text1[0][-1] '\n' >>> text2 = ''' 1. Beautiful is better than ugly. ... 3. Simple is better than complex. ... 4. Complicated is better than complex. ... 5. Flat is better than nested. ... '''.splitlines(keepends=True) Next we instantiate a Differ object: >>> d = Differ() Note that when instantiating a Differ object we may pass functions to filter out line and character 'junk'. See Differ.__init__ for details. Finally, we compare the two: >>> result = list(d.compare(text1, text2)) 'result' is a list of strings, so let's pretty-print it: >>> from pprint import pprint as _pprint >>> _pprint(result) [' 1. Beautiful is better than ugly.\n', '- 2. Explicit is better than implicit.\n', '- 3. Simple is better than complex.\n', '+ 3. Simple is better than complex.\n', '? ++\n', '- 4. Complex is better than complicated.\n', '? ^ ---- ^\n', '+ 4. Complicated is better than complex.\n', '? ++++ ^ ^\n', '+ 5. Flat is better than nested.\n'] As a single multi-line string it looks like this: >>> print(''.join(result), end="") 1. Beautiful is better than ugly. - 2. Explicit is better than implicit. - 3. Simple is better than complex. + 3. Simple is better than complex. ? ++ - 4. Complex is better than complicated. ? ^ ---- ^ + 4. Complicated is better than complex. ? ++++ ^ ^ + 5. Flat is better than nested. Ncó —||_||_y)aÅ Construct a text differencer, with optional filters. The two optional keyword parameters are for filter functions: - `linejunk`: A function that should accept a single string argument, and return true iff the string is junk. The module-level function `IS_LINE_JUNK` may be used to filter out lines without visible characters, except for at most one splat ('#'). It is recommended to leave linejunk None; the underlying SequenceMatcher class has an adaptive notion of "noise" lines that's better than any static definition the author has ever been able to craft. - `charjunk`: A function that should accept a string of length 1. The module-level function `IS_CHARACTER_JUNK` may be used to filter out whitespace characters (a blank or tab; **note**: bad idea to include newline in this!). Use of IS_CHARACTER_JUNK is recommended. N©ÚlinejunkÚcharjunk)r!r¨r©s rr"zDiffer.__init__*s€ð(!ˆŒ Ø ˆ� rc #óxK—t|j||«}|j«D]Š\}}}}}|dk(r|j||||||«} n\|dk(r|j d|||«} nB|dk(r|j d|||«} n(|dk(r|j d|||«} nt d|›�«‚| Ed {–—†ŒŒy 7Œ­w) aù Compare two sequences of lines; generate the resulting delta. Each sequence must contain individual single-line strings ending with newlines. Such sequences can be obtained from the `readlines()` method of file-like objects. The delta generated also consists of newline- terminated strings, ready to be printed as-is via the writelines() method of a file-like object. Example: >>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True), ... 'ore\ntree\nemu\n'.splitlines(True))), ... end="") - one ? ^ + ore ? ^ - two - three ? - + tree + emu rkrlÚ-rmÚ+rnr�ú unknown tag N)rr¨rtÚ_fancy_replaceÚ_dumpr“) r!rrÚcruncherrsrHrIrJrKÚgs rÚcomparezDiffer.compareAsÅèø€ô4# 4§=¡=°!°QÓ7ˆØ'/×';Ñ';Ö'=Ñ #ˆC��c˜3 Ø�iÒØ×'Ñ'¨¨3°°Q¸¸SÓA‘ؘ’Ø—J‘J˜s A s¨CÓ0‘ؘ’Ø—J‘J˜s A s¨CÓ0‘ؘ’Ø—J‘J˜s A s¨CÓ0‘å ±SÐ!:Ó;Ð;à�L‰Lñ(>ð ús‚B.B:Â0B8Â1B:c#óFK—t||«D]}|›d||›�–—Œy­w)z4Generate comparison results for a same-tagged range.r�N)rF)r!rsr`ÚloÚhir;s rr¯z Differ._dumpjs%èø€ä�r˜2–ˆAÚ  ! A¢$Ð'Ó 'ñùs‚!c#óK—||kr||ksJ‚||z ||z kr)|jd|||«}|jd|||«}n(|jd|||«}|jd|||«}||fD] } | Ed{–—†Œy7Œ­w)Nr¬r«)r¯) r!rrHrIrrJrKÚfirstÚsecondr±s rÚ_plain_replacezDiffer._plain_replaceos“èø€Ø�SŠy˜S 3šYÐ&Ð&ð �‰9�s˜S‘yÒ Ø—Z‘Z  Q¨¨SÓ1ˆEØ—Z‘Z  Q¨¨SÓ1‰Fà—Z‘Z  Q¨¨SÓ1ˆEØ—Z‘Z  Q¨¨SÓ1ˆFà˜“ˆAØ�L‰LñØ ús‚A5BÁ7A?Á8Bc#óK—d\}}t|j«} d\} } t||«D]›} || } | j| «t||«D]t}||}|| k(r| €|| } } Œ| j |«| j «|kDsŒ9| j «|kDsŒM| j«|kDsŒa| j«|| }}}ŒvŒ�||kr(| €|j||||||«Ed{–—†y| | d}}}nd} |j||||«Ed{–—†||||}}| €­dx}}| j||«| j«D]g\}}}}}||z ||z }}|dk(r|d|zz }|d|zz }Œ)|dk(r |d |zz }Œ7|d k(r |d |zz }ŒE|d k(r|d |zz }|d |zz }Œ[td|›�«‚|j||||«Ed{–—†nd|z–—|j||dz|||dz|«Ed{–—†y7�Œ7Œì7Œ67Œ ­w)aL When replacing one block of lines with another, search the blocks for *similar* lines; the best-matching pair (if any) is used as a synch point, and intraline difference marking is done on the similar pair. Lots of work, but often worth it. Example: >>> d = Differ() >>> results = d._fancy_replace(['abcDefghiJkl\n'], 0, 1, ... ['abcdefGhijkl\n'], 0, 1) >>> print(''.join(results), end="") - abcDefghiJkl ? ^ ^ ^ + abcdefGhijkl ? ^ ^ ^ )g®Gáz®ç?gè?©NNNrrjrkÚ^rlr«rmr¬rnr�r­ú r/)rr©rFr%r$rŠrˆrƒr¹Ú _fancy_helperr rtr“Ú_qformat)r!rrHrIrrJrKÚ best_ratior—r°ÚeqiÚeqjrTrqr;rpÚbest_iÚbest_jÚaeltÚbeltÚatagsÚbtagsrsÚai1Úai2Úbj1Úbj2r]r^s rr®zDiffer._fancy_replace}s†èø€ð*(ш �FÜ" 4§=¡=Ó1ˆØ‰ˆˆSô �s˜C–ˆAØ�1‘ˆBØ × Ñ ˜bÔ !ܘ3 –_�Ø�q‘T�ؘ’8Ø�{Ø#$ a˜S˜ØØ×!Ñ! "Ô%ð×,Ñ,Ó.°Ó;Ø×*Ñ*Ó,¨zÓ9Ø—n‘nÓ&¨Ó3Ø19·±Ó1AÀ1Àa¨ ‘Jñ!%ð!ð( ˜Ò àˆ{à×.Ñ.¨q°#°s¸A¸sÀCÓH×HÐHØà),¨c°3˜J�F‰FðˆCð ×%Ñ% a¨¨f°a¸¸fÓE×EÐEð�v‘Y  &¡ ˆdˆØ ˆ;àÐ ˆE�EØ × Ñ ˜d DÔ )Ø+3×+?Ñ+?Ö+AÑ'��S˜#˜s Cؘs™ C¨#¡I�B�ؘ)Ò#ؘS 2™XÑ%�EؘS 2™XÑ%‘EؘH’_ؘS 2™XÑ%‘EؘH’_ؘS 2™XÑ%‘EؘG’^ؘS 2™XÑ%�EؘS 2™XÑ%‘Eå$¹Ð%>Ó?Ð?ð,Bð—}‘} T¨4°¸Ó>× >Ñ >ð˜‘+Ò ð×%Ñ% a¨°©°3¸¸6À!¹8ÀSÓI×IÑIðQIùð Føð, ?øð Jús[‚B H H HÂ48HÃ,G>Ã-'HÄHÄB7HÇ HÇ +HÇ8HÇ9HÈHÈHÈHc#óÆK—g}||kr1||kr|j||||||«}n.|jd|||«}n||kr|jd|||«}|Ed{–—†y7Œ­w)Nr«r¬)r®r¯)r!rrHrIrrJrKr±s rr¾zDiffer._fancy_helperÛsièø€Ø ˆØ �Š9Ø�SŠyØ×'Ñ'¨¨3°°Q¸¸SÓA‘à—J‘J˜s A s¨CÓ0‘Ø �3ŠYØ— ‘ ˜3  3¨Ó,ˆAà� Š ús‚AA!ÁAÁA!c#óºK—t||«j«}t||«j«}d|z–—|rd|›d�–—d|z–—|r d|›d�–—yy­w)aš Format "?" output and deal with tabs. Example: >>> d = Differ() >>> results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n', ... ' ^ ^ ^ ', ' ^ ^ ^ ') >>> for line in results: print(repr(line)) ... '- \tabcDefghiJkl\n' '? \t ^ ^ ^\n' '+ \tabcdefGhijkl\n' '? \t ^ ^ ^\n' ú- z? Ú ú+ N)r¤Úrstrip)r!ÚalineÚblinerÇrÈs rr¿zDiffer._qformatçsmèø€ô " %¨Ó/×6Ñ6Ó8ˆÜ! %¨Ó/×6Ñ6Ó8ˆà�U‰lÒÙ Ø�u�g˜R�.Ò à�U‰lÒÙ Ø�u�g˜R�.Ó ð ùs‚AAr») rŒr�rŽr�r"r²r¯r¹r®r¾r¿rrrrrÔs0„ñSój!ò.'òR(ò ò\Jò| ó!rrNz \s*(?:#\s*)?$có—||«duS)zß Return True for ignorable line: iff `line` is blank or contains a single '#'. Examples: >>> IS_LINE_JUNK('\n') True >>> IS_LINE_JUNK(' # \n') True >>> IS_LINE_JUNK('hello\n') False Nr)ÚlineÚpats rrrs€ñ ˆt‹9˜DÐ Ð rcó —||vS)zþ Return True for ignorable character: iff `ch` is a space or tab. Examples: >>> IS_CHARACTER_JUNK(' ') True >>> IS_CHARACTER_JUNK('\t') True >>> IS_CHARACTER_JUNK('\n') False >>> IS_CHARACTER_JUNK('x') False r)ÚchÚwss rrr%s €ð �ˆ8€Orcót—|dz}||z }|dk(rdj|«S|s|dz}dj||«S©z Convert range to the "ed" formatr/z{}z{},{}©Úformat©ÚstartÚstopÚ beginningrs rÚ_format_range_unifiedrã<sI€ð˜‘ €IØ �E‰\€FØ �‚{Ø�{‰{˜9Ó%Ð%Ù Ø�Q‰ˆ Ø �>‰>˜) VÓ ,Ð,rc #óHK—t|||||||«d}td||«j|«D]ì} |sVd}|rdj|«nd} |rdj|«nd} dj|| |«–—dj|| |«–—| d| d } } t | d | d «}t | d | d «}dj|||«–—| D]J\}}}}}|dk(r|||D] }d|z–—Œ Œ |dvr|||D] }d|z–—Œ |dvsŒ:|||D] }d|z–—Œ ŒLŒîy­w)aª Compare two sequences of lines; generate the delta as a unified diff. Unified diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which defaults to three. By default, the diff control lines (those with ---, +++, or @@) are created with a trailing newline. This is helpful so that inputs created from file.readlines() result in diffs that are suitable for file.writelines() since both the inputs and outputs have trailing newlines. For inputs that do not have trailing newlines, set the lineterm argument to "" so that the output will be uniformly newline free. The unidiff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification times are normally expressed in the ISO 8601 format. Example: >>> for line in unified_diff('one two three four'.split(), ... 'zero one tree four'.split(), 'Original', 'Current', ... '2005-01-26 23:30:50', '2010-04-02 10:20:52', ... lineterm=''): ... print(line) # doctest: +NORMALIZE_WHITESPACE --- Original 2005-01-26 23:30:50 +++ Current 2010-04-02 10:20:52 @@ -1,4 +1,4 @@ +zero one -two -three +tree four FNTú {}rjú --- {}{}{}z +++ {}{}{}rrvr/ér‹éz@@ -{} +{} @@{}rnr�>rlrkr«>rmrkr¬)Ú _check_typesrr|rÞrã)rrÚfromfileÚtofileÚ fromfiledateÚ tofiledater@ÚlinetermÚstartedr{ÚfromdateÚtodater·ÚlastÚ file1_rangeÚ file2_rangersrarerbrfrÖs rr r Gsdèø€ôR��A�x ¨°zÀ8ÔLØ€GÜ   a¨Ó*×>Ñ>¸qÖAˆÙ؈GÙ6B�v—}‘} \Ô2ȈHÙ2<�V—]‘] :Ô.À"ˆFØ×%Ñ% h°¸(ÓCÒ CØ×%Ñ% f¨f°hÓ?Ò ?à˜A‘h  b¡ ˆtˆÜ+¨E°!©H°d¸1±gÓ>ˆ Ü+¨E°!©H°d¸1±gÓ>ˆ Ø×&Ñ& {°KÀÓJÒJã#(Ñ ˆC��R˜˜RØ�gŠ~ؘb ›H�DØ ™*Ó$ð%àØÐ+Ñ+ؘb ›H�DØ ™*Ó$ð%àÐ+Ò+ؘb ›H�DØ ™*Ó$ñ%ñ$)ñBùs ‚D D"Ä D"có€—|dz}||z }|s|dz}|dkrdj|«Sdj|||zdz «SrÜrÝrßs rÚ_format_range_contextrö�sS€ð˜‘ €IØ �E‰\€FÙ Ø�Q‰ˆ Ø �‚{Ø�{‰{˜9Ó%Ð%Ø �>‰>˜) Y°Ñ%7¸!Ñ%;Ó <Ð>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(True), ... 'zero\none\ntree\nfour\n'.splitlines(True), 'Original', 'Current')), ... end="") *** Original --- Current *************** *** 1,4 **** one ! two ! three four --- 1,4 ---- + zero one ! tree four rÑrÏz! r½)rmrlrkrnFNTrårjz *** {}{}{}rærrvz***************r/rçz *** {} ****{}c3ó0K—|]\}}}}}|dv–—Œy­w)>rlrkNr©rrsÚ_s rr�zcontext_diff..Ùó!èø€ÐIÁ5±°°Q¸¸1¸aˆsÐ+Ô+Á5ùó‚rmr‹rèz --- {} ----{}c3ó0K—|]\}}}}}|dv–—Œy­w)>rmrkNrrùs rr�zcontext_diff..ârûrürl)réÚdictrr|rÞröÚany)rrrêrërìrír@rîÚprefixrïr{rðrñr·ròrórsrarerúrÖrôrbrfs rr r œs¥èø€ôX��A�x ¨°zÀ8ÔLÜ ˜ d°DÀÔ E€FØ€GÜ   a¨Ó*×>Ñ>¸q×AˆÙ؈GÙ6B�v—}‘} \Ô2ȈHÙ2<�V—]‘] :Ô.À"ˆFØ×%Ñ% h°¸(ÓCÒ CØ×%Ñ% f¨f°hÓ?Ò ?à˜A‘h  b¡ ˆtˆØ (Ñ*Ò*ä+¨E°!©H°d¸1±gÓ>ˆ Ø×$Ñ$ [°(Ó;Ò;ä ÑIÁ5ÓIÔ IÛ%*Ñ!��R˜˜Q Ø˜(“?Ø ! " R£˜Ø$ S™k¨DÑ0Ó0ñ!)ð&+ô ,¨E°!©H°d¸1±gÓ>ˆ Ø×$Ñ$ [°(Ó;Ò;ä ÑIÁ5ÓIÖ IÛ%*Ñ!��Q˜˜2˜rؘ(“?Ø ! " R£˜Ø$ S™k¨DÑ0Ó0ñ!)ò&+ñ1Bùs‚C4E2Ã7AE2ÅE2ÅE2cóN—|r>t|dt«s+tdt|d«j›d|d›d�«‚|r>t|dt«s+tdt|d«j›d|d›d�«‚|D] }t|t«rŒtd|›�«‚y)Nrz"lines to compare must be str, not ú (Ú)z all arguments must be str, not: )Ú isinstanceÚstrÚ TypeErrorÚtyperŒ)rrÚargsÚargs rréréès˜€ñ ”˜A˜a™D¤#Ô&Ýܘa ™d›×,Ó,¨a°«dð4ó5ð 5ᔘA˜a™D¤#Ô&Ýܘa ™d›×,Ó,¨a°«dð4ó5ð 5ãˆÜ˜#œsÕ#ÝÁCÐIÓJÐ Jñrc #ó K—d„} tt| |««}tt| |««}| |«}| |«}| |«}| |«}| |«}|||||||||«} | D]} | jdd«–—Œy­w)aÖ Compare `a` and `b`, two sequences of lines represented as bytes rather than str. This is a wrapper for `dfunc`, which is typically either unified_diff() or context_diff(). Inputs are losslessly converted to strings so that `dfunc` only has to worry about strings, and encoded back to bytes on return. This is necessary to compare files with unknown or inconsistent encoding. All other inputs (except `n`) must be bytes rather than str. cóš— |jdd«S#t$r-}dt|«j›d|›d�}t |«|‚d}~wwxYw)NÚasciiÚsurrogateescapez!all arguments must be bytes, not rr)ÚdecodeÚAttributeErrorrrŒr)r™ÚerrÚmsgs rrzdiff_bytes..decodesK€ð *Ø—8‘8˜GÐ%6Ó7Ð 7øÜó *䘓G×$Ó$¢að)ˆCä˜C“. cÐ )ûð *ús‚” A �(AÁA r r N)rZr[Úencode) Údfuncrrrêrërìrír@rîrÚlinesrÖs rr r ùs’èø€ò*ô ŒS�˜‹^Ó€AÜ ŒS�˜‹^Ó€AÙ�hÓ€HÙ �F‹^€FÙ˜,Ó'€LÙ˜ Ó#€JÙ�hÓ€Há �!�Q˜ &¨,¸ ÀAÀxÓ P€EÛˆØ�k‰k˜'Ð#4Ó5Ó5ñùs‚BBcó:—t||«j||«S)aJ Compare `a` and `b` (lists of strings); return a `Differ`-style delta. Optional keyword parameters `linejunk` and `charjunk` are for filter functions, or can be None: - linejunk: A function that should accept a single string argument and return true iff the string is junk. The default is None, and is recommended; the underlying SequenceMatcher class has an adaptive notion of "noise" lines. - charjunk: A function that accepts a character (string of length 1), and returns true iff the character is junk. The default is the module-level function IS_CHARACTER_JUNK, which filters out whitespace characters (a blank or tab; note: it's a bad idea to include newline in this!). Tools/scripts/ndiff.py is a command-line front-end to this function. Example: >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True), ... 'ore\ntree\nemu\n'.splitlines(keepends=True)) >>> print(''.join(diff), end="") - one ? ^ + ore ? ^ - two - three ? - + tree + emu )rr²)rrr¨r©s rrrs€ôF �(˜HÓ %× -Ñ -¨a°Ó 3Ð3rc#󇇇‡K—ddl}|jd«Št||||«Šddgfˆfd„ Šˆˆfd„Šˆfd„}|«}|€ |Ed{–—†y|dz }d} ddg|z} } d} | dur' t|«\} } } | |z}| | | f| |<| dz } | durŒ'| |kDrd –—|}n| }d} |r| |z}| dz } | |–—|dz}|rŒ|dz } |r&t|«\} } } | r|dz }n|dz}| | | f–—|rŒ&Œ�7Œœ#t$rYywxYw#t$rYywxYw­w) aßReturns generator yielding marked up from/to side by side differences. Arguments: fromlines -- list of text lines to compared to tolines tolines -- list of text lines to be compared to fromlines context -- number of context lines to display on each side of difference, if None, all from/to text lines will be generated. linejunk -- passed on to ndiff (see ndiff documentation) charjunk -- passed on to ndiff (see ndiff documentation) This function returns an iterator which returns a tuple: (from line tuple, to line tuple, boolean flag) from/to line tuple -- (line num, line text) line num -- integer or None (to indicate a context separation) line text -- original line text with following markers inserted: '\0+' -- marks start of added text '\0-' -- marks start of deleted text '\0^' -- marks start of changed text '\1' -- marks end of added/deleted/changed text boolean flag -- None indicates context separation, True indicates either "from" or "to" line contains a change, otherwise False. This function/iterator was originally developed to generate side by side file difference for making HTML pages (see HtmlDiff class for example usage). Note, this function utilizes the ndiff function to generate the side by side difference markup. Optional ndiff arguments may be passed to this function and they in turn will be passed to ndiff. rNz (\++|\-+|\^+)có”•—||xxdz cc<|€|||jd«ddfS|dk(rq|jd«|jd«}}g}|fd„}‰ j||«t|«D]"\}\} } |d| dz|z|| | zdz|| dz}Œ$|dd}n#|jd«dd}|sd }d|z|zdz}|||fS) aReturns line of text with user's change markup and line formatting. lines -- list of lines from the ndiff generator to produce a line of text from. When producing the line of text to return, the lines used are removed from this list. format_key -- '+' return first line in list with "add" markup around the entire line. '-' return first line in list with "delete" markup around the entire line. '?' return first line in list with add/delete/change intraline markup (indices obtained from second line) None return first line in list with no markup side -- indice into the num_lines list (0=from,1=to) num_lines -- from/to current line number. This is NOT intended to be a passed parameter. It is present as a keyword argument to maintain memory of the current line numbers between calls of this function. Note, this function is purposefully not defined at the module scope so that data it needs from its parent function (within whose context it is defined) does not need to be of module scope. r/NrrçÚ?cóŠ—|j|jd«d|j«g«|jd«S)Nr/r)r3r{Úspan)Ú match_objectÚsub_infos rÚrecord_sub_infoz3_mdiff.._make_line..record_sub_info‡s=€Ø—‘ ×!3Ñ!3°AÓ!6°qÑ!9¸,×:KÑ:KÓ:MÐ NÔOØ#×)Ñ)¨!Ó,Ð,rÚÚr�)rXÚsubÚreversed) rÚ format_keyÚsideÚ num_linesÚtextÚmarkersrrÚkeyÚbeginÚendÚ change_res €rÚ _make_linez_mdiff.._make_linefsø€ð. �$‹˜1Ñ‹ð Рؘd‘O E§I¡I¨a£L°°Ð$4Ð5Ð 5à ˜Ò Ø!ŸI™I a›L¨%¯)©)°A«,�'ˆDàˆHØ6>ó -ð �M‰M˜/¨'Ô 2ô$,¨HÖ#5‘�‘K�U˜3ؘA˜e�} TÑ)¨#Ñ-¨d°5¸¨oÑ=¸dÑBÀ4ÈÈÀ:ÑM‘ð$6à˜˜�8‰Dð—9‘9˜Q“<  Ð#ˆDñØ�à˜*Ñ$ tÑ+¨dÑ2ˆDð˜$‘ Ð%Ð%rc3óª•K—g}d\}} t|«dkr*|jt‰d««t|«dkrŒ*dj|D�cgc]}|d‘Œ c}«}|j d«r|}�n�|j d«r‰|dd«‰|dd «df–—Œ™|j d «r|d z}‰|d d«d df–—Œ¿|j d «r‰|d d«d }}|d z d}}�n|j d«r‰|d d«‰|dd «df–—�Œ|j d«r‰|dd«‰|d d «df–—�Œ9|j d «r|d z}‰|d d«d df–—�Œ`|j d«r|d z }d ‰|dd «df–—�Œ‡|j d«rd ‰|dd «}}|d zd}}nT|j d«r|d z }d ‰|dd «df–—�ŒÓ|j d«r‰|d d d d«‰|d d «df–—�Œ|dkr|d z }d–—|dkrŒ|dkDr|d z}d–—|dkDrŒ|j d«ry df–—�ŒBcc}w­w)a¡Yields from/to lines of text with a change indication. This function is an iterator. It itself pulls lines from a differencing iterator, processes them and yields them. When it can it yields both a "from" and a "to" line, otherwise it will yield one or the other. In addition to yielding the lines of from/to text, a boolean flag is yielded to indicate if the text line(s) have differences in them. Note, this function is purposefully not defined at the module scope so that data it needs from its parent function (within whose context it is defined) does not need to be of module scope. )rrTrèÚXrjrz-?+?rr/z--++r«N)z--?+z--+rÏz-+?z-?+z+--r¬)rÑz+-r�F)N©rjrÐT)r.NT)r9r3Únextr¡Ú startswith) rÚnum_blanks_pendingÚnum_blanks_to_yieldrÖr™Ú from_lineÚto_liner+Údiff_lines_iterators €€rÚ_line_iteratorz_mdiff.._line_iteratoržsÒøèø€ðˆØ26Ñ/ÐÐ/Øô�e“*˜q’.Ø— ‘ œTÐ"5°sÓ;Ô<ô�e“*˜q“.à—‘©UÓ3©U T˜˜a›¨UÑ3Ó4ˆAØ�|‰|˜CÔ ð'9Ò#Ø—‘˜fÔ%á   s¨1Ó-©z¸%ÀÀAÓ/FÈÐLÒLØØ—‘˜fÔ%ð# aÑ'Ð"Ù   s¨1Ó-¨t°TÐ9Ò9ØØ—‘Ð3Ô4ñ%/¨u°S¸Ó$;¸T˜'� Ø9KÈAÑ9MÈaÐ$6Ò#Ø—‘˜eÔ$á   t¨AÓ.± ¸5ÀÀQÓ0GÈÐMÒMÙØ—‘˜eÔ$á   s¨1Ó-©z¸%ÀÀQÓ/GÈÐMÒMÙØ—‘˜cÔ"à" aÑ'Ð"Ù   s¨1Ó-¨t°TÐ9Ò9ÙØ—‘˜eÔ$ð# aÑ'Ð"Ø™J u¨S°Ó3°TÐ9Ò9ÙØ—‘˜lÔ+à%)©:°e¸CÀÓ+B˜7� Ø9KÈAÑ9MÈaÐ$6Ñ#Ø—‘˜cÔ"à" aÑ'Ð"Ø™J u¨S°Ó3°TÐ9Ò9ÙØ—‘˜cÔ"á  ¡q ¨$¨qÓ1±*¸UÀ4ÈÓ2JÈ5ÐPÒPÙð&¨Ò)Ø# qÑ(Ð#Ø)Ò)ð&¨Ó)ð&¨Ò)Ø# qÑ(Ð#Ø)Ò)ð&¨Ó)ð�|‰|˜CÔ Øà ¨Ð,Ò,ñMùò 4ùs%ƒAIÁIÁ IÁF?IÈIÈ3 Ic3ó’•K—‰«}gg}} t|«dk(st|«dk(rX t|«\}}}|�|j||f«|�|j||f«t|«dk(rŒIt|«dk(rŒX|j d«\}}|j d«\}}|||xs|f–—Œ¨#t$rYywxYw­w)atYields from/to lines of text with a change indication. This function is an iterator. It itself pulls lines from the line iterator. Its difference from that iterator is that this function always yields a pair of from/to text lines (with the change indication). If necessary it will collect single from/to lines until it has a matching pair from/to pair to yield. Note, this function is purposefully not defined at the module scope so that data it needs from its parent function (within whose context it is defined) does not need to be of module scope. rN)r9r/Ú StopIterationr3rX) Ú line_iteratorÚ fromlinesÚtolinesr3r4Ú found_diffÚfromDiffÚto_diffr6s €rÚ_line_pair_iteratorz#_mdiff.._line_pair_iteratorösäøèø€ñ'Ó(ˆ ؘR�'ˆ Øä�y“> 1Ò$¬¨G« °aªðÜ59¸-Ó5HÑ2�I˜w¨ ðÐ(Ø×$Ñ$ i° Ð%;Ô<ØÐ&Ø—N‘N G¨JÐ#7Ô8ô�y“> 1Ó$¬¨G« °a«ð#,§-¡-°Ó"2Ñ ˆI�xØ&Ÿ{™{¨1›~Ñ ˆG�WؘW XÒ%8°Ð9Ò 9ðøô %òÙðüs3ƒ)C­B8¼8CÁ5CÂ4CÂ8 CÃCÃCÃCr/F)NNN)ÚreÚcompilerr/r8)r:r;Úcontextr¨r©r@r?Úline_pair_iteratorÚlines_to_writeÚindexÚ contextLinesr<r3r4r;r6r+r*r5s @@@@rÚ_mdiffrG<s¦ûèø€óDð�— ‘ Ð+Ó,€Iô   ¨'°(¸8ÓDÐà78¸°eõ6&õpV-ôp:ñB-Ó.ÐØ€Ø%×%Ñ%ð �1‰ ˆØˆØð#$ d V¨WÑ%5�<ˆE؈JØ Ñ%ðÜ59Ð:LÓ5MÑ2�I˜w¨ ð˜G‘O�Ø#,¨g°zÐ"B� ˜Q‘ؘ‘ �ð Ò%ð�wŠØ&Ò&Ø!(‘à!&�Ø�٠ؘG‘O�ؘ‘ �Ø" 1‘oÒ%Ø !Ñ#�ò !ð % Q™YˆNð Ù$Ü59Ð:LÓ5MÑ2�I˜w¨ á!Ø)0°©™à&¨!Ñ+˜Ø# W¨jÐ8Ò8ò%ð=ð &ùô%òÙðûô:!ò áð üsf†AD Á C*ÁD Á*C,Á9D Â*D Â;D Ã'C;Ã)D Ã, C8Ã5D Ã7C8Ã8D Ã; DÄD ÄDÄD an %(table)s%(legend)s a„ table.diff {font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace; border:medium} .diff_header {background-color:#e0e0e0} td.diff_header {text-align:right} .diff_next {background-color:#c0c0c0} .diff_add {background-color:#aaffaa} .diff_chg {background-color:#ffff77} .diff_sub {background-color:#ffaaaa}aZ %(header_row)s %(data_rows)s
aõ
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op
có|—eZdZdZeZeZeZeZdZddde fd„Z dddœd„Z d „Z d „Z d „Zd „Zd „Zd„Zd„Z dd„Zy)r a{For producing HTML side by side comparison with change highlights. This class can be used to create an HTML table (or a complete HTML file containing the table) showing a side by side, line by line comparison of text with inter-line and intra-line change highlights. The table can be generated in either full or contextual difference mode. The following methods are provided for HTML generation: make_table -- generates HTML for a single side by side table make_file -- generates complete HTML file with a single side by side table See tools/scripts/diff.py for an example usage of this class. réNcó<—||_||_||_||_y)aØHtmlDiff instance initializer Arguments: tabsize -- tab stop spacing, defaults to 8. wrapcolumn -- column number where lines are broken and wrapped, defaults to None where lines are not wrapped. linejunk,charjunk -- keyword arguments passed into ndiff() (used by HtmlDiff() to generate the side by side HTML differences). See ndiff() documentation for argument default values and descriptions. N)Ú_tabsizeÚ _wrapcolumnÚ _linejunkÚ _charjunk)r!ÚtabsizeÚ wrapcolumnr¨r©s rr"zHtmlDiff.__init__˜s!€ð ˆŒ Ø%ˆÔØ!ˆŒØ!ˆ�rzutf-8)Úcharsetc óÊ—|jt|j|j|j ||||||¬«|¬«zj |d«j |«S)aReturns HTML file of side by side comparison with change highlights Arguments: fromlines -- list of "from" lines tolines -- list of "to" lines fromdesc -- "from" file column header string todesc -- "to" file column header string context -- set to True for contextual differences (defaults to False which shows full differences). numlines -- number of context lines. When context is set True, controls number of lines displayed before and after the change. When context is False, controls the number of lines to place the "next" link anchors before the next change (so click of "next" link jumps to just before the change). charset -- charset of the HTML document )rBÚnumlines)ÚstylesÚlegendÚtablerQÚxmlcharrefreplace)Ú_file_templaterþÚ_stylesÚ_legendÚ make_tablerr)r!r:r;ÚfromdescÚtodescrBrSrQs rÚ make_filezHtmlDiff.make_file©sf€ð&×#Ñ#¤dØ—<‘<Ø—<‘<Ø—/‘/ )¨W°hÀØ*1¸Hð"óFàô ' ñ ÷ ‰6�'Ð.Ó /·±°w³ð  @rcó~‡—ˆfd„}|D�cgc] }||«‘Œ }}|D�cgc] }||«‘Œ }}||fScc}wcc}w)aReturns from/to line lists with tabs expanded and newlines removed. Instead of tab characters being replaced by the number of spaces needed to fill in to the next tab stop, this function will fill the space with tab characters. This is done so that the difference algorithms can identify changes in a file when tabs are replaced by spaces and vice versa. At the end of the HTML generation, the tab characters will be replaced with a nonbreakable space. cóÄ•—|jdd«}|j‰j«}|jdd«}|jdd«jd«S)Nr�rÚ rÐ)rkÚ expandtabsrKrÒ)rÖr!s €rÚ expand_tabsz2HtmlDiff._tab_newline_replace..expand_tabsÎsSø€à—<‘<  DÓ)ˆDà—?‘? 4§=¡=Ó1ˆDð—<‘<  DÓ)ˆDØ—<‘<  SÓ)×0Ñ0°Ó6Ð 6rr)r!r:r;rcrÖs` rÚ_tab_newline_replacezHtmlDiff._tab_newline_replaceÄsOø€ô 7ñ4=Ó=±9¨4‘[ Õ&°9ˆ Ð=Ù18Ó9±¨‘;˜tÕ$°ˆÐ9ؘРРùò>ùÚ9s‹5 :cóÜ—|s|j||f«yt|«}|j}||ks||jd«dzz |kr|j||f«yd}d}d}||krB||kr=||dk(r|dz }||}|dz }n||dk(r|dz }d}n |dz }|dz }||kr||krŒ=|d|} ||d} |r | dz} d|z| z} |j|| f«|j |d| «y) a¤Builds list of text lines by splitting text lines at wrap point This function will determine if the input text line needs to be wrapped (split) into separate lines. If so, the first wrap point will be determined and the first line appended to the output text line list. This function is used recursively to handle the second part of the split line to further split it. Nrr‹rrjr/rÚ>)r3r9rLÚcountÚ _split_line) r!Ú data_listÚline_numr%rrrwr;r@ÚmarkÚline1Úline2s rrhzHtmlDiff._split_lineÛsC€ñØ × Ñ ˜h t˜_Ô -Ø ô�4‹yˆØ×ÑˆØ �CŠK˜d T§Z¡Z°Ó%5°aÑ%7Ñ8¸SÒ@Ø × Ñ ˜h t˜_Ô -Ø ð ˆØ ˆØˆØ�#Šg˜!˜dš(Ø�A‰w˜$ŠØ�Q‘�ؘA‘w�Ø�Q‘‘Ø�a‘˜D’Ø�Q‘�Ø‘à�Q‘�Ø�Q‘�ð�#Šg˜!˜d›(ð�R�a�ˆØ�Q�R�ˆñ ؘD‘LˆEؘ4‘K %Ñ'ˆEð ×ј( 5Ð)Ô*ð ×ј 3 uÕ-rc#óK—|D]ƒ\}}}|€|||f–—Œ||c\}}\}}gg} } |j| ||«|j| ||«| s| sŒK| r| jd«}nd}| r| jd«}nd}|||f–—| rŒ6| rŒ9Œ…y­w)z5Returns iterator that splits (wraps) mdiff text linesNr)rjr�)rhrX) r!ÚdiffsÚfromdataÚtodataÚflagÚfromlineÚfromtextÚtolineÚtotextÚfromlistÚtolists rÚ _line_wrapperzHtmlDiff._line_wrappers·èø€ó%*Ñ ˆH�V˜Dàˆ|ؘv dÐ*Ò*ØØ2:¸6Ð /Ñ ˆX�h¡ ¨ð! �VˆHØ × Ñ ˜X h¨xÔ 8Ø × Ñ ˜V F¨6Ô 2ñšfÙØ'Ÿ|™|¨A›‘Hà'�HÙØ#ŸZ™Z¨›]‘Fà%�Fؘv dÐ*Ò*ò›fñ%*ùs‚A B Á5B ÂB  B có@—ggg}}}|D]^\}}} |j|jd|g|¢­Ž«|j|jd|g|¢­Ž«|j|«Œ`|||fS#t$r%|jd«|jd«YŒEwxYw)z³Collects mdiff output into separate lists Before storing the mdiff from/to data into a list, it is converted into a single line of text with HTML markup. rr/N)r3Ú _format_liner)r!rorwrxÚflaglistrprqrrs rÚ_collect_lineszHtmlDiff._collect_lines.s¯€ð$& b¨˜�ˆã$)Ñ ˆH�V˜Dð $à—‘Ð 1 × 1Ñ 1°!°DÐ C¸(Ò CÔDØ— ‘ Ð/˜d×/Ñ/°°$Ð?¸Ò?Ô@ð �O‰O˜DÕ !ð%*ð˜˜xÐ'Ð'øô ò $à—‘ Ô%Ø— ‘ ˜dÖ#ð $ús‘AA/Á/+BÂBcó— d|z}d|j|›|›d�}|jdd«jdd«jd d «}|jd d «j«}d |›d|›d|›d�S#t$rd}YŒkwxYw)aReturns HTML markup of "from" / "to" text lines side -- 0 or 1 indicating "from" or "to" text flag -- indicates if difference on line linenum -- line number (used for line number column) text -- line text to be marked up z%dz id="Ú"rjÚ&z&rfz>Úz)Ú_prefixrrkrÒ)r!r#rrÚlinenumr%Úids rr{zHtmlDiff._format_lineCs“€ð ؘW‘n‰GØ!%§¡¨dÒ!3²GÐ<ˆBð �\‰\˜#˜gÓ &× .Ñ .¨s°6Ó :× BÑ BÀ3ÀvÓ Nˆð�|‰|˜C Ó)×0Ñ0Ó2‰ò’WšTð#ð #øôò àŠBð ús‚A:Á: BÂBcó”—dtjz}dtjz}txjdz c_||g|_y)zCreate unique anchor prefixeszfrom%d_zto%d_r/N)r Ú_default_prefixrƒ)r!Ú fromprefixÚtoprefixs rÚ _make_prefixzHtmlDiff._make_prefixZsA€ð ¤×!9Ñ!9Ñ9ˆ ØœX×5Ñ5Ñ5ˆÜ× Ò  AÑ%Õ à" 8Ð,ˆ� rcóf—|jd}dgt|«z}dgt|«z}d\} } d} t|«D]:\} } | r1| rŒ d} | } td| |z g«} d|| fz|| <| dz } d|| fz|| <Œ9d} Œ<|sdg}dg}dg}d} |rd g}|}nd gx}}|dsd |z|d<d |z|| <|||||fS) zMakes list of "next" linksr/rj)rFrTz id="difflib_chg_%s_%d"z"nFz2 No Differences Found z( Empty File z!fz#t)rƒr9r1rw)r!rwrxr|rBrSr‰Únext_idÚ next_hrefÚnum_chgÚ in_changeròr;rrs rÚ_convert_flagszHtmlDiff._convert_flagses'€ð—<‘< ‘?ˆð�$”s˜8“}Ñ$ˆØ�Dœ˜X›Ñ&ˆ Ø%ш�؈ܠÖ)‰FˆAˆdÙÚ Ø $�IØ�Dô˜Q˜q ™z˜NÓ+�AØ!:¸hÀwÐ=OÑ!O�G˜A‘Jð˜q‘L�GØ&JØ! 'ðN+ñ'+�I˜d’Oð"‘ ð!*ñ$Ø�wˆHØ�dˆGؘˆI؈DÙØPÐQ�Ø!‘à%OÐ$PÐP�˜6à˜Š{Ø>ÀÑIˆI�a‰Là?À8ÑLˆ �$‰à˜˜x¨ °'Ð9Ð9rc óD—|j«|j||«\}}|r|}nd}t||||j|j¬«}|j r|j |«}|j|«\} } } |j| | | ||«\} } } } } g}d}tt| ««D]G}| |€|dkDsŒ|jd«Œ |j|| || || || || |fz«ŒI|s|rdd›d|z›d›d|z›d �}nd }|jtd j|«||jd ¬ «z}|j!d d«j!dd«j!dd«j!dd«j!dd«S)aîReturns HTML table of side by side comparison with change highlights Arguments: fromlines -- list of "from" lines tolines -- list of "to" lines fromdesc -- "from" file column header string todesc -- "to" file column header string context -- set to True for contextual differences (defaults to False which shows full differences). numlines -- number of context lines. When context is set True, controls number of lines displayed before and after the change. When context is False, controls the number of lines to place the "next" link anchors before the next change (so click of "next" link jumps to just before the change). Nr§zV %s%s%s%s rz) z z!
z+%sz rjr/)Ú data_rowsÚ header_rowrz+zz-zz^zrzrar‚)rŠrdrGrMrNrLryr}r�rFr9r3Ú_table_templaterþr¡rƒrk)r!r:r;r\r]rBrSÚ context_linesrorwrxr|r�rŒr™Úfmtr;r“rVs rr[zHtmlDiff.make_table”sÑ€ð( ×ÑÔð!×5Ñ5°iÀÓHш �'ñ Ø$‰Mà ˆMÜ�y ¨ÀÇÁØ#Ÿ~™~ô/ˆð × Ò Ø×&Ñ& uÓ-ˆEð$(×#6Ñ#6°uÓ#=Ñ ˆ�˜ð6:×5HÑ5HØ �V˜H W¨Xó67Ñ2ˆ�˜ ¨7ð ˆð7ˆä”s˜8“}Ö%ˆAؘ‰{Ð"ð�q“5Ø—H‘HÐJÕKà—‘˜# ¨¡¨I°a©L¸À!¹Ø+4°Q©<¸¸q¹ ð!CñCõDð&ñ ‘vøá3Ø=ÀÒHÙ3Ø=ÀÓFð H‰Jð ˆJà×$Ñ$¤tØ—g‘g˜a“jØ!Ø—<‘< ‘?ô($ñ$ˆð �}‰}˜UÐ#<Ó=ß‘W˜UÐ#<Ó=ß‘W˜UÐ#<Ó=ß‘W˜T )Ó,ß‘W˜T (Ó+ð  ,r)rjrjFé)rŒr�rŽr�rXrYr”rZr‡rr"r^rdrhryr}r{rŠr�r[rrrr r ‚s„ñ ð$€NØ€GØ%€OØ€GØ€Oà¨4¸Ø+ó"ð"ACØ*+ð@Ø8?ô@ò6!ò.5.òn+ò8(ò*#ò. -ò-:ð^INØôK,rr c#óœK— dddœt|«}d|f}|D]}|dd|vsŒ |dd–—Œy#t$rtd|z«d‚wxYw­w)a0 Generate one of the two sequences that generated a delta. Given a `delta` produced by `Differ.compare()` or `ndiff()`, extract lines originating from file 1 or 2 (parameter `which`), stripping off line prefixes. Examples: >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True), ... 'ore\ntree\nemu\n'.splitlines(keepends=True)) >>> diff = list(diff) >>> print(''.join(restore(diff, 1)), end="") one two three >>> print(''.join(restore(diff, 2)), end="") ore tree emu rÏrÑ)r/rçz)unknown delta choice (must be 1 or 2): %rNr½rç)ÚintÚKeyErrorr“)ÚdeltaÚwhichrsÚprefixesrÖs rrrãswèø€ð,.ؘ4Ñ ¤ U£Ñ,ˆð�cˆ{€HÛˆØ ��ˆ8�xÒ Ø�q�r�(‹Nñøô ò.ÜÐDØ"ñ#ó$Ø)-ð .ð.üs‚A „0•A ¦ A °A Á A có4—ddl}ddl}|j|«S)Nr)ÚdoctestÚdifflibÚtestmod)rŸr s rÚ_testr¢s€ßØ �?‰?˜7Ó #Ð#rÚ__main__)r‹g333333ã?)z )rjrjrjrjr‹rÐ)rrrrr‹ó )&r�Ú__all__Úheapqrr”Ú collectionsrÚ _namedtupleÚtypesrr rrrr¤rr@rAÚmatchrrrãr rör rér rrGrXrYr”rZÚobjectr rr¢rŒrrrÚr¬sðñò8 >€õ(Ý1Ýá�G˜ZÓ(€ò÷ k 2ñk 2ó\.&òb÷l!ñl!ó~  à%˜2Ÿ:™:Ð&6Ó7×=Ñ=ó!ó ò. -ð=?Ø.2óB%òR =ð,.Ø?CóJ1òXKð"25Ø?Dó6ð<Ð(9ó#4ðJ(,°dØ%óKð\ €ð( 0€ð€ð €ô"],ˆvô],ð~ òò@$ð ˆzÒÙ …Gðr