ó RŃŐfc@sădZdZddddgZddlZddlZejdƒZeZd „Z d „Z d „Z d „Z d „Z e dd„ZedkrßxedgƒD] ZeGHqŁWdGHx%edgde ƒD] ZeGHqÍWndS(sCList 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. sOleg Broytmann, Georg Brandlthas_python_exttlooks_like_pythontcan_be_compiledtwalk_python_filesi˙˙˙˙Ns [--]cCstr|GHndS(N(tdebug(tmsg((s./usr/lib64/python2.7/Tools/scripts/pysource.pyt print_debugscCsĽytj|ƒj}Wn(tk r@}td||fƒdSX|dkretd||fƒdSyt|dƒSWn(tk r }td||fƒdSXdS(Ns%s: permission denied: %sis!%s: the file is too big: %d bytestrUs%s: access denied: %si(toststattst_sizetOSErrorRtNonetopentIOError(tfullpathtsizeterr((s./usr/lib64/python2.7/Tools/scripts/pysource.pyt_open!s cCs|jdƒp|jdƒS(Ns.pys.pyw(tendswith(R((s./usr/lib64/python2.7/Tools/scripts/pysource.pyR2scCs‰t|ƒ}|dkrtS|jƒ}|jƒtj|ƒrStd|ƒtS|jdƒsq|jdƒrut Sd|kr…t StS(Ns%s: appears to be binarys.pys.pywtpython( RR tFalsetreadlinetcloset binary_retsearchRRtTrue(Rtinfiletline((s./usr/lib64/python2.7/Tools/scripts/pysource.pyR5s     cCsut|ƒ}|dkrtS|jƒ}|jƒyt||dƒWn(tk rp}td||fƒtSXtS(Ntexecs%s: cannot compile: %s( RR RtreadRtcompilet ExceptionRR(RRtcodeR((s./usr/lib64/python2.7/Tools/scripts/pysource.pyRJs    c cs"|dkrg}nx|D]ţ}td|ƒtjj|ƒrY||ƒr|Vqqtjj|ƒrtdƒx˘tj|ƒD]„\}}}x*|D]"}||kr›|j|ƒq›q›WxE|D]=}tjj||ƒ} td| ƒ|| ƒrČ| VqČqČWq…WqtdƒqWdS(s^ 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 s testing: %ss it is a directorys unknown typeN( R RRtpathtisfiletisdirtwalktremovetjoin( tpathst is_pythont exclude_dirsR"tdirpathtdirnamest filenamestexcludetfilenameR((s./usr/lib64/python2.7/Tools/scripts/pysource.pyR[s&          t__main__t.s ----------R)(t__doc__t __author__t__all__RtreRRRRRRRRRR Rt__name__R(((s./usr/lib64/python2.7/Tools/scripts/pysource.pyts"     !