B ÔÂ_6ã@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ej dkrfe Z ddl Z e d¡Ze d¡Ze d¡Zdd„Zd d d „Zd d „Zd!d d„Zdd„Zdd„Zddgdddfdd„Zddddgddfdd„Zddddgdfdd„ZdS)"éN)érz@(?#sz'remove_chars_in_list..)ÚlenÚjoin)Úsrr)rrÚremove_chars_in_lists r rcCsLd}xB|dkrF| |¡}t|ƒdkr&Pt||ƒ}|t|ƒ8}||}qW|S)Nrr)Úreadr r )ÚfZncharsrZretBufÚbufrrrÚget_desired_chars_from_file&s      rcCsôtj |¡std|dƒ‚yt |¡}Wnd}YnX|r¬t |d¡}t| ¡ƒdkrltd|dƒ‚t j dkrŠ|  | ¡dd¡St j |  | ¡dd¡d d d SnD| d ¡ræt j dkrÌt  |d¡St j t  |d¡d d d Sn t |dƒSdS) Nzcannot find file `ú'FÚréz>cannot compare with a zip file that contains multiple files: `)rrrzutf-8r)ÚencodingÚnewlinez.gz)ÚosÚpathÚexistsÚIOErrorÚzipfileÚ is_zipfileÚZipFiler ÚnamelistÚsysÚ version_infoÚopenÚioÚ TextIOWrapperÚendswithÚgzip)ÚfilenamerZzf1rrrÚopen_possibly_compressed_file4s*       r'c CsFt|ƒ}| ¡}x&tdt|ƒƒD]}|| ¡||<q W| ¡t|ƒ}| ¡}x&tdt|ƒƒD]}|| ¡||<q`W| ¡d} |dkr¶x´tj||||dD]} | | d7} q WnŒ|dkrÂd}||} ||} | dkrÞd} | t|ƒkròt|ƒ} | t|ƒkrt|ƒ} x8tj|| | …|| | …||dD]} | | d7} q,W| S)Nrr)ZfromfileZtofileÚ r)r'Ú readlinesÚranger ÚstripÚcloseÚdifflibZ unified_diff) Ú filename1Ú filename2ÚlinenoÚcontextÚINPUT1Zlines1ÚiÚINPUT2Zlines2r ÚlineÚstartÚstoprrrÚ file_diffOs@    r8cCs„d}d}xr|sz| ¡}|d7}|dkr.d|fSt||ƒ}|sBd}q |dk rt||ƒ}|dkr`d}qx|dkrn|}qx|}q |}q W||fS)NrrrFT)Úreadliner )ÚstreamZ ignore_charsÚfilterr0r5Zline_ÚfilteredrrrÚread_and_filter_lineus( r=cCsJg}x@| |¡}|dkr ||fS| t| ¡ƒ¡|jd|dd}qWdS)Nz # r)Úcount)ÚsearchÚappendÚfloatÚgroupÚsub)r5ÚregexZansÚgrrrÚ_extract_floats‘s rFr(ú gTc CsÈtj |¡s(td|dt ¡dƒ‚tj |¡sPtd|dt ¡dƒ‚|rZt}nt}y |\}}Wn|}}YnXd} } z t|ƒ} t|ƒ} d} xðyt| ||ƒ\} } Wn4t k rìt   ¡d}t d|t |ƒfƒ‚YnX| | 7} yt| ||ƒd}Wn6t k r@t   ¡d}t d|t |ƒfƒ‚YnX| dkr`|dkr`ddd gS| dkst|dkrˆd | t||| d gSy t| |ƒ\}} t||ƒ\}}Wnd | t||| d gSt|ƒt|ƒkrêd | t||| d gSxht||ƒD]Z\}}t ||¡}tt |¡t |¡ƒ}||krö|||kröd | t||| d gSqöWt d |  ¡¡} t d | ¡¡}| |kr¤d | t||| d gSq¤WWd| dk rª|  ¡| dk r¼|  ¡Xddd gS) aÁ Do a simple comparison of two files that ignores differences in newline types and whitespace. Numeric values are compared within a specified tolerance. The return value is the tuple: (status,lineno). If status is True, then a difference has occured on the specified line number. If the status is False, then lineno is None. The goal of this utility is to simply indicate whether there are differences in files. The Python 'difflib' is much more comprehensive and consequently more costly to apply. The shutil.filecmp utility is similar, but it does not ignore differences in file newlines. Also, this utility can ignore an arbitrary set of characters. z compare_file: cannot find file `z' (in ú)Nrrz+Decoding error while processing file %s: %sFrT)r0ú )rrrrÚgetcwdÚstrict_float_pÚrelaxed_float_pr'r=ÚUnicodeDecodeErrorrÚexc_infoÚ RuntimeErrorÚstrr8rFr ÚzipÚmathÚfabsÚmaxÚ whitespace_prCr+r,)r.r/Úignorer;Ú toleranceÚstrict_numbersZfloat_pZabsolute_toleranceZrelative_tolerancer2r4r0Úline1Ú delta_linenoÚerrÚline2Zfloats1Zfloats2Zv1Zv2ZvDiffZvMaxrrrÚ compare_file_with_numeric_values›s„          r]ú rIcCsŠ|dk r\t |¡}| d¡| d¡y |\}}Wn|}d}YnXt||||||dStj |¡s„td|dt ¡dƒ‚tj |¡s¬td|dt ¡dƒ‚d}} zªt|ƒ}t|ƒ} t j   d ¡sðt  |¡t  |¡krðd dd gSd } xft |||ƒ\} } | | 7} t | ||ƒd } | dkr<| dkr s@    &  u  R