B
    18\                 @   s   d Z dZddddgZddlZddlZedZd	Zd
d Zdd Z	dd Z
dd Zdd ZedfddZedkrxedgD ]Zee q|W ed xedgedD ]Zee qW dS )aC  List python source files.

There are three functions to check whether a file is a Python source, listed
here with increasing complexity:

- has_python_ext() checks whether a file name ends in '.py[w]'.
- look_like_python() checks whether the file is not binary and either has
  the '.py[w]' extension or the first line contains the word 'python'.
- can_be_compiled() checks whether the file can be compiled by compile().

The file also must be of appropriate size - not bigger than a megabyte.

walk_python_files() recursively lists all Python files under the given directories.
zOleg Broytmann, Georg Brandlhas_python_extlooks_like_pythoncan_be_compiledwalk_python_files    Ns   [\x00-\x08\x0E-\x1F\x7F]Fc             C   s   t rt|  d S )N)debugprint)msg r	   V/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Tools/scripts/pysource.pyprint_debug   s     r   c          
   C   s   yt | j}W n2 tk
rB } ztd| |f  d S d }~X Y nX |dkr`td| |f  d S y
t| dS  tk
r } ztd| |f  d S d }~X Y nX d S )Nz%s: permission denied: %si   z!%s: the file is too big: %d bytesrbz%s: access denied: %s)osstatst_sizeOSErrorr   openIOError)fullpathsizeerrr	   r	   r
   _open!   s    
r   c             C   s   |  dp|  dS )Nz.pyz.pyw)endswith)r   r	   r	   r
   r   2   s    c          	   C   sn   t | }|d krdS | | }W d Q R X t|rFtd|   dS | dsZ| dr^dS d|krjdS dS )NFz%s: appears to be binaryz.pyz.pywTs   python)r   readline	binary_researchr   r   )r   infileliner	   r	   r
   r   5   s    
c          
   C   st   t | }|d krdS | | }W d Q R X yt|| d W n2 tk
rn } ztd| |f  dS d }~X Y nX dS )NFexecz%s: cannot compile: %sT)r   readcompile	Exceptionr   )r   r   coder   r	   r	   r
   r   J   s    c       
      c   s   |dkrg }x| D ]}t d|  tj|r>||r|V  qtj|rt d xxt|D ]`\}}}x|D ]}||krn|| qnW x4|D ],}tj||}	t d|	  ||	r|	V  qW q^W qt d qW dS )a^      Recursively yield all Python source files below the given paths.

    paths: a list of files and/or directories to be checked.
    is_python: a function that takes a file name and checks whether it is a
               Python source file
    exclude_dirs: a list of directory base names that should be excluded in
                  the search
    Nztesting: %sz    it is a directoryz    unknown type)r   r   pathisfileisdirwalkremovejoin)
paths	is_pythonZexclude_dirsr"   dirpathdirnames	filenamesexcludefilenamer   r	   r	   r
   r   [   s&    



__main__.z
----------)r)   )__doc__
__author____all__r   rer   r   r   r   r   r   r   r   r   __name__r   r   r	   r	   r	   r
   <module>   s"   
!