o
    `i: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.N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   pager	pager_cmdproc r+   U/home/ubuntu/SoloSpeech/.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*   version_outputr+   r+   r,   _is_gnu_diff3   s   
r4   tagsinclude_tablesexclude_tablesc                 c   s2    | D ]}|r||v rq|r||vrq|V  qd S )Nr+   )r5   r6   r7   tagr+   r+   r,   _iter_filtered_table_tagsC   s   r9   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lazy
fontNumberc                 S      h | ]}t |qS r+   str.0r8   r+   r+   r,   	<setcomp>^       zsummarize.<locals>.<setcomp>c                 S   rD   r+   rE   rG   r+   r+   r,   rI   _   rJ   r6   r7   c                    s    g | ]}| v r|vr|qS r+   r+   rG   tags1tags2r+   r,   
<listcomp>k        zsummarize.<locals>.<listcomp>c                    s    g | ]}|v r| vr|qS r+   r+   rG   rL   r+   r,   rO   l   rP   c                        g | ]}| v r|v r|qS r+   r+   rG   rL   r+   r,   rO   m   rP   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
r0   )
fontTools.ttLibr@   readerkeyssortedsetr9   r   lenjoin)r;   r<   r6   r7   r=   r>   r@   font1font2all_tagsonly1only2both	identicallinesr8   data1data2r+   rL   r,   	summarizeP   sb   

$$

(
Vrd   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?   TrA   c                 S   rD   r+   rE   rG   r+   r+   r,   rI      rJ   z,get_binary_exclude_tables.<locals>.<setcomp>c                 S   rD   r+   rE   rG   r+   r+   r,   rI      rJ   rK   c                    rQ   r+   r+   rG   rL   r+   r,   rO      rP   z-get_binary_exclude_tables.<locals>.<listcomp>)rS   r@   rT   rU   rV   rW   r9   add)r;   r<   r6   r7   r=   r>   r@   rZ   r[   r\   r_   outr8   rb   rc   r+   rL   r,   get_binary_exclude_tables   s8   



Rrg   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)r1   r   argvr&   r%   r   opendevnullO_WRONLYdup2r   fileno)retrj   r+   r+   r,   main   s   ro   rh   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defaultrs   z-tz	--include+z5Font tables to include. Multiple options are allowed.)ru   nargsrv   rs   z-xz	--excludez5Font tables to exclude. Multiple options are allowed.z--diffz.Run external diff tool command (default: diff))ru   rs   z
--diff-argz*External diff tool arguments (default: -u)z--color)autoneveralwaysry   z*Whether to colorize output (default: auto))choicesrv   rs   z--y1r:   NUMBERzMSelect font number for TrueType Collection (.ttc/.otc) FILE1, starting from 0)ru   rv   metavarrs   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)rs   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.)r6   r7   r=   r>   r   r   z[*] ERROR: c                    s   g | ]}| vr|qS r+   r+   rG   excluded_binary_tablesr+   r,   rO   q  s    zrun.<locals>.<listcomp>r{   diffz.[*] ERROR: The external diff tool executable 'z' was not found.z-uz-u{}z-F^\s\s<)r6   r7   font_number_afont_number_buse_multiprocess)context_linesr6   r7   r   r   r   c                 S   s   g | ]}t |qS r+   r	   )rH   liner+   r+   r,   rO     rJ   r0   ),argparseArgumentParseradd_argumentintrF   
parse_argsr{   binaryquietr   r/   r   r   linesepr   r   r   r   includeexcludesummaryrd   y1y2r   r'   rg   extendrV   r   colorr   r   r   diff_argra   formatr4   r   splitr   r   rY   r-   )rh   parserargsinclude_listexclude_listr`   r   er.   color_outputr   r+   r   r,   r1      s  















r1   )NN)NNr:   r:   )r   r   r   r   r    typingr   r   r   r   r   r   r   r
   r   r   r   utilsr   r   rF   r-   boolr4   r9   r   rd   rg   ro   r1   r+   r+   r+   r,   <module>   s|     &






F



'