o
    `i#                     @   s  d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZmZmZmZmZmZmZ d dlmZ ddlmZ d	ed
ededeee  deee  dedededeeeeeeef fddZd	ed
edeeeeef fddZdededededeee  deee  deddfddZdededeee  deee  def
ddZed	ed
edeee  deee  dedededeeeeeeeef  fd d!Zd	ed
edeee  deee  dededed"eeeeeeegee f dee fd#d$Z	%			&	&	'd/d	ed
ed(edeee  deee  dedededee fd)d*Z			&	&	'd0d+ed,ee d	ed
edeee  deee  dedededee fd-d.Z dS )1    N)contextmanager)unified_diff)Pool	cpu_count)AnyCallableIterableIteratorListOptionalTextTuple)TTFont   )get_file_modtime
filepath_a
filepath_b
tmpdirpathinclude_tablesexclude_tablesfont_number_afont_number_buse_multiprocessreturnc                 C   sj   t | |\}}	}
}t||d}t|	|d}tj|d}tj|d}t||||||| |||
|||	fS )N)
fontNumberzleft.ttxz	right.ttx)_get_pre_post_pathsr   ospathjoin_mp_save_ttx_xml)r   r   r   r   r   r   r   r   post_pathnamepostpathpre_pathnameprepathtt_lefttt_rightleft_ttxpathright_ttxpath r(   Q/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/fontTools/diff/diff.py_get_fonts_and_save_xml   s"   
	r*   c                 C   s   | }|}| }|}||||fS Nr(   )r   r   r#   r!   r"   r    r(   r(   r)   r   2   s
   r   r$   r%   r&   r'   c           	      C   s   |r1t  dkr1| |||f||||fg}tdd}|t| W d    d S 1 s*w   Y  d S t| ||| t|||| d S )Nr      )	processes)r   r   starmap_ttfont_save_xml)	r$   r%   r&   r'   r   r   r   mp_args_listpoolr(   r(   r)   r   =   s   	

"r   ttffilepathc                 C   s   | j |||d dS )z;Writes TTX specification formatted XML to disk on filepath.)tables
skipTablesT)saveXML)r2   r3   r   r   r(   r(   r)   r/   Y   s   r/   c              
   c   sH    t  }t| |||||||V  W d    d S 1 sw   Y  d S r+   )tempfileTemporaryDirectoryr*   )r   r   r   r   r   r   r   r   r(   r(   r)   _saved_ttx_filesd   s   

"r9   create_differc                 c   s`    t | ||||||\}}	}
}}}|||	|
|||E d H  W d    d S 1 s)w   Y  d S r+   )r9   )r   r   r   r   r   r   r   r:   r&   r'   r"   r#   r    r!   r(   r(   r)   _diff_with_saved_ttx_files{   s4   
"r;      Tcontext_linesc           	      #   sP    dt dt dt dt dt dt dtt  f fdd	}t| |||||||E d
H  d
S )a  Performs a unified diff on a TTX serialized data format dump of font binary data using
    a modified version of the Python standard libary difflib module.

    filepath_a: (string) pre-file local file path
    filepath_b: (string) post-file local file path
    context_lines: (int) number of context lines to include in the diff (default=3)
    include_tables: (list of str) Python list of OpenType tables to include in the diff
    exclude_tables: (list of str) Python list of OpentType tables to exclude from the diff
    use_multiprocess: (bool) use multi-processor optimizations (default=True)

    include_tables and exclude_tables are mutually exclusive arguments.  Only one should
    be defined

    :returns: Generator of ordered diff line strings that include newline line endings
    :raises: KeyError if include_tables or exclude_tables includes a mis-specified table
    that is not included in filepath_a OR filepath_b
    r&   r'   r"   r#   r    r!   r   c              	   3   s    t | }| }W d    n1 sw   Y  t |}| }	W d    n1 s,w   Y  t|}
t|}t||	|||
| dE d H  d S )N)n)open	readlinesr   r   )r&   r'   r"   r#   r    r!   ff	fromlinestftolinesfromdatetodater>   r(   r)   _create_unified_diff   s$   



z$u_diff.<locals>._create_unified_diffNr   r   r;   )	r   r   r>   r   r   r   r   r   rI   r(   rH   r)   u_diff   s4   rK   	diff_tool	diff_argsc	           
      #   sR    dt dt dt dt dt dt dtt  f fdd	}	t||||||||	E d
H  d
S )a'  Performs a unified diff on a TTX serialized data format dump of font binary data using
    an external diff executable that is requested by the caller via `command`

    diff_tool: (string) command line executable string
    diff_args: (list of strings) arguments for the diff tool
    filepath_a: (string) pre-file local file path
    filepath_b: (string) post-file local file path
    include_tables: (list of str) Python list of OpenType tables to include in the diff
    exclude_tables: (list of str) Python list of OpentType tables to exclude from the diff
    use_multiprocess: (bool) use multi-processor optimizations (default=True)

    include_tables and exclude_tables are mutually exclusive arguments.  Only one should
    be defined

    :returns: Generator of ordered diff line strings that include newline line endings
    :raises: KeyError if include_tables or exclude_tables includes a mis-specified table
    that is not included in filepath_a OR filepath_b
    :raises: IOError if exception raised during execution of `command` on TTX files
    r&   r'   _pre_pathname_prepath_post_pathname	_postpathr   c           
      3   sV    g  | |g }t j|t jt jdd}|jD ]}|V  q|j }	|	r)t|	d S )Nutf8)stdoutstderrencoding)
subprocessPopenPIPErS   rT   readIOError)
r&   r'   rN   rO   rP   rQ   commandprocesslineerrrM   rL   r(   r)   _create_external_diff  s   

z0run_external_diff.<locals>._create_external_diffNrJ   )
rL   rM   r   r   r   r   r   r   r   r`   r(   r_   r)   run_external_diff   s4   ra   )r<   NNr=   r=   T)NNr=   r=   T)!r   rV   r7   
contextlibr   difflibr   multiprocessingr   r   typingr   r   r   r	   r
   r   r   r   fontTools.ttLibr   utilsr   intboolr*   r   r   r/   r9   r;   rK   ra   r(   r(   r(   r)   <module>   s.   (	

	











	
.

	
G

	
