a �DOgkE�@s,gd�ZddlmZddlmZddlmZedd�Z dd�Z Gd d �d �Z d9d d�Z dd�Z Gdd�d�ZddlZe�d�jfdd�Zd:dd�Zdd�Zd;dd�Zd d!�Zd) �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 sizecCs|rd||SdS)Ng@��?�)�matches�lengthrr�/usr/lib64/python3.9/difflib.py�_calculate_ratio's rc@szeZdZddd�Zdd�Zdd �Zd d �Zd d �Zddd�Zdd�Z dd�Z d dd�Z dd�Z dd�Z dd�Zee�ZdS)!rN�TcCs(||_d|_|_||_|�||�dS�N)�isjunk�a�b�autojunk�set_seqs)�selfrrrrrrr�__init__xs; zSequenceMatcher.__init__cCs|�|�|�|�dSr)�set_seq1�set_seq2)rrrrrrr�s zSequenceMatcher.set_seqscCs$||jurdS||_d|_|_dSr)r�matching_blocks�opcodes)rrrrrr �s zSequenceMatcher.set_seq1cCs2||jurdS||_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] }||=q�dS)N���d�)r�b2j� enumerate� setdefault�append�set�bjunkr�keys�addZbpopular�lenr�items) rrr)�i�elt�indicesZjunkrZpopular�nZntestZidxsrrrZ __chain_b s,           zSequenceMatcher.__chain_br cCsT|j|j|j|jjf\}}}}|dur.t|�}|dur>t|�}||d} } } i} g} t||�D]�}| j}i}|�||| �D]\}||kr�q~||kr�q�||dd�d}||<|| kr~||d||d|} } } q~|} q`| |k�r@| |k�r@||| d��s@|| d|| dk�r@| d| d| d} } } q�| | |k�r�| | |k�r�||| | ��s�|| | || | k�r�| d7} �q@| |k�r�| |k�r�||| d��r�|| d|| dk�r�| d| d| d} } } �q�| | |k�rH| | |k�rH||| | ��rH|| | || | k�rH| d} �q�t| | | �S�Nr r() rrr)r.� __contains__r1�range�getr )r�alo�ahi�blo�bhirrr)ZisbjunkZbestiZbestjZbestsizeZj2lenZnothingr3Zj2lengetZnewj2len�j�krrr�find_longest_match1sZ:"���� �� �� z"SequenceMatcher.find_longest_matchcCs||jdur|jSt|j�t|j�}}d|d|fg}g}|r�|��\}}}}|�||||�\} } } } | r8|�| �|| kr�|| kr�|�|| || f�| | |kr8| | |kr8|�| | || | |f�q8|��d} }}g}|D]V\}}}| ||k�r|||k�r||7}q�|�r,|�| ||f�|||} }}q�|�rT|�| ||f�|�||df�tt t j |��|_|jS�Nr ) r"r1rr�poprAr,�sort�list�mapr �_make)r�la�lb�queuer"r;r<r=r>r3r?r@�x�i1�j1Zk1Z non_adjacent�i2�j2Zk2rrr�get_matching_blocks�s8    z#SequenceMatcher.get_matching_blockscCs�|jdur|jSd}}g|_}|��D]�\}}}d}||krN||krNd}n||kr\d}n ||krhd}|r�|�|||||f�||||}}|r*|�d||||f�q*|S)Nr r�replace�delete�insert�equal)r#rPr,)rr3r?Zanswer�ai�bj�size�tagrrr� get_opcodes�s$  zSequenceMatcher.get_opcodes�c csn|��}|sdg}|dddkrZ|d\}}}}}|t|||�|t|||�|f|d<|dddkr�|d\}}}}}||t|||�|t|||�f|d<||}g} |D]�\}}}}}|dk�r(|||k�r(| �||t|||�|t|||�f�| Vg} t|||�t|||�}}| �|||||f�q�| �rjt| �dk�rd| dddk�sj| VdS)N)rTr r(r r(r rT�����r()rY�max�minr,r1) rr6ZcodesrXrLrNrMrO�nn�grouprrr�get_grouped_opcodes#s(&&(&z#SequenceMatcher.get_grouped_opcodescCs0tdd�|��D��}t|t|j�t|j��S)Ncss|]}|dVqdS)r[Nr)�.0Ztriplerrr� k�z(SequenceMatcher.ratio..)�sumrPrr1rr)rrrrr�ratioUszSequenceMatcher.ratiocCs�|jdur4i|_}|jD]}|�|d�d||<q|j}i}|jd}}|jD]>}||�rf||}n |�|d�}|d||<|dkrP|d}qPt|t|j�t|j��Sr7)r$rr:r8rrr1)rr$r4ZavailZavailhasrZnumbrrr� quick_rations         zSequenceMatcher.quick_ratiocCs*t|j�t|j�}}tt||�||�Sr)r1rrrr])rrHrIrrr�real_quick_ratio�sz SequenceMatcher.real_quick_ratio)NrrT)r Nr N)rZ)�__name__� __module__� __qualname__rrr r!r%rArPrYr`rerfrg� classmethodr�__class_getitem__rrrrr,sL @ ,' tG7 2 rrZ�333333�?cCs�|dkstd|f��d|kr*dks:ntd|f��g}t�}|�|�|D]D}|�|�|��|krR|��|krR|��|krR|�|��|f�qRt||�}dd�|D�S)Nr zn must be > 0: %rgrz cutoff must be in [0.0, 1.0]: %rcSsg|] \}}|�qSrr)raZscorerKrrr� �rcz%get_close_matches..) � ValueErrorrr!r rgrfrer,� _nlargest)ZwordZ possibilitiesr6�cutoff�result�srKrrrr�s"    � � rcCsd�dd�t||�D��S)Nrcss*|]"\}}|dkr|��r|n|VqdS)� N)�isspace)ra�cZtag_crrrrb�s�z$_keep_original_ws..)�join�zip)rsZtag_srrr�_keep_original_ws�s �ryc@sFeZdZddd�Zdd�Zdd�Zdd �Zd d �Zd d �Zdd�Z dS)rNcCs||_||_dSr��linejunk�charjunk)rr{r|rrrr*szDiffer.__init__c cs�t|j||�}|��D]�\}}}}}|dkrB|�||||||�} n\|dkr\|�d|||�} nB|dkrv|�d|||�} n(|dkr�|�d|||�} ntd|f��| EdHqdS) NrQrR�-rS�+rTrt�unknown tag %r)rr{rY�_fancy_replace�_dumpro) rrr�cruncherrXr;r<r=r>�grrr�compareAszDiffer.compareccs&t||�D]}d|||fVq dS)Nz%s %s)r9)rrXrK�lo�hir3rrrr�jsz Differ._dumpc csn||||kr2|�d|||�}|�d|||�}n |�d|||�}|�d|||�}||fD]} | EdHqZdS)Nr~r})r�) rrr;r<rr=r>�first�secondr�rrr�_plain_replaceos zDiffer._plain_replaceccs:d\}}t|j�} d\} } t||�D]�} || } | �| �t||�D]j}||}|| krl| durD|| } } qD| �|�| ��|krD| ��|krD| ��|krD| ��|| }}}qDq$||kr�| dur�|�||||||�EdHdS| | d}}}nd} |� ||||||�EdH||||}}| du�r d}}| � ||�| � �D]�\}}}}}||||}}|dk�r�|d|7}|d|7}nb|dk�r�|d|7}nJ|d k�r�|d |7}n2|d k�r�|d |7}|d |7}nt d |f���qH|� ||||�EdHn d|V|� ||d|||d|�EdHdS)N)g�G�z��?g�?)NNrrrQ�^rRr}rSr~rTrtr� r()rr|r9r!r rgrfrer�� _fancy_helperrrYro�_qformat)rrr;r<rr=r>Z best_ratiorqr�ZeqiZeqjr?rVr3rUZbest_iZbest_jZaeltZbelt�atags�btagsrXZai1Zai2Zbj1Zbj2rHrIrrrr�}s\      � �         zDiffer._fancy_replaceccsbg}||kr<||kr*|�||||||�}qT|�d|||�}n||krT|�d|||�}|EdHdS)Nr}r~)r�r�)rrr;r<rr=r>r�rrrr��szDiffer._fancy_helperccsXt||���}t||���}d|V|r8d|�d�Vd|V|rTd|�d�VdS)N�- z? � �+ )ry�rstrip)rZalineZbliner�r�rrrr��s  zDiffer._qformat)NN) rhrirjrr�r�r�r�r�r�rrrrr�sV )^ rNz \s*(?:#\s*)?$cCs ||�duSrr)�line�patrrrrsr� cCs||vSrr)Zch�wsrrrr%srcCs:|d}||}|dkr"d�|�S|s.|d8}d�||�S�Nr(z{}z{},{}��format��start�stopZ beginningrrrr�_format_range_unified<s r�rr�ccsPt|||||||�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|Vq�q�|dv�r"|||�D]}d|V�q|dvr�|||�D]}d|V�q6q�q*dS)NFT� {}r� --- {}{}{}z +++ {}{}{}r r[r(�rZ�z@@ -{} +{} @@{}rTrt>rQrRr}>rQrSr~)� _check_typesrr`r�r�)rr�fromfile�tofile� fromfiledate� tofiledater6�lineterm�startedr_�fromdate�todater��last� file1_range� file2_rangerXrLrNrMrOr�rrrr Gs0)  r cCsB|d}||}|s|d8}|dkr.d�|�Sd�|||d�Sr�r�r�rrr�_format_range_context�s r�ccs�t|||||||�tddddd�}d} td||��|�D�]R} | s�d} |rVd�|�nd } |rhd�|�nd } d �|| |�Vd �|| |�V| d | d } }d|Vt| d|d�}d�||�Vtdd�| D���r| D]8\}}}}}|dkr�|||�D]}|||V�qq�t| d|d�}d�||�Vtdd�| D��r:| D]<\}}}}}|dk�rP|||�D]}|||V�qt�qPq:dS)Nr�r�z! r�)rSrRrQrTFTr�rz *** {}{}{}r�r r[z***************r(r�z *** {} ****{}css |]\}}}}}|dvVqdS)>rQrRNr�rarX�_rrrrb�rczcontext_diff..rSrZr�z --- {} ----{}css |]\}}}}}|dvVqdS)>rQrSNrr�rrrrb�rcrR)r��dictrr`r�r��any)rrr�r�r�r�r6r��prefixr�r_r�r�r�r�r�rXrLrNr�r�r�rMrOrrrr�s4,  rcGs�|r0t|dt�s0tdt|d�j|df��|r`t|dt�s`tdt|d�j|df��|D]}t|t�sdtd|f��qddS)Nr z)lines to compare must be str, not %s (%r)z"all arguments must be str, not: %r)� isinstance�str� TypeError�typerh)rr�args�argrrrr��s�� r�rc� c cs~dd�} tt| |��}tt| |��}| |�}| |�}| |�}| |�}| |�}|||||||||�} | D]} | �dd�VqfdS)Nc SsTz|�dd�WStyN}z(dt|�j|f}t|�|�WYd}~n d}~00dS)N�ascii�surrogateescapez(all arguments must be bytes, not %s (%r))�decode�AttributeErrorr�rhr�)rs�err�msgrrrr�s �zdiff_bytes..decoder�r�)rErF�encode) Zdfuncrrr�r�r�r�r6r�r��linesr�rrrr �s r cCst||��||�Sr)rr�)rrr{r|rrrrs#rc#s�ddl}|�d��t||||��ddgf�fdd� ���fdd���fdd�}|�}|durj|EdH�n|d 7}d}ddg|} } d } | d ur�zt|�\} } } Wnty�YdS0| |}| | | f| |<| d 7} q�| |kr�d V|}n| }d} |�r | |}| d 7} | |V|d 8}q�|d }z@|�rft|�\} } } | �rN|d }n|d 8}| | | fV�q*Wqvt�y~YdS0qvdS) Nr z (\++|\-+|\^+)c s�||d7<|dur2|||�d�dd�fS|dkr�|�d�|�d�}}g}|fdd�}��||�t|�D]<\}\} } |d| �d||| | �d|| d�}qt|dd�}n*|�d�dd�}|s�d }d||d}|||fS) Nr(r r��?cSs&|�|�d�d|��g�|�d�S)Nr(r )r,r_�span)Z match_object�sub_inforrr�record_sub_info�sz3_mdiff.._make_line..record_sub_info��rt)rC�sub�reversed) r�Z format_key�sideZ num_lines�textZmarkersr�r��keyZbegin�end)� change_rerr� _make_linefs   2z_mdiff.._make_linec3sng}d\}}t|�dkr*|�t�d��q d�dd�|D��}|�d�rP|}�n�|�d�r|�|dd ��|dd �d fVq �n�|�d �r�|d 8}�|d d �dd fVq �nl|�d�rֈ|d d �d}}|d d }}�n>|�d��r�|dd ��|dd �d fVq �n|�d��r0�|dd ��|dd �d fVq n�|�d ��r\|d 8}�|d d �dd fVq n�|�d��r�|d 7}d�|dd �d fVq n�|�d��r�d�|dd �}}|d d }}n^|�d��r�|d 7}d�|dd �d fVq n2|�d��r�|dd�dd ��|dd �dfVq |d k�r0|d 7}dV�q|d k�rL|d 8}dV�q0|�d��r\dS||d fVq dS)N)r r r��XrcSsg|] }|d�qS)r r�rar�rrrrn�rcz2_mdiff.._line_iterator..z-?+?r�r r(Tz--++r})z--?+z--+r�z-+?z-?+z+--r~)r�z+-rtF)N�rr�T)r�NT)r1r,�nextrw� startswith)r�Znum_blanks_pendingZnum_blanks_to_yieldrs� from_line�to_line)r��diff_lines_iteratorrr�_line_iterator�sd            $     z_mdiff.._line_iteratorc3s���}gg}}t|�dks(t|�dkr~zt|�\}}}WntyNYdS0|durf|�||f�|dur|�||f�q|�d�\}}|�d�\}}|||p�|fVqdSrB)r1r�� StopIterationr,rC)Z line_iterator� fromlines�tolinesr�r�� found_diffZfromDiffZto_diff)r�rr�_line_pair_iterator�s   z#_mdiff.._line_pair_iteratorr(F)NNN)�re�compilerr�r�)r�r��contextr{r|r�r�Zline_pair_iteratorZlines_to_write�indexZ contextLinesr�r�r�r3r)r�r�r�r�r�_mdiff<sR" 8X !     r�an %(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@s�eZdZeZeZeZeZdZdddefdd�Z dd d �d d �Z d d�Z dd�Z dd�Z dd�Zdd�Zdd�Zdd�Zddd�ZdS)r r �NcCs||_||_||_||_dSr)�_tabsize� _wrapcolumn� _linejunk� _charjunk)r�tabsizeZ wrapcolumnr{r|rrrr�s zHtmlDiff.__init__rF�zutf-8)�charsetc Cs:|jt|j|j|j||||||d�|d��|d��|�S)N)r��numlines)ZstylesZlegend�tabler��xmlcharrefreplace)�_file_templater��_styles�_legend� make_tabler�r�)rr�r��fromdesc�todescr�r�r�rrr� make_file�s ����zHtmlDiff.make_filecs8�fdd���fdd�|D�}�fdd�|D�}||fS)Ncs6|�dd�}|��j�}|�dd�}|�dd��d�S)Nrtr�� r�)rQ� expandtabsr�r�)r�)rrr� expand_tabs�s   z2HtmlDiff._tab_newline_replace..expand_tabscsg|] }�|��qSrrr��r�rrrn�rcz1HtmlDiff._tab_newline_replace..csg|] }�|��qSrrr�r�rrrn�rcr)rr�r�r)r�rr�_tab_newline_replace�s zHtmlDiff._tab_newline_replacec Cs|s|�||f�dSt|�}|j}||ksB||�d�d|krT|�||f�dSd}d}d}||kr�||kr�||dkr�|d7}||}|d7}q`||dkr�|d7}d}q`|d7}|d7}q`|d|�} ||d�} |r�| d} d|| } |�|| f�|�|d| �dS)Nr�rZr rr(r��>)r,r1r��count� _split_line) rZ data_listZline_numr�rWr\r3r6ZmarkZline1Zline2rrrr��s8        zHtmlDiff._split_linec cs�|D]�\}}}|dur$|||fVq||\}}\}}gg} } |�| ||�|�| ||�| sd| r| rt| �d�}nd}| r�| �d�}nd}|||fVq\qdS)Nr )rrt)r�rC) r�diffs�fromdata�todata�flagZfromlineZfromtextZtolineZtotext�fromlist�tolistrrr� _line_wrappers     zHtmlDiff._line_wrapperc Cs�ggg}}}|D]t\}}}z8|�|jd|g|�R��|�|jd|g|�R��Wn&ty||�d�|�d�Yn0|�|�q|||fSr7)r,� _format_liner�)rr�rr�flaglistrrrrrr�_collect_lines.s   zHtmlDiff._collect_linescCspzd|}d|j||f}Wnty4d}Yn0|�dd��dd��dd �}|�d d ���}d |||fS) Nz%dz id="%s%s"r�&z&r�z>�%s%s)�_prefixr�rQr�)rr�rZlinenumr��idrrrrCs  �zHtmlDiff._format_linecCs0dtj}dtj}tjd7_||g|_dS)Nzfrom%d_zto%d_r()r �_default_prefixr )rZ fromprefix�toprefixrrr� _make_prefixZs  zHtmlDiff._make_prefixcCs�|jd}dgt|�}dgt|�}d\} } d} t|�D]V\} } | r�| s�d} | } td| |g�} d|| f|| <| d7} d|| f|| <q:d} q:|s�dg}dg}dg}d} |r�d g}|}n d g}}|ds�d ||d<d ||| <|||||fS) Nr(r)r Fr Tz id="difflib_chg_%s_%d"z"nFz2 No Differences Found z( Empty File z!fz#t)r r1r*r\)rrrrr�r�r�next_id� next_hrefZnum_chgZ in_changer�r3rrrr�_convert_flagses< �    zHtmlDiff._convert_flagsc CsR|��|�||�\}}|r"|}nd}t||||j|jd�}|jrL|�|�}|�|�\} } } |�| | | ||�\} } } } } g}d}t t | ��D]P}| |dur�|dkr�|� d�q�|� || || || || || |f�q�|s�|�rddd|dd|f}nd}|j t d�|�||jd d �}|�d d ��d d��dd��dd��dd�S)NrzzV %s%s%s%s r z) z %s%s%s%sz!
z+%srr()Z data_rows� header_rowr�z+zz-zz^zr�zr�r )rr�r�r�r�r�rrrr9r1r,�_table_templater�rwr rQ)rr�r�r�r�r�r�Z context_linesr�rrrrrrs�fmtr3rr�rrrr��sZ �  �   �  �� ����zHtmlDiff.make_table)rrFr�)rrFr�)rhrirjr�r�rr�rrrr�r�r�rrrrrr�rrrrr �s.� �� 7 /�r ccslzddd�t|�}Wn ty6td|�d�Yn0d|f}|D]"}|dd�|vrD|dd�VqDdS)Nr�r�)r(r�z)unknown delta choice (must be 1 or 2): %rr�r�)�int�KeyErrorro)Zdelta�whichrX�prefixesr�rrrr�s ��rcCsddl}ddl}|�|�SrB)�doctest�difflib�testmod)rrrrr�_testsr�__main__)rZrm)r�)rrrrrZr�)rrrrrZr�)rcrcrcrcrZr�)%�__all__�heapqrrp� collectionsrZ _namedtuple�typesrr rrrryrr�r��matchrrr�r r�rr�r rr�r�r�rr��objectr rrrhrrrr�s`    r 1 A  � I � L� %�   a