B Vw`@s\dZddlZddlZddlZddlZddZddZddZd d Ze d krXe edS) a finddiv - a grep-like tool that looks for division operators. Usage: finddiv [-l] file_or_directory ... For directory arguments, all files in the directory whose name ends in .py are processed, and subdirectories are processed recursively. This actually tokenizes the files to avoid false hits in comments or strings literals. By default, this prints all lines containing a / or /= operator, in grep -n style. With the -l option specified, it prints the filename of files that contain at least one / or /= operator. Nc Csyttjddd\}}Wn,tjk rJ}z t|dSd}~XYnX|s\tddSd}x0|D](\}}|dkrttdS|dkrfd}qfWd}x|D]}t||}|p|}qW|S)NZlhz&at least one file argument is requiredrz-hz-l)getoptsysargverrorusageprint__doc__process) Zoptsargsmsg listnamesoaexitfilenamexr:/opt/alt/python37/lib64/python3.7/Tools/scripts/finddiv.pymains(   rcCsJtjdtjd|ftjdtjdtjdtjddS)Nz%s: %s rzUsage: %s [-l] file ... z"Try `%s -h' for more information. )rstderrwriter)r rrrr-src Cstj|rt||Sy t|}Wn2tk rT}ztjd|dSd}~XYnXt |j }d}xR|D]J\}}\}} } } |dkrl|rt |P||krl|}t d||| fddqlW| dS)NzCan't open: %s r)/z/=z%s:%d:%s )end)ospathisdir processdiropenIOErrorrrrtokenizegenerate_tokensreadliner close) rrfpr gZlastrowtypetokenrowcolrlinerrrr 2s$    r c Csyt|}Wn2tk r@}ztjd|dSd}~XYnXg}xB|D]:}tj||}tj| ds|tj |rL| |qLW|j tjjdd}x|D]}t ||}|p|}qW|S)NzCan't list directory: %s rz.py)key)rlistdirOSErrorrrrrjoinnormcaseendswithrappendsortr ) dirrnamesr filesnamefnrrrrrrFs     r__main__) r rrrr"rrr r__name__rrrrrs