o
    ôjf  ã                   @   sê   d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ d dlmZ 	ddede	e de
ee ee	e f fd	d
„Zdee dee fdd„ZG dd„ deƒZejdd�dd„ ƒZdd„ ZG dd„ deƒZdd„ ZdS )é    N)Údedent)ÚAnyÚListÚ
NamedTupleÚOptionalÚTuple)ÚErrorReport)ÚSourceRangeFactoryÚobjÚ	error_msgÚreturnc              
   C   sj   d}zt  | ¡}t  | ¡\}}W n ty/ } zd| › d�}|r&|d| 7 }t|ƒ|‚d}~ww |||fS )z{
    Wrapper around inspect.getsourcelines and inspect.getsourcefile.

    Returns: (sourcelines, file_lino, filename)
    NzCan't get source for zs. TorchScript requires source access in order to carry out compilation, make sure original .py files are available.Ú
)ÚinspectÚgetsourcefileÚgetsourcelinesÚOSError)r
   r   ÚfilenameÚsourcelinesÚfile_linenoÚeÚmsg© r   ú_/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torch/_sources.pyÚget_source_lines_and_file   s   	

ÿ
€ø

r   r   c                    s¤   dd„ ‰ d}t | ƒD ]\}}| ¡  d¡r|} nq
|du r | S | | }| d¡d ‰‡ ‡fdd„| d|… D ƒ}‡ ‡fdd„| |d	 d… D ƒ}| |¡ || S )
a   
    This helper function accepts a list of source lines. It finds the
    indentation level of the function definition (`def`), then it indents
    all lines in the function body to a point at or greater than that
    level. This allows for comments and continued string literals that
    are at a lower indentation than the rest of the code.
    Args:
        sourcelines: function source code, separated into lines by
                        the '
' character
    Returns:
        A list of source lines that have been correctly aligned
    c                 S   s   | |   |¡o	t|ƒd … S ©N)Ú
startswithÚlen)ÚtextÚprefixr   r   r   Úremove_prefix4   s   z-normalize_source_lines.<locals>.remove_prefixNÚdefr   c                    ó   g | ]	}ˆˆ |ˆƒ ‘qS r   r   ©Ú.0Ús©r   Ú
whitespacer   r   Ú
<listcomp>I   ó    ÿz*normalize_source_lines.<locals>.<listcomp>c                    r!   r   r   r"   r%   r   r   r'   L   r(   é   )Ú	enumerateÚlstripr   ÚsplitÚappend)r   ÚidxÚiÚlZfn_defZaligned_prefixZaligned_suffixr   r%   r   Únormalize_source_lines&   s&   þ
ÿÿ
r1   c                       s"   e Zd Z		d‡ fdd„	Z‡  ZS )ÚSourceContextTNc                    s(   t ƒ  ||||¡ || _|| _|| _d S r   )ÚsuperÚ__init__Úuses_true_divisionr   Úfuncname)ÚselfÚsourcer   r   Úleading_whitespace_lenr5   r6   ©Ú	__class__r   r   r4   X   s   	
zSourceContext.__init__)TN)Ú__name__Ú
__module__Ú__qualname__r4   Ú__classcell__r   r   r:   r   r2   W   s    ùr2   )Úmaxsizec                  G   s   t | Ž S r   )r2   )Úargsr   r   r   Úmake_source_contextg   s   rB   c                   C   s   t dd ddƒ dd¡S )NÚ r   r)   )r2   Úmake_raw_ranger   r   r   r   Ú
fake_rangel   s   rE   c                   @   s<   e Zd ZU ejed< eed< eed< ee ed< e	ed< dS )Ú	ParsedDefÚastÚctxr8   r   r   N)
r<   r=   r>   rG   ÚModuleÚ__annotations__r2   Ústrr   Úintr   r   r   r   rF   p   s   
 
rF   c           	      C   s¸   t | t ¡ ƒ\}}}t|ƒ}d |¡}t|ƒ}t |¡}t|j	ƒdks,t
|j	d tjƒs6td|› d|› �ƒ‚t| dd¡d ƒt| dd¡d ƒ }t||||d| jƒ}t|||||ƒS )NrC   r)   r   z&Expected a single top-level function: ú:r   T)r   r   Ú
call_stackr1   Újoinr   rG   Úparser   ÚbodyÚ
isinstanceÚFunctionDefÚRuntimeErrorr,   rB   r<   rF   )	Úfnr   r   r   r8   Z
dedent_srcZpy_astr9   rH   r   r   r   Ú	parse_defx   s$   
ÿ

 ÿÿÿrV   r   )rG   Ú	functoolsr   Útextwrapr   Útypingr   r   r   r   r   Útorch._Cr   Ztorch._C._jit_tree_viewsr	   rK   rL   r   r1   r2   Ú	lru_cacherB   rE   rF   rV   r   r   r   r   Ú<module>   s,   þÿþ
ý1

