//usr/lib64/lib64//lib64//python2.7/ó
àœSec @ sã d Z d Z d d d d g Z d d l Z d d l Z e j d ƒ Z e Z d „ Z d
„ Z
d „ Z d „ Z d
„ Z
e d d „ Z e d k rß x e d g ƒ D] Z e GHq£ Wd GHx% e d g d e
ƒD] Z e GHqÍ Wn d S( sC 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.
s Oleg Broytmann, Georg Brandlt has_python_extt looks_like_pythont can_be_compiledt walk_python_filesiÿÿÿÿNs [ --]c C s t r | GHn d S( N( t debug( t msg( ( s. /usr/lib64/python2.7/Tools/scripts/pysource.pyt print_debug s c C s¥ y t j | ƒ j } Wn( t k
r@ } t d | | f ƒ d SX| d k re t d | | f ƒ d Sy t | d ƒ SWn( t k
r } t d | | f ƒ d SXd S( Ns %s: permission denied: %si s! %s: the file is too big: %d bytest rUs %s: access denied: %si ( t ost statt st_sizet OSErrorR t Nonet opent IOError( t fullpatht sizet err( ( s. /usr/lib64/python2.7/Tools/scripts/pysource.pyt _open! s c C s | j d ƒ p | j d ƒ S( Ns .pys .pyw( t endswith( R ( ( s. /usr/lib64/python2.7/Tools/scripts/pysource.pyR 2 s c C s‰ t | ƒ } | d k r t S| j ƒ } | j ƒ t j | ƒ rS t d | ƒ t S| j d ƒ sq | j d ƒ ru t Sd | k r… t St S( Ns %s: appears to be binarys .pys .pywt python(
R R t Falset readlinet closet binary_ret searchR R t True( R t infilet line( ( s. /usr/lib64/python2.7/Tools/scripts/pysource.pyR 5 s
c C su t | ƒ } | d k r t S| j ƒ } | j ƒ y t | | d ƒ Wn( t k
rp } t d | | f ƒ t SXt S( Nt execs %s: cannot compile: %s( R R R t readR t compilet ExceptionR R ( R R t codeR ( ( s. /usr/lib64/python2.7/Tools/scripts/pysource.pyR J 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]" } | | k r› | j | ƒ q› q› WxE | D]= } t j j | | ƒ } t d | ƒ | | ƒ rÈ | VqÈ qÈ Wq… Wq t d ƒ q Wd S( 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 R R t patht isfilet isdirt walkt removet join(
t pathst is_pythont exclude_dirsR" t dirpatht dirnamest filenamest excludet filenameR ( ( s. /usr/lib64/python2.7/Tools/scripts/pysource.pyR [ s&