U e5dZH @s4dddddddddd d d g Zd d lmZd dlmZed dZddZGdddZ d7ddZ ddZ GdddZ d dl Z e djfddZd8ddZddZd9d"dZd#d$Zd:d%dZd&d'Zd;d*d Zdefd+dZddefd,d-Zd.Zd/Zd0Zd1ZGd2d d eZ[ d3dZ d4d5Z!e"d6kr0e!dS)<get_close_matchesndiffrestoreSequenceMatcherDifferIS_CHARACTER_JUNK IS_LINE_JUNK context_diff unified_diff diff_bytesHtmlDiffMatch)nlargest) namedtupleza b sizecCs|rd||SdS)Ng@?)matcheslengthrr/usr/lib64/python3.8/difflib.py_calculate_ratio&s rc@speZdZdddZddZdd Zd d Zd d ZddZddZ ddZ dddZ ddZ ddZ ddZdS)rNTcCs(||_d|_|_||_|||dSN)isjunkabautojunkset_seqs)selfrrrrrrr__init__s; zSequenceMatcher.__init__cCs||||dSr)set_seq1set_seq2)rrrrrrrs zSequenceMatcher.set_seqscCs$||jkrdS||_d|_|_dSr)rmatching_blocksopcodes)rrrrrrs zSequenceMatcher.set_seq1cCs2||jkrdS||_d|_|_d|_|dSr)rr!r" fullbcount_SequenceMatcher__chain_b)rrrrrr s   zSequenceMatcher.set_seq2c Cs|j}i|_}t|D]\}}||g}||qt|_}|j}|r~|D]}||rV| |qV|D] }||=qrt|_ }t |} |j r| dkr| dd} | D]\}} t | | kr| |q|D] }||=qdS)Nd)rb2j enumerate setdefaultappendsetbjunkrkeysaddZbpopularlenritems) rrr(ieltindicesZjunkrZpopularnZntestZidxsrrrZ __chain_b)s,           zSequenceMatcher.__chain_bcCs4|j|j|j|jjf\}}}}||d} } } i} g} t||D]}| j}i}|||| D]\}||krlq^||krxq||ddd}||<|| kr^||d||d|} } } q^|} q@| |kr | |kr ||| ds || d|| dkr | d| d| d} } } q| | |krt| | |krt||| | st|| | || | krt| d7} q | |kr| |kr||| dr|| d|| dkr| d| d| d} } } qt| | |kr(| | |kr(||| | r(|| | || | kr(| d} qt| | | SNr r')rrr(r- __contains__rangegetr )raloahiblobhirrr(ZisbjunkZbestiZbestjZbestsizeZj2lenZnothingr2Zj2lengetZnewj2lenjkrrrfind_longest_matchPsR8"   z"SequenceMatcher.find_longest_matchcCs||jdk r|jSt|jt|j}}d|d|fg}g}|r|\}}}}|||||\} } } } | r8|| || kr|| kr||| || f| | |kr8| | |kr8|| | || | |fq8|d} }}g}|D]V\}}}| ||kr|||kr||7}q|r,|| ||f|||} }}q|rT|| ||f|||dftt t j ||_|jSNr ) r!r0rrpopr@r+sortlistmapr _make)rlalbZqueuer!r:r;r<r=r2r>r?xi1j1Zk1Z non_adjacenti2j2Zk2rrrget_matching_blockss8    z#SequenceMatcher.get_matching_blockscCs|jdk r|jSd}}g|_}|D]\}}}d}||krN||krNd}n||kr\d}n ||krhd}|r||||||f||||}}|r*|d||||fq*|S)Nr rreplacedeleteinsertequal)r"rNr+)rr2r>Zansweraibjsizetagrrr get_opcodess$  zSequenceMatcher.get_opcodesc csn|}|sdg}|dddkrZ|d\}}}}}|t||||t||||f|d<|dddkr|d\}}}}}||t||||t|||f|d<||}g} |D]\}}}}}|dkr(|||kr(| ||t||||t|||f| Vg} t|||t|||}}| |||||fq| rjt| dkrd| dddksj| VdS)N)rRr r'r r'r rRr')rWmaxminr+r0) rr5ZcodesrVrJrLrKrMZnngrouprrrget_grouped_opcodes<s(&&(&z#SequenceMatcher.get_grouped_opcodescCs0tdd|D}t|t|jt|jS)Ncss|]}|dVqdS)rYNr).0Ztriplerrr sz(SequenceMatcher.ratio..)sumrNrr0rr)rrrrrrationszSequenceMatcher.ratiocCs|jdkr4i|_}|jD]}||dd||<q|j}i}|jd}}|jD]>}||rf||}n ||d}|d||<|dkrP|d}qPt|t|jt|jSr6)r#rr9r7rrr0)rr#r3ZavailZavailhasrZnumbrrr quick_ratios         zSequenceMatcher.quick_ratiocCs*t|jt|j}}tt||||Sr)r0rrrr[)rrGrHrrrreal_quick_ratiosz SequenceMatcher.real_quick_ratio)NrrT)rX)__name__ __module__ __qualname__rrrr r$r@rNrWr]rarbrcrrrrr+sl @ ,'nG7 2rX333333?cCs|dkstd|fd|kr*dks:ntd|fg}t}|||D]D}||||krR||krR||krR|||fqRt||}dd|DS)Nr zn must be > 0: %rgrz cutoff must be in [0.0, 1.0]: %rcSsg|] \}}|qSrr)r^ZscorerIrrr sz%get_close_matches..) ValueErrorrr rrcrbrar+ _nlargest)ZwordZ possibilitiesr5cutoffresultsrIrrrrs"      cCsdddt||DS)Nrcss*|]"\}}|dkr|r|n|VqdS) N)isspace)r^cZtag_crrrr_sz$_keep_original_ws..)joinzip)rmZtag_srrr_keep_original_wss rsc@sFeZdZdddZddZddZdd Zd d Zd d ZddZ dS)rNcCs||_||_dSrlinejunkcharjunk)rrurvrrrrHszDiffer.__init__c cst|j||}|D]\}}}}}|dkrB|||||||} n\|dkr\|d|||} nB|dkrv|d|||} n(|dkr|d|||} ntd|f| EdHqdS) NrOrP-rQ+rRrnunknown tag %r)rrurW_fancy_replace_dumpri) rrrcruncherrVr:r;r<r=grrrcompare_szDiffer.compareccs&t||D]}d|||fVq dS)Nz%s %s)r8)rrVrIlohir2rrrr{sz Differ._dumpc csn||||kr2|d|||}|d|||}n |d|||}|d|||}||fD]} | EdHqZdS)Nrxrw)r{) rrr:r;rr<r=firstsecondr}rrr_plain_replaces zDiffer._plain_replaceccs:d\}}t|j} d\} } t||D]} || } | | t||D]j}||}|| krl| dkrD|| } } qD| || |krD| |krD| |krD| || }}}qDq$||kr| dkr|||||||EdHdS| | d}}}nd} | ||||||EdH||||}}| dkr d}}| ||| D]\}}}}}||||}}|dkr|d|7}|d|7}nb|dkr|d|7}nJ|d kr|d |7}n2|d kr|d |7}|d |7}nt d |fqH| ||||EdHn d|V| ||d|||d|EdHdS)N)gGz?g?)NNrrrO^rPrwrQrxrRrnry r')rrvr8r rrcrbrar _fancy_helperrrWri_qformat)rrr:r;rr<r=Z best_ratiorkr|ZeqiZeqjr>rTr2rSZbest_iZbest_jZaeltZbeltatagsbtagsrVZai1Zai2Zbj1Zbj2rGrHrrrrzs\                zDiffer._fancy_replaceccsbg}||kr<||kr*|||||||}qT|d|||}n||krT|d|||}|EdHdS)Nrwrx)rzr{)rrr:r;rr<r=r}rrrrszDiffer._fancy_helperccsXt||}t||}d|V|r8d|dVd|V|rTd|dVdS)N- z?  + )rsrstrip)rZalineZblinerrrrrrs  zDiffer._qformat)NN) rdrerfrr~r{rrzrrrrrrrs^ )^ Nz \s*(?:#\s*)?$cCs ||dk Srr)lineZpatrrrr3s cCs||kSrr)ZchZwsrrrrCscCs:|d}||}|dkr"d|S|s.|d8}d||SNr'z{}z{},{}formatstartstopZ beginningrrrr_format_range_unifiedZs rrrccsPt|||||||d}td|||D]} |s|d}|rFd|nd} |rXd|nd} d|| |Vd|| |V| d| d} } t| d | d }t| d | d }d |||V| D]\}}}}}|dkr|||D]}d|Vqq|dkr"|||D]}d|Vq|dkr|||D]}d|Vq6qq*dS)NFT {}r --- {}{}{}z +++ {}{}{}r rYr'rXz@@ -{} +{} @@{}rRrn>rPrOrw>rOrQrx) _check_typesrr]rr)rrfromfiletofile fromfiledate tofiledater5linetermstartedr\fromdatetodaterlast file1_range file2_rangerVrJrLrKrMrrrrr es0)  cCsB|d}||}|s|d8}|dkr.d|Sd|||dSrrrrrr_format_range_contexts rccst|||||||tddddd}d} td|||D]R} | sd} |rVd|nd } |rhd|nd } d || |Vd || |V| d | d } }d|Vt| d|d}d||Vtdd| Dr| D]8\}}}}}|dkr|||D]}|||Vqqt| d|d}d||Vtdd| Dr:| D]<\}}}}}|dkrP|||D]}|||VqtqPq:dS)Nrrz! r)rQrPrOrRFTrrz *** {}{}{}rr rYz***************r'rz *** {} ****{}css |]\}}}}}|dkVqdS)>rPrONrr^rV_rrrr_s zcontext_diff..rQrXrz --- {} ----{}css |]\}}}}}|dkVqdS)>rOrQNrrrrrr_s rP)rdictrr]rrany)rrrrrrr5rprefixrr\rrrrrrVrJrLrrrrKrMrrrrs4,  cGs|r0t|dts0tdt|dj|df|r`t|dts`tdt|dj|df|D]}t|tsdtd|fqddS)Nr z)lines to compare must be str, not %s (%r)z"all arguments must be str, not: %r) isinstancestr TypeErrortyperd)rrargsargrrrrs r c cs~dd} tt| |}tt| |}| |}| |}| |}| |}| |}|||||||||} | D]} | ddVqfdS)Nc SsRz|ddWStk rL}z dt|j|f}t||W5d}~XYnXdS)Nasciisurrogateescapez(all arguments must be bytes, not %s (%r))decodeAttributeErrorrrdr)rmerrmsgrrrr"s zdiff_bytes..decoderr)rDrEencode) Zdfuncrrrrrrr5rrlinesrrrrr s cCst||||Sr)rr~)rrrurvrrrr5s#c#sddl}|dt||||ddgffdd fddfdd}|}|dkrj|EdHn|d 7}d}ddg|} } d } | d krzt|\} } } Wntk rYdSX| |}| | | f| |<| d 7} q| |krd V|}n| }d} |r"| |}| d 7} | |V|d 8}q|d }z@|rht|\} } } | rP|d }n|d 8}| | | fVq,Wqvtk rYdSXqvdS) Nr z (\++|\-+|\^+)c s||d7<|dkr2|||dddfS|dkr|d|d}}g}|fdd}||t|D]<\}\} } |d| d||| | d|| d}qt|dd}n*|ddd}|sd }d||d}|||fS) Nr'r r?cSs&||dd|g|dS)Nr'r )r+r\span)Z match_objectsub_inforrrrecord_sub_infosz3_mdiff.._make_line..record_sub_inforn)rBsubreversed) rZ format_keysideZ num_linestextZmarkersrrkeyZbeginend) change_rerr _make_lines   2z_mdiff.._make_linec3sng}d\}}t|dkr*|tdq ddd|D}|drP|}n|dr||dd |dd d fVq n|d r|d 8}|d d dd fVq nl|drֈ|d d d}}|d d }}n>|dr|dd |dd d fVq n|dr0|dd |dd d fVq n|d r\|d 8}|d d dd fVq n|dr|d 7}d|dd d fVq n|drd|dd }}|d d }}n^|dr|d 7}d|dd d fVq n2|dr|dddd |dd dfVq |d kr0|d 7}dVq|d krL|d 8}dVq0|dr\dS||d fVq dS)N)r r rXrcSsg|] }|dqS)r rr^rrrrrhsz2_mdiff.._line_iterator..z-?+?rr r'Tz--++rw)z--?+z--+rz-+?z-?+z+--rx)rz+-rnF)NrrT)rNT)r0r+nextrq startswith)rZnum_blanks_pendingZnum_blanks_to_yieldrm from_lineto_line)rdiff_lines_iteratorrr_line_iteratorsd            $     z_mdiff.._line_iteratorc3s}gg}}t|dks(t|dkrzt|\}}}Wntk rPYdSX|dk rh|||f|dk r|||fq|d\}}|d\}}|||p|fVqdSrA)r0r StopIterationr+rB)Z line_iterator fromlinestolinesrr found_diffZfromDiffZto_diff)rrr_line_pair_iterators  z#_mdiff.._line_pair_iteratorr'F)NNN)recompilerrr)rrcontextrurvrrZline_pair_iteratorZlines_to_writeindexZ contextLinesrrrr2r)rrrrr_mdiffZsR" 8X !    ran %(table)s%(legend)s aH table.diff {font-family:Courier; 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@seZdZeZeZeZeZdZdddefddZ dd d d d Z d dZ ddZ ddZ ddZddZddZddZdddZdS)r r NcCs||_||_||_||_dSr)_tabsize _wrapcolumn _linejunk _charjunk)rtabsizeZ wrapcolumnrurvrrrrs zHtmlDiff.__init__rFzutf-8)charsetc Cs:|jt|j|j|j||||||d|d|d|S)N)rnumlines)ZstylesZlegendtablerxmlcharrefreplace)_file_templater_styles_legend make_tablerr)rrrfromdesctodescrrrrrr make_files zHtmlDiff.make_filecs8fddfdd|D}fdd|D}||fS)Ncs6|dd}|j}|dd}|dddS)Nrnr r)rO expandtabsrr)r)rrr expand_tabss   z2HtmlDiff._tab_newline_replace..expand_tabscsg|] }|qSrrrrrrrhsz1HtmlDiff._tab_newline_replace..csg|] }|qSrrrrrrrhsr)rrrr)rrr_tab_newline_replaces zHtmlDiff._tab_newline_replacec Cs|s|||fdSt|}|j}||ksB||dd|krT|||fdSd}d}d}||kr||kr||dkr|d7}||}|d7}q`||dkr|d7}d}q`|d7}|d7}q`|d|} ||d} |r| d} d|| } ||| f||d| dS)NrrXr rr'r>)r+r0rcount _split_line) rZ data_listZline_numrrUrZr2r5ZmarkZline1Zline2rrrrs8        zHtmlDiff._split_linec cs|D]\}}}|dkr$|||fVq||\}}\}}gg} } || |||| ||| sd| r| rt| d}nd}| r| d}nd}|||fVq\qdS)Nr )rrn)rrB) rdiffsfromdatatodataflagZfromlineZfromtextZtolineZtotextfromlisttolistrrr _line_wrapper0s     zHtmlDiff._line_wrapperc Csggg}}}|D]r\}}}z4||jd|f|||jd|f|Wn(tk rz|d|dYnX||q|||fSr6)r+ _format_liner)rrrrflaglistrrrrrr_collect_linesLs  zHtmlDiff._collect_linescCsrzd|}d|j||f}Wntk r6d}YnX|dddddd }|d d }d |||fS) Nz%dz id="%s%s"r&z&rz>%s%s)_prefixrrOr)rrrZlinenumridrrrras zHtmlDiff._format_linecCs0dtj}dtj}tjd7_||g|_dS)Nzfrom%d_zto%d_r')r _default_prefixr)rZ fromprefixtoprefixrrr _make_prefixxs  zHtmlDiff._make_prefixcCs|jd}dgt|}dgt|}d\} } d} t|D]V\} } | r| sd} | } td| |g} d|| f|| <| d7} d|| f|| <q:d} q:|sdg}dg}dg}d} |rd g}|}n d g}}|dsd ||d<d ||| <|||||fS) Nr'r)r Fr Tz id="difflib_chg_%s_%d"z"nFz2 No Differences Found z( Empty File z!fz#t)rr0r)rZ)rrrrrrrnext_id next_hrefZnum_chgZ in_changerr2rrrr_convert_flagss>     zHtmlDiff._convert_flagsc CsR||||\}}|r"|}nd}t||||j|jd}|jrL||}||\} } } || | | ||\} } } } } g}d}t t | D]P}| |dkr|dkr| dq| || || || || || |fq|s|rddd|dd|f}nd}|j t d|||jd d }|d d d dddddddS)NrtzV %s%s%s%s r z) z %s%s%s%sz!
z+%srr')Z data_rows header_rowrz+zz-zz^zrzrr)r rrrrrrrr r8r0r+_table_templaterrqrrO)rrrrrrrZ context_linesrrrrr r rmZfmtr2r rrrrrsl       zHtmlDiff.make_table)rrFr)rrFr)rdrerfrrrrrrrrrrrrrr r rrrrrr s0  7 /ccsnzdddt|}Wn"tk r8td|dYnXd|f}|D]"}|dd|krF|ddVqFdS)Nrr)r'rz)unknown delta choice (must be 1 or 2): %rrr)intKeyErrorri)ZdeltaZwhichrVprefixesrrrrrscCsddl}ddl}||SrA)doctestdifflibZtestmod)rrrrr_test!sr__main__)rXrg)r)rrrrrXr)rrrrrXr)rrrrrXr)#__all__heapqrrj collectionsrZ _namedtupler rrrrsrrrmatchrrrr rrrr rrrrrrobjectr rrrdrrrrs    1 I   I  L %   a