B &%L呗@sdZdZddddgZddlZddlZedZd Zd d Zd d Z ddZ ddZ ddZ e dfddZ edkrxe dgD] Zeeq|Wedxe dge dD] ZeeqWdS)aCList 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. zOleg Broytmann, Georg Brandlhas_python_extlooks_like_pythoncan_be_compiledwalk_python_filesNs[\x00-\x08\x0E-\x1F\x7F]FcCstr t|dS)N)debugprint)msgr ;/opt/alt/python37/lib64/python3.7/Tools/scripts/pysource.py print_debugsr c Csyt|j}Wn2tk rB}ztd||fdSd}~XYnX|dkr`td||fdSy t|dStk r}ztd||fdSd}~XYnXdS)Nz%s: permission denied: %siz!%s: the file is too big: %d bytesrbz%s: access denied: %s)osstatst_sizeOSErrorr openIOError)fullpathsizeerrr r r _open!s rcCs|dp|dS)Nz.pyz.pyw)endswith)rr r r r2sc Csnt|}|dkrdS||}WdQRXt|rFtd|dS|dsZ|dr^dSd|krjdSdS)NFz%s: appears to be binaryz.pyz.pywTspython)rreadline binary_researchr r)rinfileliner r r r5s  c Cstt|}|dkrdS||}WdQRXyt||dWn2tk rn}ztd||fdSd}~XYnXdS)NFexecz%s: cannot compile: %sT)rreadcompile Exceptionr )rrcoderr r r rJsc cs|dkr g}x|D]}td|tj|r>||r|Vqtj|rtdxxt|D]`\}}}x|D]}||krn||qnWx4|D],}tj||} td| || r| VqWq^WqtdqWdS)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 pathisfileisdirwalkremovejoin) paths is_pythonZ exclude_dirsr"dirpathZdirnames filenamesZexcludefilenamerr r r r[s&        __main__.z ----------)r))__doc__ __author____all__r rerrrr rrrrr__name__rrr r r r s"  !