B
    18\              
   @   s  d Z dZddlZddlZddlZddlZyddlZW n6 ek
rj   G dd dZe Zedej	d Y nX e
dZe
d	Zd
d Zdd Zdd Zdejd  Zedkryeejdd d\ZZW nL ejk
r Z z*eeej	d eeej	d ed W ddZ[X Y nX ejZdZx2eD ]*\ZZedkrFejZnedkr,dZq,W esxeeej	d ed x>eeeD ].Zerede  eeZ e ree qW dS )zcList all those Python files that require a coding directive

Usage: findnocoding.py dir1 [dir2...]
zOleg Broytmann, Georg Brandl    Nc               @   s    e Zd Zd Z ZZdd ZdS )pysourceNc       	      o   sz   xt|D ]l}t j|r$|dV  qt j|rx@t |D ]2\}}}x&|D ]}|drLt j||V  qLW q<W qW d S )Nz.py)ospathisfileendswithisdirwalkjoin)	selfpathsargskwargsr   rootdirsfilesfilename r   Z/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Tools/scripts/findnocoding.pywalk_python_files   s    


zpysource.walk_python_files)__name__
__module____qualname__Zhas_python_extlooks_like_pythoncan_be_compiledr   r   r   r   r   r      s   r   z^The pysource module is not available; no sophisticated Python source file search will be done.)files&   ^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)s   ^[ \t\f]*(?:[#\r\n]|$)c             C   s   t | }|r|dS dS )N       )decl_rematchgroup)liner   r   r   r   get_declaration&   s    

r!   c             C   s,   yt | | W n tk
r"   dS X dS d S )NFT)strUnicodeDecodeError)textcodecr   r   r   has_correct_encoding,   s
    r&   c          	   C   s   yt | d}W n tk
r"   d S X |< | }| }t|sTt|rXt|rXdS | }W d Q R X t|| | drdS dS )NrbFzutf-8T)openIOErrorreadliner!   blank_rer   readr&   )fullpathinfileline1line2restr   r   r   needs_declaration4   s    r2   zjUsage: %s [-cd] paths...
    -c: recognize Python source files trying to compile them
    -d: debug output__main__r   ZcdFz-cz-dTzTesting for coding: %s)!__doc__
__author__sysr   regetoptr   ImportErrorprintstderrcompiler   r+   r!   r&   r2   argvusager   optsr   errormsgexitr   Z	is_pythondebugoar   r   r-   resultr   r   r   r   <module>   sL    






