a
    h                  	   @  s   d dl mZ d dlZd dlZd dlZd dlmZ erDd dlmZm	Z	 G dd dZ
edkre
dZeejd	d
gddgddddgg d dS )    )annotationsN)TYPE_CHECKING)MappingSequencec                   @  sl   e Zd ZU dZeeejZded< ded< e	dd dddZ
dddd	d
ddZdddddddZdS )CodeTemplatez-(^[^\n\S]*)?\$([^\d\W]\w*|\{,?[^\d\W]\w*\,?})strpatternfilename)r	   returnc                 C  s:   t | }t| | W  d    S 1 s,0    Y  d S N)openr   read)r	   f r   D/var/www/auris/lib/python3.9/site-packages/torchgen/code_template.py	from_file   s    
zCodeTemplate.from_file None)r   r	   r
   c                 C  s   || _ || _d S r   )r   r	   )selfr   r	   r   r   r   __init__#   s    zCodeTemplate.__init__NzMapping[str, object] | Noneobject)envkwargsr
   c                   sZ    d u ri  ddd fdddddddd	d
ddfdd}| j || jS )Nr   r   )vr
   c                   s$    d usJ | v r|  S  |  S r   r   )r   )r   r   r   r   lookup-   s    z'CodeTemplate.substitute.<locals>.lookupzSequence[object])indentr   r
   c                 S  sD   d tjdd |D }tj|| d}d ttj|	  S )N
c                 s  s   | ]}t | V  qd S r   )r   
splitlines).0er   r   r   	<genexpr>3       z@CodeTemplate.substitute.<locals>.indent_lines.<locals>.<genexpr>)prefix)
join	itertoolschainfrom_iterabletextwrapr   mapr   rstripr   )r   r   contentr   r   r   indent_lines1   s
    z-CodeTemplate.substitute.<locals>.indent_lineszre.Match[str])matchr
   c                   s   |  d}|  d}d}d}|d dkrl|dd }|d dkrPd}|dd  }|d dkrld}|d d }|}|d urt|ts|g} ||S t|trdd	d
 |D }t|dkr|S || | S t|S d S )N      r   r   {,z, c                 S  s   g | ]}t |qS r   )r   )r   xr   r   r   
<listcomp>L   r!   z<CodeTemplate.substitute.<locals>.replace.<locals>.<listcomp>)group
isinstancelistr#   lenr   )r,   r   keyZcomma_beforeZcomma_afterr   Zmiddle)r+   r   r   r   replace9   s.    




z(CodeTemplate.substitute.<locals>.replace)substitutionsubr   )r   r   r   r9   r   )r   r+   r   r   r   
substitute'   s    zCodeTemplate.substitute)r   )N)__name__
__module____qualname__Zsubstitution_strrecompile	MULTILINEr:   __annotations__staticmethodr   r   r<   r   r   r   r   r      s   
 r   __main__z    int foo($args) {

        $bar
            $bar
        $a+$b
    }
    int commatest(int a${,stuff})
    int notest(int a${,empty,})
    hi   what         z	things...others)argsbarabstuffempty)
__future__r   r$   r@   r'   typingr   collections.abcr   r   r   r=   cprintr<   r   r   r   r   <module>   s*   ?