B Ǫ9 @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@g?)matcheslengthrr*/opt/alt/python37/lib/python3.7/difflib.py_calculate_ratio&s rc@speZdZdddZddZdd Zd d Zd d ZddZddZ ddZ dddZ ddZ ddZ ddZdS)rNTcCs(||_d|_|_||_|||dS)N)isjunkabautojunkset_seqs)selfrrrrrrr__init__s; zSequenceMatcher.__init__cCs||||dS)N)set_seq1set_seq2)rrrrrrrs zSequenceMatcher.set_seqscCs$||jkrdS||_d|_|_dS)N)rmatching_blocksopcodes)rrrrrrs zSequenceMatcher.set_seq1cCs2||jkrdS||_d|_|_d|_|dS)N)rrr fullbcount_SequenceMatcher__chain_b)rrrrrrs   zSequenceMatcher.set_seq2c Cs|j}i|_}x*t|D]\}}||g}||qWt|_}|j}|rx"|D]}||r\| |q\Wx|D] }||=q|Wt|_ }t |} |j r| dkr| dd} x*| D]\}} t | | kr| |qWx|D] }||=qWdS)Nd)rb2j enumerate setdefaultappendsetbjunkrkeysaddZbpopularlenritems) rrr&ieltindicesZjunkrZpopularnZntestZidxsrrrZ __chain_b)s,          zSequenceMatcher.__chain_bcCsJ|j|j|j|jjf\}}}}||d} } } i} g} xt||D]}| j}i}xn|||| D]Z}||krpqb||krzP||ddd}||<|| krb||d||d|} } } qbW|} qBWx`| |kr(| |kr(||| ds(|| d|| dkr(| d| d| d} } } qWxV| | |kr| | |kr||| | s|| | || | kr| d7} q,Wxb| |kr| |kr||| dr|| d|| dkr| d| d| d} } } qWxV| | |kr<| | |kr<||| | r<|| | || | kr<| d} qWt| | | S)Nr r%)rrr&r+ __contains__rangegetr )raloahiblobhirrr&ZisbjunkZbestiZbestjZbestsizeZj2lenZnothingr0Zj2lengetZnewj2lenjkrrrfind_longest_matchPsB8$  "z"SequenceMatcher.find_longest_matchcCs|jdk r|jSt|jt|j}}d|d|fg}g}x|r|\}}}}|||||\} } } } | r:|| || kr|| kr||| || f| | |kr:| | |kr:|| | || | |fq:W|d} }}g}x^|D]V\}}}| ||kr|||kr||7}q|r2|| ||f|||} }}qW|r\|| ||f|||dftt t j ||_|jS)Nr ) rr.rrpopr=r)sortlistmapr _make)rlalbZqueuerr7r8r9r:r0r;r<xi1j1Zk1Z non_adjacenti2j2Zk2rrrget_matching_blockss8    z#SequenceMatcher.get_matching_blockscCs|jdk r|jSd}}g|_}x|D]\}}}d}||krP||krPd}n||kr^d}n ||krjd}|r||||||f||||}}|r,|d||||fq,W|S)Nr rreplacedeleteinsertequal)r rJr))rr0r;Zansweraibjsizetagrrr get_opcodess$  zSequenceMatcher.get_opcodesc csr|}|sdg}|dddkrZ|d\}}}}}|t||||t||||f|d<|dddkr|d\}}}}}||t||||t|||f|d<||}g} x|D]\}}}}}|dkr*|||kr*| ||t||||t|||f| Vg} t|||t|||}}| |||||fqW| rnt| dkrh| dddksn| VdS)N)rNr r%r r%r rNr%)rSmaxminr)r.) rr3ZcodesrRrFrHrGrInngrouprrrget_grouped_opcodes<s(&&(&z#SequenceMatcher.get_grouped_opcodescCs0tdd|D}t|t|jt|jS)Ncss|]}|dVqdS)rUNr).0Ztriplerrr sz(SequenceMatcher.ratio..)sumrJrr.rr)rrrrrrationszSequenceMatcher.ratiocCs|jdkr8i|_}x"|jD]}||dd||<qW|j}i}|jd}}xH|jD]>}||rl||}n ||d}|d||<|dkrV|d}qVWt|t|jt|jS)Nr r%)r!rr6r4rrr.)rr!r1ZavailZavailhasrZnumbrrr quick_ratios         zSequenceMatcher.quick_ratiocCs*t|jt|j}}tt||||S)N)r.rrrrW)rrCrDrrrreal_quick_ratiosz SequenceMatcher.real_quick_ratio)NrrT)rT)__name__ __module__ __qualname__rrrrr"r=rJrSrZr^r_r`rrrrr+sl @ ,'nG7 2rT333333?cCs|dkstd|fd|kr*dks:ntd|fg}t}||xL|D]D}||||krT||krT||krT|||fqTWt||}dd|DS)Nr zn must be > 0: %rgg?z cutoff must be in [0.0, 1.0]: %rcSsg|] \}}|qSrr)r[ZscorerErrr sz%get_close_matches..) ValueErrorrrrr`r_r^r) _nlargest)ZwordZ possibilitiesr3cutoffresultsrErrrrs       cCs4dt|}}x ||kr.|||kr.|d7}qW|S)Nr r%)r.)linechr0r3rrr_count_leadings  rmc@sFeZdZdddZddZddZdd Zd d Zd d ZddZ dS)rNcCs||_||_dS)N)linejunkcharjunk)rrnrorrrrMszDiffer.__init__c cst|j||}x|D]\}}}}}|dkrD|||||||} n\|dkr^|d|||} nB|dkrx|d|||} n(|dkr|d|||} ntd|f| EdHqWdS) NrKrL-rM+rN zunknown tag %r)rrnrS_fancy_replace_dumprf) rrrcruncherrRr7r8r9r:grrrcomparedszDiffer.compareccs*x$t||D]}d|||fVq WdS)Nz%s %s)r5)rrRrElohir0rrrrtsz Differ._dumpc csr||||kr2|d|||}|d|||}n |d|||}|d|||}x||fD]} | EdHq\WdS)Nrqrp)rt) rrr7r8rr9r:firstsecondrvrrr_plain_replaceszDiffer._plain_replaceccsFd\}}t|j} d\} } xt||D]} || } | | xxt||D]j}||}|| krp| dkrH|| } } qH| || |krH| |krH| |krH| || }}}qHWq&W||kr| dkr|||||||EdHdS| | d}}}nd} | ||||||EdH||||}}| dkrd}}| ||x| D]\}}}}}||||}}|dkr|d|7}|d|7}nb|dkr|d|7}nJ|d kr|d |7}n2|d kr|d |7}|d |7}nt d |fqRW| ||||EdHn d|V| ||d|||d|EdHdS)N)gGz?g?)NNg?rrK^rLrprMrqrNrrzunknown tag %rz r%)rror5rrr`r_r^r| _fancy_helperrrSrf_qformat)rrr7r8rr9r:Z best_ratiorhruZeqiZeqjr;rPr0rOZbest_iZbest_jZaeltZbeltatagsbtagsrRZai1Zai2Zbj1Zbj2rCrDrrrrssX                zDiffer._fancy_replaceccsbg}||kr<||kr*|||||||}qT|d|||}n||krT|d|||}|EdHdS)Nrprq)rsrt)rrr7r8rr9r:rvrrrr~szDiffer._fancy_helperccstt|dt|d}t|t|d|d}t|t|d|d}||d}||d}d|V|rdd||fVd|V|rdd||fVdS)N rrz- z? %s%s z+ )rWrmrstrip)rZalineZblinerrcommonrrrr s    zDiffer._qformat)NN) rarbrcrrwrtr|rsr~rrrrrrs^ )^ Nz \s*(?:#\s*)?$cCs ||dk S)Nr)rkZpatrrrr>s cCs||kS)Nr)rlZwsrrrrNscCs:|d}||}|dkr"d|S|s.|d8}d||S)Nr%z{}z{},{})format)startstop beginningrrrr_format_range_unifiedes rr ccsht|||||||d}xHtd|||D]0} |sd}|rJd|nd} |r\d|nd} d|| |Vd|| |V| d| d} } t| d | d }t| d | d }d |||Vx| D]\}}}}}|dkrx|||D]}d|VqWq|dkr2x |||D]}d|VqW|dkrx |||D]}d|VqHWqWq.WdS)NFTz {}rz --- {}{}{}z +++ {}{}{}r rUr%rTz@@ -{} +{} @@{}rNrr>rLrKrp>rKrMrq) _check_typesrrZrr)rrfromfiletofile fromfiledate tofiledater3linetermstartedrYfromdatetodaterzlast file1_range file2_rangerRrFrHrGrIrkrrrr ps0)  cCsB|d}||}|s|d8}|dkr.d|Sd|||dS)Nr%z{}z{},{})r)rrrrrrr_format_range_contexts rccst|||||||tddddd}d} xztd|||D]b} | sd} |rZd|nd } |rld|nd } d || |Vd || |V| d | d } }d|Vt| d|d}d||Vtdd| Dr&xD| D]<\}}}}}|dkrx$|||D]}|||Vq WqWt| d|d}d||Vtdd| Dr>xH| D]@\}}}}}|dkr^x$|||D]}|||VqWq^Wq>WdS)Nz+ z- z! z )rMrLrKrNFTz {}rz *** {}{}{}z --- {}{}{}r rUz***************r%rz *** {} ****{}css |]\}}}}}|dkVqdS)>rLrKNr)r[rR_rrrr\szcontext_diff..rMrTrz --- {} ----{}css |]\}}}}}|dkVqdS)>rKrMNr)r[rRrrrrr\ srL)rdictrrZrrany)rrrrrrr3rprefixrrYrrrzrrrRrFrHrrkrrGrIrrrrs4,  cGs|r0t|dts0tdt|dj|df|r`t|dts`tdt|dj|dfx$|D]}t|tsftd|fqfWdS)Nr z)lines to compare must be str, not %s (%r)z"all arguments must be str, not: %r) isinstancestr TypeErrortypera)rrargsargrrrrs  r c csdd} tt| |}tt| |}| |}| |}| |}| |}| |}|||||||||} x| D]} | ddVqhWdS)Nc SsPy |ddStk rJ}z dt|j|f}t||Wdd}~XYnXdS)Nasciisurrogateescapez(all arguments must be bytes, not %s (%r))decodeAttributeErrorrrar)rjerrmsgrrrr-s  zdiff_bytes..decoderr)r@rAencode) Zdfuncrrrrrrr3rrlinesrkrrrr "s  cCst||||S)N)rrw)rrrnrorrrr@s#c#sddl}|dt||||ddgffdd fddfdd}|}|dkrj|EdHn,|d 7}d}xddg|} } d } xR| d kryt|\} } } Wntk rdSX| |}| | | f| |<| d 7} qW| |krd V|}n| }d} x.|r,| |}| d 7} | |V|d 8}qW|d }yDx>|rvt|\} } } | r^|d }n|d 8}| | | fVq:WWqztk rdSXqzWdS) Nr z (\++|\-+|\^+)c s||d7<|dkr2|||dddfS|dkr|d|d}}g}|fdd}||xHt|D]<\}\} } |d| d||| | d|| d}qvW|dd}n*|ddd}|sd }d||d}|||fS) Nr%r r?cSs&||dd|g|dS)Nr%r )r)rYspan)Z match_objectsub_inforrrrecord_sub_infosz3_mdiff.._make_line..record_sub_inforr)r>subreversed) rZ format_keysideZ num_linestextZmarkersrrkeyZbeginend) change_rerr _make_lines   4z_mdiff.._make_linec3sg}d\}}xlx t|dkr0|tdqWddd|D}|drX|}n|dr|dd |dd d fVqn|d r|d 8}|d d dd fVqnl|drވ|d d d}}|d d }}n>|dr |dd |dd d fVqn|dr8|dd |dd d fVqn|d rd|d 8}|d d dd fVqn|dr|d 7}d|dd d fVqn|drd|dd }}|d d }}n^|dr|d 7}d|dd d fVqn2|dr|dddd |dd dfVqx|d kr:|d 7}dVqWx|d krZ|d 8}dVq>W|drldS||d fVqWdS)N)r r rXrcSsg|] }|dqS)r r)r[rkrrrresz2_mdiff.._line_iterator..z-?+?rr r%Tz--++rp)z--?+z--+z- z-+?z-?+z+--rq)z+ z+-rrF)N)rrT))rrNT)r.r)nextjoin startswith)rZnum_blanks_pendingZnum_blanks_to_yieldrj from_lineto_line)rdiff_lines_iteratorrr_line_iteratorsf           $     z_mdiff.._line_iteratorc3s}gg}}xxpt|dks,t|dkryt|\}}}Wntk rRdSX|dk rj|||f|dk r|||fqW|d\}}|d\}}|||p|fVqWdS)Nr )r.r StopIterationr)r>)Z line_iterator fromlinestolinesrr found_diffZfromDiffZto_diff)rrr_line_pair_iterators  z#_mdiff.._line_pair_iteratorr%F)NNN)recompilerrr)rrcontextrnrorrZline_pair_iteratorZlines_to_writeindexZ contextLinesrrrr0r)rrrrr_mdiffesT" 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||_||_||_||_dS)N)_tabsize _wrapcolumn _linejunk _charjunk)rtabsizeZ wrapcolumnrnrorrrrs 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)Nrrrrr)rK expandtabsrr)rk)rrr expand_tabss   z2HtmlDiff._tab_newline_replace..expand_tabscsg|] }|qSrr)r[rk)rrrresz1HtmlDiff._tab_newline_replace..csg|] }|qSrr)r[rk)rrrresr)rrrr)rrr_tab_newline_replaces zHtmlDiff._tab_newline_replacec Cs|s|||fdSt|}|j}||ksB||dd|krT|||fdSd}d}d}xd||kr||kr||dkr|d7}||}|d7}qb||dkr|d7}d}qb|d7}|d7}qbW|d|} ||d} |r| d} d|| } ||| f||d| dS)NrrTr rr%r>)r)r.rcount _split_line) rZ data_listZline_numrrQrVr0r3ZmarkZline1Zline2rrrrs8        zHtmlDiff._split_linec csx|D]\}}}|dkr&|||fVq||\}}\}}gg} } || |||| ||x@| sh| r| rx| d}nd}| r| d}nd}|||fVq`WqWdS)Nr )rrr)rr>) rdiffsfromdatatodataflagZfromlineZfromtextZtolineZtotextfromlisttolistrrr _line_wrapper;s      zHtmlDiff._line_wrapperc Csggg}}}xz|D]r\}}}y4||jd|f|||jd|f|Wn(tk r||d|dYnX||qW|||fS)Nr r%)r) _format_liner)rrrrflaglistrrrrrr_collect_linesWs zHtmlDiff._collect_linescCsryd|}d|j||f}Wntk r6d}YnX|dddddd }|d d }d |||fS) Nz%dz id="%s%s"r&z&rz>%s%s)_prefixrrKr)rrrZlinenumridrrrrls zHtmlDiff._format_linecCs0dtj}dtj}tjd7_||g|_dS)Nzfrom%d_zto%d_r%)r _default_prefixr)rZ fromprefixtoprefixrrr _make_prefixs  zHtmlDiff._make_prefixcCs|jd}dgt|}dgt|}d\} } d} xbt|D]V\} } | r| sd} | } td| |g} d|| f|| <| d7} d|| f|| <qnFz2 No Differences Found z( Empty File z!fz#t)rr.r'rV)rrrrrrrnext_id next_hrefZnum_chgZ in_changerr0rrrr_convert_flagss:    zHtmlDiff._convert_flagsc CsV||||\}}|r"|}nd}t||||j|jd}|jrL||}||\} } } || | | ||\} } } } } g}d}x`t t | D]P}| |dkr|dkr| dq| || || || || || |fqW|s|rddd|dd|f}nd}|j t d|||jd d }|d d d dddddddS)N)rnrozV %s%s%s%s r z) z %s%s%s%sz!
z+%srr%)Z data_rows header_rowrz+zz-zz^zrzrz )rrrrrrrrrr5r.r)_table_templaterrrrK)rrrrrrrZ context_linesrrrrrrrjZfmtr0rrrrrrsH       zHtmlDiff.make_table)rrFr)rrFr)rarbrcrrrrrrrrrrrrrrrrrrrrr s$ 7 /ccsrydddt|}Wn"tk r8td|dYnXd|f}x*|D]"}|dd|krH|ddVqHWdS)Nz- z+ )r%rz)unknown delta choice (must be 1 or 2): %rz r)intKeyErrorrf)ZdeltaZwhichrRprefixesrkrrrr s cCsddl}ddl}||S)Nr )doctestdifflibZtestmod)rrrrr_test,sr__main__)rTrd)r)rrrrrTr)rrrrrTr)rrrrrTr)#__all__heapqrrg collectionsrZ _namedtupler rrrrmrrrmatchrrrr rrrr rrrrrrobjectr rrrarrrrs\     0O   H  K % !  a