o
    j:5                     @   s~  d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
mZ ddlmZ ddlmZmZ ddlmZmZ deddfd	d
ZdedefddZ		d!dee de	ee  de	ee  dee fddZ				d"dedede	ee  de	ee  dededeeef fddZ				d"dedede	ee  de	ee  dededeeef fddZdd Zdee
 fdd ZdS )#    N)IterableIteratorListOptionalTextTuple   color_unified_diff_line)run_external_diffu_diff)file_existsget_tables_argument_listoutputreturnc              	   C   s   | sdS t j st j|  dS tdptd}|s%t j|  dS |g}dtj	|v r5|
d tj|tjdd}z|j|  |j  |  W dS  ttfyg   |jrd|j  Y dS Y dS  tyv   |jru|j   w )zDPipes output to a pager if stdout is a TTY and a pager is available.NZPAGERlessz-RT)stdintext)sysstdoutisattywriteosgetenvshutilwhichpathbasenameappend
subprocessPopenPIPEr   closewaitBrokenPipeErrorKeyboardInterrupt	Exception)r   pagerZ	pager_cmdproc r)   X/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/fontTools/diff/__init__.pypipe_output   s4   



r+   	diff_toolc                 C   sP   zt j| dgt jt jdd}W n
 ty   Y dS w |jpd|jp"d }d|v S )z9Returns True if the provided diff executable is GNU diff.z	--versionT)r   stderrr   F zGNU diffutils)r   runr!   OSErrorr   r-   )r,   r(   Zversion_outputr)   r)   r*   _is_gnu_diff3   s   
r1   tagsinclude_tablesexclude_tablesc                 c   s2    | D ]}|r||v rq|r||vrq|V  qd S )Nr)   )r2   r3   r4   tagr)   r)   r*   _iter_filtered_table_tagsC   s   r6   file1file2font_number_1font_number_2c                    sz  ddl m} || d|d$}||d|d
}dd |j D  dd |j D ttt B ||d}	 fd	d
|	D }
 fdd
|	D } fdd
|	D }d}g }|d |d|  d |d| d |
rd}|dt|
 d |
D ]}|d| dt|j|  d q|rd}|dt| d |D ]}|d| dt|j|  d q|dt| d |D ]4}|j| }|j| }||kr|d| dt| d qd}|d| dt| dt| d q|r|d n|d  |d!	|fW  d    W  d    S 1 s%w   Y  W d    d S 1 s6w   Y  d S )"Nr   TTFontTZlazyZ
fontNumberc                 S      h | ]}t |qS r)   str.0r5   r)   r)   r*   	<setcomp>^       zsummarize.<locals>.<setcomp>c                 S   r?   r)   r@   rB   r)   r)   r*   rD   _   rE   r3   r4   c                    s    g | ]}| v r|vr|qS r)   r)   rB   Ztags1Ztags2r)   r*   
<listcomp>k        zsummarize.<locals>.<listcomp>c                    s    g | ]}|v r| vr|qS r)   r)   rB   rG   r)   r*   rH   l   rI   c                        g | ]}| v r|v r|qS r)   r)   rB   rG   r)   r*   rH   m   rI   zBinary table summary:
z	  file1: 
z	  file2: Fz
Tables only in file1 (z):
z- z (z bytes)
z
Tables only in file2 (z+ z
Tables in both (z  z: SAME (z* z: DIFF (z vs z
Result: SAME
z
Result: DIFFERENT
r.   )
fontTools.ttLibr=   readerkeyssortedsetr6   r   lenjoin)r8   r9   r3   r4   r:   r;   r=   font1font2all_tagsZonly1Zonly2both	identicallinesr5   data1data2r)   rG   r*   	summarizeP   sb   

$$

(
Vr[   c              	      s  ddl m} || d|do}||d|dW}dd |j D  dd |j D ttt B ||d}	 fd	d
|	D }
t }|
D ]}|j| }|j| }||kr[|| qF|W  d    W  d    S 1 sow   Y  W d    d S 1 sw   Y  d S )Nr   r<   Tr>   c                 S   r?   r)   r@   rB   r)   r)   r*   rD      rE   z,get_binary_exclude_tables.<locals>.<setcomp>c                 S   r?   r)   r@   rB   r)   r)   r*   rD      rE   rF   c                    rJ   r)   r)   rB   rG   r)   r*   rH      rI   z-get_binary_exclude_tables.<locals>.<listcomp>)rL   r=   rM   rN   rO   rP   r6   add)r8   r9   r3   r4   r:   r;   r=   rS   rT   rU   rV   outr5   rY   rZ   r)   rG   r*   get_binary_exclude_tables   s8   



Rr^   c                  C   sf   d} zt tjdd } W | S  ty   Y | S  ty2   ttjtj}t	|tj
  Y | S w )z!Compare two fonts for differencesr   r   N)r/   r   argvr%   r$   r   opendevnullO_WRONLYdup2r   fileno)retra   r)   r)   r*   main   s   rf   r_   c                    s^  t jdd}|jddddd |jdd	td
dd |jddtdd dd |jddtdd dd |jdtdd |jdtd dd |jdg dddd |jdtd d!d"d# |jd$td d!d%d# |jd&d'dd(d |jd)d*dd+d |jd,d-dd.d |jd/d0d1 |jd2d3d1 || }|jr|jr|jst	j
d4tj  d5S |jsd6|_t|js|jst	j
d7|j d8tj  d5S t|js|jst	j
d7|j d8tj  d5S t|j}t|j}|jr.z#t|j|j|||j|jd9\}}|jst	j| |rd:W S d;W S  ty- } z|js"t	j
d<| tj  W Y d }~d5S d }~ww |jr]t|j|j|||j|jd9 |d urO fd=d>|D }n|d u rVg }|t  |j}|jd?kpo|jdkoot	jj}	|d u r{t !d@}n!|rt !|}|d u r|jst	j
dA|j dBtj  d5S zn|r|j"}
|
d u r|j#d
krdCg}
ndD$|j#g}
t%|r|
&dE n|
' }
t(||
|j|j|||j|jd6dF	}nt)|j|j|j#|||j|jd6dG}|	rdHd> |D }dI*|}|jst+| |rd;W S d:W S  ty. } z|js#t	j
d<| tj  W Y d }~d5S d }~ww )JNz&An OpenType table diff tool for fonts.)descriptionz-lz	--summary
store_truez.Report table presence and binary equality only)actionhelpz-Uz--lines   z5Number of context lines for unified diff (default: 3))typedefaultrj   z-tz	--include+z5Font tables to include. Multiple options are allowed.)rl   nargsrm   rj   z-xz	--excludez5Font tables to exclude. Multiple options are allowed.z--diffz.Run external diff tool command (default: diff))rl   rj   z
--diff-argz*External diff tool arguments (default: -u)z--color)autoneveralwaysrp   z*Whether to colorize output (default: auto))choicesrm   rj   z--y1r7   NUMBERzMSelect font number for TrueType Collection (.ttc/.otc) FILE1, starting from 0)rl   rm   metavarrj   z--y2zMSelect font number for TrueType Collection (.ttc/.otc) FILE2, starting from 0z-az--alwaysz'Compare tables even if binary identicalz-bz--binaryz0Compare tables only if binaries differ (default)z-qz--quietzSuppress all outputFILE1zFont file path 1)rj   FILE2zFont file path 2zv[*] Error: --always and --binary are mutually exclusive options. Please use ONLY one of these options in your command.   Tz[*] ERROR: The file path 'z' can not be found.)r3   r4   r:   r;   r   r   z[*] ERROR: c                    s   g | ]}| vr|qS r)   r)   rB   Zexcluded_binary_tablesr)   r*   rH   q  s    zrun.<locals>.<listcomp>rr   diffz.[*] ERROR: The external diff tool executable 'z' was not found.z-uz-u{}z-F^\s\s<)r3   r4   font_number_afont_number_buse_multiprocess)Zcontext_linesr3   r4   r{   r|   r}   c                 S   s   g | ]}t |qS r)   r	   )rC   liner)   r)   r*   rH     rE   r.   ),argparseArgumentParseradd_argumentintrA   
parse_argsrr   binaryquietr   r-   r   r   linesepr   rv   rw   r   includeexcludesummaryr[   y1y2r   r&   r^   extendrO   rz   colorr   r   r   diff_argrX   formatr1   r   splitr   r   rR   r+   )r_   parserargsZinclude_listZexclude_listrW   r   er,   Zcolor_outputr   r)   ry   r*   r/      s  















r/   )NN)NNr7   r7   )r   r   r   r   r   typingr   r   r   r   r   r   r   r
   rz   r   r   utilsr   r   rA   r+   boolr1   r6   r   r[   r^   rf   r/   r)   r)   r)   r*   <module>   s|     &






F



'