Your IP : 216.73.216.213
�
��f$ c @ s d Z d Z d d d d g Z d d l Z d d l Z e j d � Z d Z d d
� Z d d � Z
d
d � Z d d � Z d d � Z
e d d d � Z e d k r x! e d g � D] Z e e � q� We d � x* e d g d e
�D] Z e e � q� Wn d S( uC 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.
u Oleg Broytmann, Georg Brandlu has_python_extu looks_like_pythonu can_be_compiledu walk_python_filesi Ns [\x00-\x08\x0E-\x1F\x7F]c C s t r t | � n d S( N( u debugu print( u msg( ( u; /opt/alt/python33/lib64/python3.3/Tools/scripts/pysource.pyu print_debug s u print_debugc C s� y t j | � j } Wn= t k
rU } z t d | | f � d SWYd d } ~ Xn X| d k rz t d | | f � d Sy t | d � SWn= t k
r� } z t d | | f � d SWYd d } ~ Xn Xd S( Nu %s: permission denied: %si u! %s: the file is too big: %d bytesu rbu %s: access denied: %si ( u osu statu st_sizeu OSErroru print_debugu Noneu openu IOError( u fullpathu sizeu err( ( u; /opt/alt/python33/lib64/python3.3/Tools/scripts/pysource.pyu _open! s u _openc C s | j d � p | j d � S( Nu .pyu .pyw( u endswith( u fullpath( ( u; /opt/alt/python33/lib64/python3.3/Tools/scripts/pysource.pyu has_python_ext2 s c C s� t | � } | d k r d S| � | j � } Wd QXt j | � rV t d | � d S| j d � st | j d � rx d Sd | k r� d Sd S( Nu %s: appears to be binaryu .pyu .pyws pythonFT( u _openu Noneu Falseu readlineu binary_reu searchu print_debugu endswithu True( u fullpathu infileu line( ( u; /opt/alt/python33/lib64/python3.3/Tools/scripts/pysource.pyu looks_like_python5 s c C s� t | � } | d k r d S| � | j � } Wd QXy t | | d � Wn= t k
r� } z t d | | f � d SWYd d } ~ Xn Xd S( Nu execu %s: cannot compile: %sFT( u _openu Noneu Falseu readu compileu Exceptionu print_debugu True( u fullpathu infileu codeu err( ( u; /opt/alt/python33/lib64/python3.3/Tools/scripts/pysource.pyu can_be_compiledJ s c
c s" | d k r g } n x| D]� } t d | � t j j | � rY | | � r| Vqq t j j | � rt d � x� t j | � D]� \ } } } x* | D]"