
    Pgf                        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	Zd
ee   dee   fdZ G d de      Z ej(                  d      d        Zd Z G d de      Zd Zy)    N)dedent)AnyList
NamedTupleOptionalTuple)ErrorReport)SourceRangeFactoryobj	error_msgreturnc                     d}	 t        j                  |       }t        j                  |       \  }}|||fS # t        $ r!}d|  d}|r|d|z   z  }t        |      |d}~ww xY w)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msgs          U/var/www/html/suriana-translation/venv/lib/python3.12/site-packages/torch/_sources.pyget_source_lines_and_filer      s     H"((-#*#9#9##> [ X--  "#C5 )  	
 4)##Ccl!"s   -6 	A AA r   c                 h   d }d}t        |       D ](  \  }}|j                         j                  d      s&|} n || S | |   }|j                  d      d   }| d| D cg c]  }| |||      z    }}| |dz   d D cg c]  }| |||      z    }	}|j	                  |       ||	z   S c c}w c c}w )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                 D    | | j                  |      xr t        |      d  S N)
startswithlen)textprefixs     r   remove_prefixz-normalize_source_lines.<locals>.remove_prefix4   s"    DOOF+;F=>>    Ndefr      )	enumeratelstripr   splitappend)
r   r"   idxilfn_def
whitespacesaligned_prefixaligned_suffixs
             r   normalize_source_linesr2   &   s    ? C+& 188:  'C { Fe$Q'J <Gt;L67
]1j11N  <GsQwy;Q67
]1j11N 
 &!N**s    B*?B/c                   $     e Zd Z	 	 d fd	Z xZS )SourceContextc                 T    t         |   ||||       || _        || _        || _        y r   )super__init__uses_true_divisionr   funcname)selfsourcer   r   leading_whitespace_lenr8   r9   	__class__s          r   r7   zSourceContext.__init__X   s/     	;8NO"4  r#   )TN)__name__
__module____qualname__r7   __classcell__)r=   s   @r   r4   r4   W   s      ! !r#   r4   )maxsizec                      t        |  S r   )r4   )argss    r   make_source_contextrE   g   s    $r#   c                  >    t        dd dd      j                  dd      S )N r   r%   )r4   make_raw_range r#   r   
fake_rangerJ   l   s     T1a(771==r#   c                   Z    e Zd ZU ej                  ed<   eed<   eed<   ee   ed<   e	ed<   y)	ParsedDefastctxr;   r   r   N)
r>   r?   r@   rM   Module__annotations__r4   strr   intrI   r#   r   rL   rL   p   s&    	O	Ksmr#   rL   c                 *   t        | t        j                               \  }}}t        |      }dj	                  |      }t        |      }t        j                  |      }t        |j                        dk7  s't        |j                  d   t        j                        st        d| d|       t        |j                  dd      d         t        |j                  dd      d         z
  }t        ||||d| j                        }t!        |||||      S )NrG   r%   r   z&Expected a single top-level function: :r   T)r   r	   
call_stackr2   joinr   rM   parser   body
isinstanceFunctionDefRuntimeErrorr(   rE   r>   rL   )	fnr   r   r   r;   
dedent_srcpy_astr<   rN   s	            r   	parse_defr_   x   s   )B
K""$*&Kh )5KWW[!FJYYz"F
6;;1Jv{{1~s$O4XJa}M
 	
 !dA!6q!9:Sq!!$>  +'=tR[[C VS&(K@@r#   r   )rM   	functoolsr   textwrapr   typingr   r   r   r   r   torch._Cr	   torch._C._jit_tree_viewsr
   rQ   rR   r   r2   r4   	lru_cacherE   rJ   rL   r_   rI   r#   r   <module>rf      s    
    9 9   7
  $.	.}. 49c8C=().4,+S	 ,+d3i ,+b!& !  T"  # >
 Ar#   