o
    h                     @  s  d Z ddlmZ ddlZddlZddlZddlZddl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 ddlmZ ddlmZ ddlmZ e
dZe
d	Ze
d
ZefdCddZG dd deZd\ZZZZZdZe
defe
defe
defe
defe
defgZ dDddZ!dEd"d#Z"ej#fdFd'd(Z$ej#fdGd*d+Z%ej&d,d-dHd.d/Z'dId0d1Z(dJd3d4Z)dKd7d8ZdLd<d=Z*dHd>d?Z+dMdAdBZ,dS )NzUtility methods for flake8.    )annotationsN)
NamedTuple)Pattern)Sequence)
exceptionsz[,\s]z[,\t\n\r\f\v]z[-_.]+valuestrregexpPattern[str]return	list[str]c                 C  s8   t | ts	J | || }dd |D }dd |D S )a  Parse a comma-separated list.

    :param value:
        String to be parsed and normalized.
    :param regexp:
        Compiled regular expression used to split the value when it is a
        string.
    :returns:
        List of values with whitespace stripped.
    c                 s  s    | ]}|  V  qd S N)strip.0item r   B/var/www/html/ai/venv/lib/python3.10/site-packages/flake8/utils.py	<genexpr>)   s    z-parse_comma_separated_list.<locals>.<genexpr>c                 S  s   g | ]}|r|qS r   r   r   r   r   r   
<listcomp>*   s    z.parse_comma_separated_list.<locals>.<listcomp>)
isinstancer   split)r   r	   	separateditem_genr   r   r   parse_comma_separated_list   s   
r   c                   @  s   e Zd ZU ded< ded< dS )_Tokenr   tpsrcN)__name__
__module____qualname____annotations__r   r   r   r   r   -   s   
 r   )codefilecoloncommawseofz[A-Z]+[0-9]*(?=$|\s|,)z[^\s:,]+z\s*:\s*z\s*,\s*z\s+list[_Token]c                 C  s   g }d}|t | k r7tD ]\}}|| |}|r*|t||   | } nqtd| ||t | k s
|tt	d |S )Nr   unreachable )
len_FILE_LIST_TOKEN_TYPESmatchappendr   groupr   endAssertionError_EOF)r   tokensitoken_re
token_namer-   r   r   r    _tokenize_files_to_codes_mapping=   s   	r7   value_Sequence[str] | strlist[tuple[str, list[str]]]c                   s0  t | tsd| n| g  sS G dd d d fdd}dfd	d
}tD ]f}|jtthv r<d _q/ j	sa|jt
krKd _	d _q/ jr^|jtkr^ j|j d _q/| |jtkrj|  q/ jr}|jtkr} j|j d _q/ jr|jtkr|   j|j d _q/| S )a  Parse a files-to-codes mapping.

    A files-to-codes mapping a sequence of values specified as
    `filenames list:codes list ...`.  Each of the lists may be separated by
    either comma or whitespace tokens.

    :param value: String to be parsed and normalized.
    
c                   @  s.   e Zd ZU dZdZg Zded< g Zded< dS )z+parse_files_to_codes_mapping.<locals>.StateTFr   	filenamescodesN)r   r   r    seen_sep
seen_colonr<   r!   r=   r   r   r   r   Stateb   s
   
 r@   r   Nonec                    s>    j r jD ]
} |  j f qd _d _g  _g  _ d S )NTF)r=   r<   r.   r>   r?   filename)r@   retr   r   _reseth   s   

z,parse_files_to_codes_mapping.<locals>._resetexceptions.ExecutionErrorc                     s   t dt  d S )NzExpected `per-file-ignores` to be a mapping from file exclude patterns to ignore codes.

Configured `per-file-ignores` setting:

z    )r   ExecutionErrortextwrapindentr   r   )r   r   r   _unexpected_tokenq   s
   z7parse_files_to_codes_mapping.<locals>._unexpected_tokenTFN)r   rA   )r   rF   )r   r   joinr   r7   r   _COMMA_WSr>   r?   _COLON_FILEr<   r.   r   r2   _CODEr=   )r8   rE   rJ   tokenr   )r@   rD   r   r   parse_files_to_codes_mappingN   s>   
	

rR   pathsSequence[str]parentc                   s$   t | ts	J |  fdd| D S )zkNormalize a list of paths relative to a parent directory.

    :returns:
        The normalized paths.
    c                   s   g | ]}t | qS r   )normalize_path)r   prU   r   r   r      s    z#normalize_paths.<locals>.<listcomp>)r   list)rS   rU   r   rX   r   normalize_paths   s   rZ   pathc                 C  sT   t jj}t jjp	d}| dks|| v s|r#|| v r#t jt j|| } | || S )zINormalize a single-path.

    :returns:
        The normalized path.
    r*   .)osr[   sepaltsepabspathrK   rstrip)r[   rU   	separatoralternate_separatorr   r   r   rV      s   	rV      )maxsizec               
   C  sf   t jj } t| }zt|j\}}|	d t
|| W S  tttfy2   | d Y S w )z'Get and cache it so plugins can use it.r   zutf-8)sysstdinbufferreadioBytesIOtokenizedetect_encodingreadlineseekTextIOWrapperLookupErrorSyntaxErrorUnicodeErrordecode)stdin_valuefdcoding_r   r   r   stdin_get_value   s   

ry   c                   C  s   t tt S )z8Return lines of stdin split according to file splitting.)rY   rj   StringIOry   r   r   r   r   stdin_get_lines      r{   boolc                 C  s   d| v S )zDetermine if we're going to read from stdin.

    :param paths:
        The paths that we're going to check.
    :returns:
        True if stdin (-) is in the path, otherwise False
    -r   )rS   r   r   r   is_using_stdin   s   r   rC   patternsc                   s   |sdS t  fdd|D S )a  Wrap :func:`fnmatch.fnmatch` to add some functionality.

    :param filename:
        Name of the file we're trying to match.
    :param patterns:
        Patterns we're using to try to match the filename.
    :param default:
        The default value if patterns is empty
    :returns:
        True if a pattern matches the filename, False if it doesn't.
        ``True`` if patterns is empty.
    Tc                 3  s    | ]	}t  |V  qd S r   )_fnmatchfnmatch)r   patternrB   r   r   r      s    zfnmatch.<locals>.<genexpr>)any)rC   r   r   rB   r   r      s   r   log_messageloggerlogging.Loggerc                 C  sp   |sdS t j| }|dvrt||r|||dd dS t j| }t||}||||r1dndd |S )aH  Use fnmatch to discern if a path exists in patterns.

    :param path:
        The path to the file under question
    :param patterns:
        The patterns to match the path against.
    :param log_message:
        The message used for logging purposes.
    :returns:
        True if path matches patterns, False otherwise
    F>   ..r\   r*   )r[   whetherTznot )r]   r[   basenamer   debugr`   )r[   r   r   r   r   absolute_pathr-   r   r   r   matches_filename   s   
r   c                   C  s   d t t t S )zFind and format the python implementation and version.

    :returns:
        Implementation name, version, and platform as a string.
    z{} {} on {})formatplatformpython_implementationpython_versionsystemr   r   r   r   get_python_version	  s
   r   sc                 C  s   t d|  S )z3Normalize a distribution name according to PEP 503.r~   )NORMALIZE_PACKAGE_NAME_REsublower)r   r   r   r   normalize_pypi_name  r|   r   )r   r   r	   r
   r   r   )r   r   r   r(   )r8   r9   r   r:   )rS   rT   rU   r   r   r   )r[   r   rU   r   r   r   )r   r   )r   r   )rS   r   r   r}   )rC   r   r   rT   r   r}   )
r[   r   r   rT   r   r   r   r   r   r}   )r   r   r   r   )-__doc__
__future__r   r   r   	functoolsrj   loggingr]   r   rerf   rH   rl   typingr   r   r   flake8r   compileCOMMA_SEPARATED_LIST_RELOCAL_PLUGIN_LIST_REr   r   r   rP   rO   rN   rL   rM   r2   r,   r7   rR   curdirrZ   rV   	lru_cachery   r{   r   r   r   r   r   r   r   r   <module>   sV    



	
K





!