o
    h                     @   s   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dZdddZdd	d
Zdd Zdd Zdd Zdd Zdd ZdddZdS )z,
API for the command-line I{pyflakes} tool.
    N)checker__version__)reporter)check	checkPathcheckRecursiveiterSourceCodemains#   ^#!.*\bpython(3(\.\d+)?|w)?[dmu]?\sc              
   C   s   |du rt  }z	tj| |d}W n1 ty3 } z|||jd |j|j|j	 W Y d}~dS d}~w t
yB   ||d Y dS w tj||d}|jjdd d |jD ]}|| qVt|jS )	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                 S   s   | j S N)lineno)m r   B/var/www/html/ai/venv/lib/python3.10/site-packages/pyflakes/api.py<lambda>0   s    zcheck.<locals>.<lambda>)key)modReporter_makeDefaultReporterastparseSyntaxErrorsyntaxErrorargsr   offsettext	ExceptionunexpectedErrorr   Checkermessagessortflakelen)
codeStringr
   r   treeewwarningr   r   r   r      s"   

r   c              
   C   s   |du rt  }zt| d}| }W d   n1 sw   Y  W n ty? } z|| |jd  W Y d}~dS d}~ww t|| |S )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%   r   r   r   r   6   s   	
r   c                 C   s   |  drdS |  drdS d}z(t| d}||}|s(	 W d   W dS W d   n1 s2w   Y  W n
 tyB   Y dS w t|S )z0Return True if filename points to a Python file.z.pyT~F   r(   N)endswithr)   r*   r+   PYTHON_SHEBANG_REGEXmatch)r
   	max_bytesr,   r   r   r   r   isPythonFileJ   s$   



r4   c                 c   s`    | D ]*}t j|r*t |D ]\}}}|D ]}t j||}t|r'|V  qqq|V  qdS )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joinr4   )pathsr6   dirpathdirnames	filenamesr
   	full_pathr   r   r   r   `   s   r   c                 C   s$   d}t | D ]	}|t||7 }q|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
sourcePathr   r   r   r   s   s   
r   c                    s`   ddl }zt|| }W n
 ty   Y dS w  fdd}z	| || W dS  ty/   Y dS 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                    s   t   d S r   )sysexit)sigr,   messager   r   handler   s   z_exitOnSignal.<locals>.handler)signalgetattrAttributeError
ValueError)sigNamerE   rG   	sigNumberrF   r   rD   r   _exitOnSignal   s   rM   c                   C   s   dt t t f S )zQ
    Retrieve and format package version along with python version & OS used
    z%s Python %s on %s)r   platformpython_versionsystemr   r   r   r   _get_version   s   rQ   c                 C   s   ddl }tdd tdd |j| dd}|jd	d
dt d |jdddd |j|dj}t }|r:t	||}n	t
tj d|}t|dk)z&Entry point for the script "pyflakes".r   NSIGINTz... stoppedSIGPIPEr   z$Check Python source files for errors)progdescriptionz-Vz	--versionversion)actionrV   r6   *z7Path(s) of Python file(s) to check. STDIN if not given.)nargshelp)r   z<stdin>)argparserM   ArgumentParseradd_argumentrQ   
parse_argsr6   r   r   r   r   rA   stdinr*   
SystemExit)rT   r   r[   parserr   r?   r   r   r   r	      s    

r	   r   )NN)__doc__r   r5   rN   rerA   pyflakesr   r   r   r   __all__compiler1   r   r   r4   r   r   rM   rQ   r	   r   r   r   r   <module>   s$    


$