HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib64/python3.10/site-packages/flake8/__pycache__/checker.cpython-310.pyc
o

%we5X�@s�UdZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"eee#e$e$e#ee#fZ%e�&e'�Z(ej)hZ*de+d<de+d<ej,d7dd��Z-d8d!d"�Z.d9d&d'�Z/Gd(d)�d)�Z0Gd*d+�d+�Z1d:d/d0�Z2d;d5d6�Z3dS)<z$Checker Manager and Checker classes.�)�annotationsN)�Any)�	Generator)�List)�Optional)�Sequence)�Tuple)�defaults)�
exceptions)�	processor)�utils)�
FSTRING_START)�expand_paths)�
parse_args)�Checkers)�LoadedPlugin)�StyleGuideManagerr�_mp_plugins�argparse.Namespace�_mp_options�plugins�options�return�Generator[None, None, None]ccs$�||aazdVWbbdSbbw�N)rr)rr�r�G/home/arjun/projects/env/lib/python3.10/site-packages/flake8/checker.py�_mp_prefork5s
�
r�argv�
Sequence[str]�NonecCsLt�tjtj�zttfWdSty%t|�\}}|j|aaYdSwr)�signal�SIGINT�SIG_IGNrr�	NameErrorr�checkers)rrrrrr�_mp_initBs�r&�filename�str�#tuple[str, Results, dict[str, int]]cCst|ttd���S)N�r'rr)�FileCheckerrr�
run_checks�r'rrr�_mp_runOs
��r.c@steZdZdZd%d
d�Zd&dd
�Zd'dd�Zd(dd�Zd)dd�Zd&dd�Z	d&dd�Z
d&dd�Zd&d d!�Zd&d"d#�Z
d$S)*�ManageraRManage the parallelism and checker instances for each plugin and file.

    This class will be responsible for the following:

    - Determining the parallelism of Flake8, e.g.:

      * Do we use :mod:`multiprocessing` or is it unavailable?

      * Do we automatically decide on the number of jobs to use or did the
        user provide that?

    - Falling back to a serial way of processing files if we run into an
      OSError related to :mod:`multiprocessing`

    - Organizing the results of each checker so we can group the output
      together and make our output deterministic.
    �style_guiderrrrrrr cCsV||_|j|_||_|��|_ddddd�|_g|jj�|jj�R|_||_g|_	dS)z Initialize our Manager instance.r)�files�
logical lines�physical lines�tokensN)
r0rr�
_job_count�jobs�
statistics�exclude�extend_excluder�results)�selfr0rrrrr�__init__hs
�
zManager.__init__cCsP|jD]\}}}tjD]
}|j|||7<qq|jdt|j�7<dS)Nr1)r:r	�STATISTIC_NAMESr7�len�	filenames)r;�_r7�	statisticrrr�_process_statistics}s

�zManager._process_statistics�intcCsPt�|jj�rt�d�dS|jj}|jr%zt�	�WSt
y$YdSw|jS)Nz]The --jobs option is not compatible with supplying input using - . Ignoring --jobs arguments.r)r�is_using_stdinrr?�LOG�warningr6�is_auto�multiprocessing�	cpu_count�NotImplementedError�n_jobs)r;r6rrrr5�s�
�zManager._job_countr'r(r:�Resultsc

Cs<|j}d}|D]\}}}}}	||j||||||	d�7}q|S)Nr)�coder'�line_number�
column_number�text�
physical_line)r0�handle_error)
r;r'r:r0�reported_results_count�
error_coderN�columnrPrQrrr�_handle_results�s
�zManager._handle_results�tuple[int, int]c	Cs�d}}|jjt�d�d�|jD]3\}}}|jt�dd�d�|j�|��||�||�7}Wd�n1s9wY|t|�7}q||fS)aReport all of the errors found in the managed file checkers.

        This iterates over each of the checkers and reports the errors sorted
        by line number.

        :returns:
            A tuple of the total results found and the results reported.
        r)�key��N)r:�sort�operator�
itemgetterr0�processing_filerVr>)r;�results_reported�
results_foundr'r:r@rrr�report�s	�zManager.reportcCs�t|j|j��t|j|j�}Wd�n1swY|dur(|��dSd}z#t|�t	|j
��|_|��|�
�d}W|sL|��|�
�dSdS|sY|��|�
�ww)zRun the checkers in parallel.NFT)rrr�_try_initialize_processpoolr6r�
run_serial�list�imap_unorderedr.r?r:�close�join�	terminate)r;�pool�pool_closedrrr�run_parallel�s&��
�zManager.run_parallelcs�fdd��jD��_dS)zRun the checkers in serial.cs"g|]
}t|�j�jd����qS)r*)r+rrr,)�.0r'�r;rr�
<listcomp>�s���z&Manager.run_serial.<locals>.<listcomp>N)r?r:rmrrmrrc�s
�zManager.run_serialcCsXz|jdkrt|j�dkr|��WdS|��WdSty+t�d�t�	d��w)a#Run all the checkers.

        This will intelligently decide whether to run the checks in parallel
        or whether to run them in serial.

        If running the checks in parallel causes a problem (e.g.,
        :issue:`117`) this also implements fallback to serial processing.
        rYz"Flake8 was interrupted by the userzEarly quit while running checksN)
r6r>r?rkrc�KeyboardInterruptrErFr
�	EarlyQuitrmrrr�run�s	

�zManager.runcCs2t�d�tt|jj|jj|jj|jd��|_dS)z�Start checking files.

        :param paths:
            Path names to check. This is passed directly to
            :meth:`~Manager.make_checkers`.
        zMaking checkers)�paths�stdin_display_name�filename_patternsr8N)	rE�info�tuplerrr?rsr'r8rmrrr�start�s
�
�z
Manager.startcCs|��dS)zStop checking files.N)rBrmrrr�stop�zManager.stopN)r0rrrrrrr �rr )rrC)r'r(r:rLrrC)rrW)�__name__�
__module__�__qualname__�__doc__r<rBr5rVrarkrcrqrwrxrrrrr/Us








r/c@s�eZdZdZd9d
d�Zd:dd
�Zd;dd�Zd<dd�Zd=dd�Ze	d>d"d#��Z
d?d$d%�Zd?d&d'�Zd@d)d*�Z
d?d+d,�ZdAd.d/�ZdBd1d2�ZdCd6d7�Zd8S)Dr+z;Manage running checks for a file and aggregate the results.r'r(rrrrrr cCsx||_||_||_g|_dddd�|_|��|_||_d|_|jdur:|jj|_|j�	�|_t
|jj�|jd<dSdS)zInitialize our file checker.r)r4r2r3FNr3)rr'rr:r7�_make_processorr�display_name�should_process�should_ignore_filer>�lines)r;r'rrrrrr<s �


�zFileChecker.__init__cCsd|j��S)z)Provide helpful debugging representation.zFileChecker for r-rmrrr�__repr__$ryzFileChecker.__repr__�processor.FileProcessor | NonecCsZz	t�|j|j�WSty,}z|�dddt|�j�d|���WYd}~dSd}~ww)N�E902r�: )r�
FileProcessorr'r�OSErrorra�typer{)r;�errrr(s ��zFileChecker._make_processorrT�
str | NonerNrCrUrPcCsX|dur|�dd�\}}t|d�r|jdur|j�|�}nd}|j�|||||f�|S)z2Report an error by storing it in the results list.N� rYr)�split�hasattrr�
noqa_line_forr:�append)r;rTrNrUrP�linerrrra5szFileChecker.report�pluginr�	argumentsrc
Ks�|jdus
J|j��z
|j�|j|�}Wnty(}ztj|j|d��d}~wwz|jdi|�|��WSt	yS}zt
jd|jdd�tj|j|j|d��d}~ww)z!Run the check in a single plugin.N)�plugin_name�	exceptionz(Plugin %s raised an unexpected exceptionT)�exc_info)r'r�r�r)
rr'�keyword_arguments_for�
parameters�AttributeErrorr
� PluginRequestedUnknownParametersr��obj�	ExceptionrE�critical�PluginExecutionFailed)r;r�r��params�ae�all_excrrr�	run_checkJs4��������zFileChecker.run_checkr�r�rWc
Cst|j�dkr#|jdr#t|jd�dkr#|jd}|dd�\}}n&t|tj�rCt|j�dkrCt|jd�dkrCd}|jd\}}nd}d\}}|dkr�|r�t|t�r�t|�dkr�d}d}|d}|dur�|�d��d�}t|�d}|d}t|�}	||	kr�|	}||8}||8}||fS)	NrYrZ�r)rYrr��
)r>�args�
isinstance�tokenize�
TokenError�SyntaxError�rstripr�)
r��token�rowrU�
column_offset�
row_offsetrQr��logical_line�logical_line_lengthrrr�_extract_syntax_informationcsB�

���	z'FileChecker._extract_syntax_informationc		Cs�|jdus
J|j��|j��}|jjD]-}|j||d�}z|��}Wnty-|}Ynw|D]\}}}}|jd|||d�q0qdS)z1Run all checks expecting an abstract syntax tree.N)�tree�rTrNrUrP)	rr'�	build_astrr�r�rqr�ra)	r;�astr��checker�runnerrN�offsetrPr@rrr�run_ast_checks�s$
����zFileChecker.run_ast_checksc
Cs�|jdusJ�|j��\}}}|sdS|j�|�t�d|���|jjD]:}|j�|�|j	||d�p5d}|D]&\}}t
||�\}}	||	krMdkrUnnt�d|�|jd||	|d�q8q%|j�
�dS)z(Run all checks expecting a logical line.NzLogical line: "%s")r�rrz#position of error out of bounds: %sr�)r�build_logical_line�update_staterE�debugr�rr��update_checker_state_forr��find_offsetrFra�next_logical_line)
r;�commentsr��mappingr�r:r�rPrNr�rrr�run_logical_checks�s*��zFileChecker.run_logical_checksrQc
Cs�|jdusJ�|jjD]C}|j�|�|j||d�}|durNd}z|d}Wnttfy1Ynwt|t�r:|f}|D]}|\}}|j	d|jj
||d�q<qdS)zoRun all checks for a given physical line.

        A single physical check may return multiple errors.
        N)rQrr�)rrrQr�r��
IndexError�	TypeErrorr�rCrarN)r;rQr��resultr��
result_singlerPrrr�run_physical_checks�s.�
���zFileChecker.run_physical_checkscCs�|jdusJ�d}|j}|j}d}|��D]6}|dd7<|�||�|dd�\}}|tjkr9t�||�}n|dkrGt�|�rG|�|�|d}q|j	r]|�
|jd�|��dSdS)	z�Process tokens and trigger checks.

        Instead of using this directly, you should use
        :meth:`flake8.checker.FileChecker.run_checks`.
        Nr�r4rYrZr����)
rr7�generate_tokens�check_physical_eolr��OP�count_parentheses�token_is_newline�handle_newliner4r�r�r�)r;�parensr7�file_processor�
prev_physicalr��
token_typerPrrr�process_tokens�s&



�zFileChecker.process_tokensr)cCs�|jdus|js|j|j|jfSz
|��|��WnAttj	fy[}z2t
|tj	�r-dnd}|�|�\}}|�|||t
|�j�d|jd���|j|j|jfWYd}~Sd}~ww|jjd}||jd<|j|j|jfS)zRun checks against the file.Nr��E999r�rr2)rr�r�r:r7r�r�r�r�r�r�r�rar�r{r�)r;r�rMr�rU�
logical_linesrrrr,s&��
zFileChecker.run_checksr�cCsb|jdusJ�|tjkr|��|j��dSt|jj�dkr+|j��|j��dS|��dS)z3Handle the logic when encountering a newline token.NrY)	rr��NEWLINEr��reset_blank_beforer>r4�visited_new_blank_line�delete_first_token)r;r�rrrr�s

zFileChecker.handle_newliner��tokenize.TokenInfor�cCs�|jdusJ�|jtkr|j�|jd�dSt�|�r0|jdkr(|�|�dS|�|j�dSt�|�rC|j�	|�D]	}|�|�q;dSdS)z@Run physical checks if and only if it is at the end of the line.Nrr�)
rr�r
�
fstring_startrw�is_eol_tokenr�r��is_multiline_string�multiline_string)r;r�r�r�rrrr�&s



�zFileChecker.check_physical_eolN)r'r(rrrrrr )rr()rr�)
rTr�rNrCrUrCrPr(rr()r�rr�rrr)r�r�rrWrz)rQr(rr )rr))r�rCrr )r�r�r�r(rr )r{r|r}r~r<r�rrar��staticmethodr�r�r�r�r�r,r�r�rrrrr+s 





:





r+�	job_countrC� multiprocessing.pool.Pool | Nonec
CsZz
tj|t|fd�WSty#}z
|jtvr�WYd}~dSd}~wty,YdSw)z@Return a new process pool instance if we are able to create one.)�initargsN)rH�Poolr&r��errno�SERIAL_RETRY_ERRNOS�ImportError)r�r�errrrrrbFs

����rbr�r��processor._LogicalMappingrWcCsXt|t�r|S|D]}|d}||kr|d}nq	d}d}}|d|d||fS)z*Find the offset tuple for a single offset.rrY)rr)r�rv)r�r�r��token_offset�positionrrrr�Vs
�r�)rrrrrr)rrrr )r'r(rr))r�rCrrrr�)r�rCr�r�rrW)4r~�
__future__r�argparse�
contextlibr��logging�multiprocessing.poolrHr\r!r��typingrrrrrr�flake8r	r
rr�flake8._compatr
�flake8.discover_filesr�flake8.options.parse_argsr�flake8.plugins.finderrr�flake8.style_guiderr(rCrL�	getLoggerr{rE�ENOSPCr��__annotations__�contextmanagerrr&r.r/r+rbr�rrrr�<module>sV

�


4
@