a
    Ø
þdâ  ã                   @   sH   d Z ddlZddlZddlZddlZG dd„ deƒZdd„ Zdd„ ZdS )	zîVerify that the generated code is valid code.

This takes a line of code and "normalizes" it. I.e., it transforms the snippet
into something that has the potential to compile.

    VerifyCode(): the main function exported by this module.
é    Nc                   @   s   e Zd ZdZdS )ÚInternalErrorz+Internal error in verifying formatted code.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú^/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/yapf/yapflib/verifier.pyr      s   r   c                 C   s¬   zt t | ¡ d¡ddƒ W nŠ ty¦   z"t t |  d¡¡ ¡ dd¡ W nT ty    zt| ƒ}t | d¡ddƒ W n" tyš   t	t
 ¡ d ƒ‚Y n0 Y n0 Y n0 dS )zÁVerify that the reformatted code is syntactically correct.

  Arguments:
    code: (unicode) The reformatted code snippet.

  Raises:
    SyntaxError if the code was reformatted incorrectly.
  zUTF-8ú<string>ÚexecÚ
é   N)ÚcompileÚtextwrapÚdedentÚencodeÚSyntaxErrorÚastÚparseÚlstripÚ_NormalizeCoder   ÚsysÚexc_info)ÚcodeZnormalized_coder   r   r   Ú
VerifyCode!   s    	"r   c                 C   sl  t  |  d¡¡ ¡ } |  d¡}d}t|ƒD ]"\}}| ¡ }|r*| d¡s* qNq*d ||d… ¡d } t 	d| ¡rz| d7 } nêt 	d| ¡rÖz2d|  d }t
 t  | d¡¡ ¡ d	d
¡ |} W n tyÒ   d|  } Y n0 nŽ|  d¡rê| d7 } nzt 	d| ¡r| d7 } nbt 	d| ¡rd|  d } nFt 	d| ¡r6d|  } n.t 	d| ¡rNd|  } nt 	d| ¡rdd|  } | d S )z.Make sure that the code snippet is compilable.r   r   ú#Nz+(if|while|for|with|def|class|async|await)\bz	
    passz(elif|else)\bzif True:
    pass
r	   r
   zif True: pass
ú@z
def _():
    passztry\bz
    pass
except:
    passz(except|finally)\bztry:
    pass
z(return|yield)\bzdef _():
    z(continue|break)\bzwhile True:
    zprint\bz&from __future__ import print_function
)r   r   r   ÚsplitÚ	enumerateÚstripÚ
startswithÚjoinÚreÚmatchr   r   r   )r   ÚlinesÚiÚlineZtry_coder   r   r   r   7   s@    

ÿ




r   )	r   r   r!   r   r   Ú	Exceptionr   r   r   r   r   r   r   Ú<module>   s   