mò .á¸Ec@s|dZdddfZdZdkZeidƒid„Zdd„Z[d fd „ƒYZd „Z hd d <dd<dd<dd file1_or_file2 Print a human-friendly file difference report to stdout. Both inter- and intra-line differences are noted. In the second form, recreate file1 (-r1) or file2 (-r2) on stdout, from an ndiff report on stdin. In the first form, if -q ("quiet") is not specified, the first two lines of output are -: file1 +: file2 Each remaining line begins with a two-letter code: "- " line unique to file1 "+ " line unique to file2 " " line common to both files "? " line not present in either input file Lines beginning with "? " attempt to guide the eye to intraline differences, and were not present in either input file. These lines can be confusing if the source files contain tab characters. The first file can be recovered by retaining only lines that begin with " " or "- ", and deleting those 2-character prefixes; use ndiff with -r1. The second file can be recovered similarly, but by retaining only " " and "+ " lines; use ndiff with -r2; or, on Unix, the second file can be recovered by piping the output through sed -n '/^[+ ] /s/^..//p' See module comments for details and programmatic interface. iiiNs \s*#?\s*$cCs||ƒdj S(N(tpattlinetNone(RR((t(/data/zmath/zope/lib/python/OFS/ndiff.pyt IS_LINE_JUNKiss cCs ||jS(N(tchtws(RR((RtIS_CHARACTER_JUNKlstSequenceMatchercBs}tZdddd„Zd„Zd„Zd„Zd„Zd„Zd„Z d „Z d „Z d „Z d „Z d „ZRS(NtcCs-||_d|_|_|i||ƒdS(N(tisjunktselfRtatbtset_seqs(R R R R ((Rt__init__rs& cCs|i|ƒ|i|ƒdS(N(R tset_seq1R tset_seq2R (R R R ((RRœs cCs5||ijodSn||_d|_|_dS(N(R R Rtmatching_blockstopcodes(R R ((RR s cCsH||ijodSn||_d|_|_d|_|iƒdS(N(R R RRRt fullbcountt_SequenceMatcher__chain_b(R R ((RR¦s   cCsà|i}h|_}|i|_}xStt|ƒƒD]?}||}||ƒo||i |ƒq9|g||= 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. 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. If no blocks match, return (alo, blo, 0). iitget_matching_blockss returnsN(R R R RR talotblotbestitbestjtbestsizetj2lentnothingRtahiRtgettj2lengettnewj2lentjtbhitktTRACE(R R#R*R$R/R%R R&RR-R'R.R R R)R,R(R0R((Rtfind_longest_matchàs:*    , L%TcCs–|idj o |iSng|_t|iƒt|iƒ}}|id|d||iƒ|ii ||dfƒt odG|iGHn|iS(Nis*** matching blocks( R RRRR R tlatlbt_SequenceMatcher__helperRR1(R R4R3((RR"4s  c Cs¿|i||||ƒ\}}} }| o||jo*||jo|i |||||ƒn|i |ƒ|| |jo6|| |jo%|i || ||| ||ƒq»ndS(N( R R2R#R*R$R/RR.R0txR5tanswerR( R R#R*R$R/R7R.RR6R0((Rt__helperBs% "cCs=td„|iƒdƒ}d|t|iƒt|iƒS(s/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*M / T. Note that this is 1 if the sequences are identical, and 0 if they have nothing in common. cCs ||dS(Niÿÿÿÿ(tsumttriple(R9R:((RtWsif2.0N(treduceR R"tmatchesRR R (R R=((RtratioNs cCsú|idjo?h|_}x/|iD] }|i|dƒd||RBRDRM(((RRqs*    ' T   cCs*x#t||ƒD]}|G||GqWdS(N(RtlothiRRLR6(RLR6RPRQR((Rtdump–ss t s. t-s .t+s..t^cCsŠ||jo ||jpt‚||||jo*td|||ƒtd|||ƒn'td|||ƒtd|||ƒdS(NRURT(R#R*R$R/tAssertionErrorRRR R (R R#R*R R$R/((Rt plain_replace¡s !cCsûto?dG|G|G|G|GHtd|||ƒtd|||ƒnd\}}t t ƒ}d\}}xèt||ƒD]×}||}|i|ƒx·t||ƒD]¦}||}||jo%|djo||}}q§q§n|i|ƒ|iƒ|joD|iƒ|jo1|iƒ|jo|iƒ||}} } q§q§WqzW||joF|djo!t||||||ƒdSn||d} } }nd}toCdG|G| G| GHtd|| | dƒtd|| | dƒnt||| ||| ƒ|| || }}|djo›d }}|i"||ƒxÞ|i#ƒD]Ð\} }}}}||||} } | d jo |d | }|d | }qZ| d jo|d | }qZ| d jo|d | }qZ| djo |d| }|d| }qZt+d| ‚qZWt,|ƒt,|ƒ} } | | jo|d| | }n$| | jo|d| | }nt-d„||ƒ}dG|GdG|GdGd i/|ƒi0ƒGHn dG|Gt|| d||| d|ƒdS(Ns*** fancy_replacet>ttbest_itbest_jRXt fancy_helpertaelttbelttatagstbtagsRRMRLtai1tai2tbj1tbj2R3R4t ValueErrorRtmaptcombinedtjointrstrip(R R#R*R R$R/R`RIRgRLRdReR4R3RaRkRlRbRcRqR_RhRJRjRnRmRiRR.((Rt fancy_replace±sv         9&           ,cCsv||joA||jot||||||ƒqrtd|||ƒn%||jotd|||ƒndS(NRTRU(R#R*R$R/RtR R RR(R R#R*R R$R/((RRf s    cCs1dk}|ii}||dƒ|tƒdS(Ns i(tsyststderrtwritetouttmsgt__doc__(RyRuRx((Rtfails    cCsIyt|dƒSWn1tj o%}td|dt|ƒƒSnXdS(Ntrscouldn't open s: (topentfnametIOErrortdetailR{tstr(R~R€((Rtfopensc Cs<t|ƒ}t|ƒ}| p| odSn|iƒ}|iƒ|iƒ}|iƒt t ||ƒ}xÇ|i ƒD]¹\} }}} } | djot||||| | ƒq{| djotd|||ƒq{| djotd|| | ƒq{| djotd|||ƒq{td | ‚q{Wd S( NiRERFRTRGRURHRSs unknown tag i(R‚tf1nametf1tf2nametf2t readlinesR tcloseR RRRaRMRLR#R*R$R/RtRRRo( RƒR…R R„R†R R#RaR*R$R/RL((Rtfcompare&s&       c Csmdk}y|i|dƒ\} }Wn(|ij o}tt|ƒƒSnXd} d}}xN| D]F\}}|djod}d} qg|djod}|} qgqgW|o|otdƒSn|oB|otdƒSn| djot | ƒdSntd ƒSnt|ƒd jotd ƒSn|\}}| od G|GHd G|GHnt||ƒS(Nsqr:iis-qs-rscan't specify both -q and -rsno args allowed with -r optiont12s-r value must be 1 or 2isneed 2 filename argss-:s+:(tgetopttargstoptsterrorR€R{Rtnoisytqseentrseentopttvalt whichfiletrestoreRRƒR…R‰( RŒR’R“R…R€RƒRR‹R‘R”RR((RtmainAs>           cCsldk}hdd<dd<|}d|f}x4|iiƒD]#}|d |jo |dGqAqAWdS(Nt1s- t2s+ s i(RutwhichRLtprefixeststdinR‡R(R™RuRšRRL((RR•as  t__main__s-profiles ndiff.pros main(args)ttime(!Rzt __version__R1tretcompiletmatchRRRRRR\RXRtRfR{R‚R‰R–R•RNRutargvRŒtprofiletpstatstremovetstatftruntStatststatst strip_dirst sort_statst print_stats(R•RRR{RXR‚R©R¦RŸRR–RR£R‰RŒRuR\RtRRžRfR1R¤((RR^,s:6  ÿ& *  \