
    g                         d Z ddlZddlZddlZddlZddlZddlmZmZ ddlm	Z
 g dZ ej                  d      ZddZddZd	 Zd
 Zd Zd Zd ZddZy)z,
API for the command-line I{pyflakes} tool.
    N)checker__version__)reporter)check	checkPathcheckRecursiveiterSourceCodemains#   ^#!.*\bpython(3(\.\d+)?|w)?[dmu]?\sc                    |t        j                         }	 t        j                  | |      }t        j                  ||      }|j                  j                  d        |j                  D ]  }|j!                  |        t#        |j                        S # t        $ rJ}|j                  ||j                  d   |j                  |j                  |j                         Y d}~yd}~wt        $ r |j                  |d       Y yw xY w)a  
    Check the Python source given by C{codeString} for flakes.

    @param codeString: The Python source to check.
    @type codeString: C{str}

    @param filename: The name of the file the source came from, used to report
        errors.
    @type filename: C{str}

    @param reporter: A L{Reporter} instance, where errors and warnings will be
        reported.

    @return: The number of warnings emitted.
    @rtype: C{int}
    N)filenamer      zproblem decoding sourcec                     | j                   S N)lineno)ms    O/var/www/html/brdwt/brdwt/brdwtenv/lib/python3.12/site-packages/pyflakes/api.py<lambda>zcheck.<locals>.<lambda>0   s
    !((     )key)modReporter_makeDefaultReporterastparseSyntaxErrorsyntaxErrorargsr   offsettext	ExceptionunexpectedErrorr   Checkermessagessortflakelen)
codeStringr   r   treeewwarnings          r   r   r      s    " 335yyh7 	x0AJJOO*O+::  w qzz?  Xqvvay!((AHHaffM   +DEs   B 	D	#A C((D	D	c                    |t        j                         }	 t        | d      5 }|j                         }ddd       t        | |      S # 1 sw Y   xY w# t        $ r)}|j                  | |j                  d          Y d}~yd}~ww xY w)z
    Check the given path, printing out any warnings detected.

    @param reporter: A L{Reporter} instance, where errors and warnings will be
        reported.

    @return: the number of warnings printed
    Nrbr   )r   r   openreadOSErrorr    r   r   )r   r   fcodestrr(   s        r   r   r   6   s     335(D! 	QffhG	
 (H--	 	   166!95s-   A A
A 
AA 	BBBc                    | j                  d      ry| j                  d      ryd}	 t        | d      5 }|j                  |      }|s
	 ddd       y	 ddd       t        j                        S # 1 sw Y   xY w# t        $ r Y yw xY w)z0Return True if filename points to a Python file.z.pyT~F   r,   N)endswithr-   r.   r/   PYTHON_SHEBANG_REGEXmatch)r   	max_bytesr0   r   s       r   isPythonFiler9   J   s     I(D! 	Q66)$D	 		  %%d++	 	  s.   A< A0	A< A< 0A95A< <	BBc              #     K   | D ]{  }t         j                  j                  |      rVt        j                  |      D ]=  \  }}}|D ]2  }t         j                  j	                  ||      }t        |      s/| 4 ? x| } yw)z
    Iterate over all Python source files in C{paths}.

    @param paths: A list of paths.  Directories will be recursed into and
        any .py files found will be yielded.  Any non-directories will be
        yielded as-is.
    N)ospathisdirwalkjoinr9   )pathsr<   dirpathdirnames	filenamesr   	full_paths          r   r	   r	   `   s|       77==02 (,9 ) (H "Wh ?I#I.'(( Js   A1B4Bc                 H    d}t        |       D ]  }|t        ||      z  } |S )a;  
    Recursively check all source files in C{paths}.

    @param paths: A list of paths to Python source files and directories
        containing Python source files.
    @param reporter: A L{Reporter} where all of the warnings and errors
        will be reported to.
    @return: The number of warnings found.
    r   )r	   r   )r@   r   warnings
sourcePaths       r   r   r   s   s3     H$U+ 4
Ij(334Or   c                     ddl }	 t        ||       }fd}	 |j                  ||       y# t        $ r Y yw xY w# t        $ r Y yw xY w)zHandles a signal with sys.exit.

    Some of these signals (SIGPIPE, for example) don't exist or are invalid on
    Windows. So, ignore errors that might arise.
    r   Nc                 0    t        j                         y r   )sysexit)sigr0   messages     r   handlerz_exitOnSignal.<locals>.handler   s    r   )signalgetattrAttributeError
ValueError)sigNamerM   rO   	sigNumberrN   s    `   r   _exitOnSignalrU      s\     FG,	i)   		   	s   , ; 	88	AAc                  f    t         dt        j                         dt        j                         S )zQ
    Retrieve and format package version along with python version & OS used
    z Python z on )r   platformpython_versionsystem r   r   _get_versionr[      s'    
 (113X__5FH Ir   c                    ddl }t        dd       t        dd       |j                  | d      }|j                  d	d
dt	                      |j                  ddd       |j                  |      j                  }t        j                         }|rt        ||      }n)t        t        j                  j                         d|      }t        |dkD        )z&Entry point for the script "pyflakes".r   NSIGINTz... stoppedSIGPIPEr   z$Check Python source files for errors)progdescriptionz-Vz	--versionversion)actionra   r<   *z7Path(s) of Python file(s) to check. STDIN if not given.)nargshelp)r   z<stdin>)argparserU   ArgumentParseradd_argumentr[   
parse_argsr<   r   r   r   r   rJ   stdinr.   
SystemExit)r_   r   rf   parserr   rF   s         r   r
   r
      s     (M*)Q$$$1W % YF
k)\^T
cV  X$',,D//1H!$1)9h?
X\
""r   r   )NN)__doc__r   r;   rW   rerJ   pyflakesr   r   r   r   __all__compiler6   r   r   r9   r	   r   rU   r[   r
   rZ   r   r   <module>rr      sb     	  	 
 ) ,
L!rzz"IJ !H.(,,& 6I#r   