
    yIf                       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
j        d          Z e
j        d	          Z e
j        d
          Zefd7dZ G d de          Zd\  ZZZZZdZ e
j        d          ef e
j        d          ef e
j        d          ef e
j        d          ef e
j        d          efgZ d8dZ!d9d Z"ej#        fd:d$Z$ej#        fd;d&Z% ej&        d'(          d<d)            Z'd=d*Z(d>d,Z)d?d/Zd@d3Z*d<d4Z+dAd6Z,dS )Bz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                    t          | t                    s
J |             |                    |           }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              3  >   K   | ]}|                                 V  d S N)strip.0items     @/var/www/piapp/venv/lib/python3.11/site-packages/flake8/utils.py	<genexpr>z-parse_comma_separated_list.<locals>.<genexpr>)   s*      33

333333    c                    g | ]}||S  r   r   s     r   
<listcomp>z.parse_comma_separated_list.<locals>.<listcomp>*   s    ...T.D...r   )
isinstancer	   split)r   r
   	separateditem_gens       r   parse_comma_separated_listr      sZ     eS!!((5(((U##I33333H..X....r   c                  $    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"         GGGHHHHHr   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                   g }d}|t          |           k     rt          D ]z\  }}|                    | |          }|r]|                    t	          ||                                                                                     |                                } n{t          d| |          |t          |           k     |                    t	          t          d                     |S )Nr   unreachable )
len_FILE_LIST_TOKEN_TYPESmatchappendr!   groupr   endAssertionError_EOF)r   tokensitoken_re
token_namer4   s         r    _tokenize_files_to_codes_mappingr>   =   s    F	A
c%jj..$: 	: 	: HjNN5!,,E fZ1D1D1F1FGGHHHIIKK
 !q999 c%jj.. MM&r""###Mr   value_Sequence[str] | strlist[tuple[str, list[str]]]c                \   t          | t                    sd                    |           n| g                                 sS  G d d          dfd}dfd}t	                    D ]8}|j        t          t          hv rd	_         j	        sg|j        t          k    rd	_	        d	_        Fj        r7|j        t          k    r'j                            |j                   d
_         |            |j        t          k    r |             j        r7|j        t           k    r'j                            |j                   d
_        j        rB|j        t          k    r2 |             j                            |j                   d
_        0 |            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                  4    e Zd ZU dZdZg Zded<   g Zded<   dS )+parse_files_to_codes_mapping.<locals>.StateTFr   	filenamescodesN)r$   r%   r&   seen_sep
seen_colonrF   r'   rG   r   r   r   StaterE   b   s>         
!	!!!!r   rJ   r   Nonec                     j         r&j        D ]}                     | j         f           d_        d_        g _        g _         d S )NTF)rG   rF   r5   rH   rI   )filenamerJ   rets    r   _resetz,parse_files_to_codes_mapping.<locals>._reseth   s[    ; 	4!O 4 4

Hek23333 r   exceptions.ExecutionErrorc                 |    t          j        dt          j                                         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   s   r   _unexpected_tokenz7parse_files_to_codes_mapping.<locals>._unexpected_tokenq   s@    (8 u{{}}f558 8
 
 	
r   TF)r   rK   )r   rP   )r   r	   joinr   r>   r"   _COMMA_WSrH   rI   _COLON_FILErF   r5   r#   r9   _CODErG   )r?   rO   rU   tokenrJ   rN   r   s       @@@r   parse_files_to_codes_mappingr]   N   s    fc"" 		&!!')C;;== 
             
 
 
 
 
 
 2%88 * *8}$$!ENN! 	*x6!!#' !% *EH$5$5&&uy111!&''))) x4 *EH$5$5""59---!& *EH$5$5&&uy111!&'')))Jr   pathsSequence[str]parentc                ^    t          | t                    s
J |             fd| D             S )zkNormalize a list of paths relative to a parent directory.

    :returns:
        The normalized paths.
    c                0    g | ]}t          |          S r   )normalize_path)r   pr`   s     r   r   z#normalize_paths.<locals>.<listcomp>   s#    555!N1f%%555r   )r   list)r^   r`   s    `r   normalize_pathsrf      s=     eT""))E)))5555u5555r   pathc                   t           j        j        }t           j        j        pd}| dk    s
|| v s|rA|| v r=t           j                            t           j                            ||                     } |                     ||z             S )zINormalize a single-path.

    :returns:
        The normalized path.
    r1   .)osrg   sepaltsepabspathrV   rstrip)rg   r`   	separatoralternate_separators       r   rc   rc      s~     I'..B $74$?$?wrw||FD99::;;y#66777r      )maxsizec                    t           j        j                                        } t	          j        |           }	 t          j        |j                  \  }}|	                    d           t	          j
        ||                                          S # t          t          t          f$ r |                     d          cY S w xY 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_s       r   stdin_get_valuer      s     )"''))K	K	 	 B+,R[99	



F++00222l3 + + +!!'*****+s   AB ,C ?C c                 \    t          t          j        t                                          S )z8Return lines of stdin split according to file splitting.)re   rx   StringIOr   r   r   r   stdin_get_linesr      s     O--..///r   boolc                
    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   )r^   s    r   is_using_stdinr      s     %<r   rM   patternsc                B     |sdS t           f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  B   K   | ]}t          j        |          V  d S r   )_fnmatchfnmatch)r   patternrM   s     r   r   zfnmatch.<locals>.<genexpr>   s0      KKwx'22KKKKKKr   )any)rM   r   s   ` r   r   r      s5      tKKKK(KKKKKKr   log_messageloggerlogging.Loggerc                B   |sdS t           j                            |           }|dvr+t          ||          r|                    ||dd           dS t           j                            |           }t          ||          }|                    |||rd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>   ..ri   r1   )rg   whetherTznot )rj   rg   basenamer   debugrm   )rg   r   r   r   r   absolute_pathr4   s          r   matches_filenamer      s    "  uw%%H{""wx'B'B"[8"C"CDDDtGOOD))MM8,,E
LL+B22FCC   Lr   c                     d                     t          j                    t          j                    t          j                              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   get_python_versionr   	  s?     &((!!  r   sc                \    t                               d|                                           S )z3Normalize a distribution name according to PEP 503.r   )NORMALIZE_PACKAGE_NAME_REsublower)r   s    r   normalize_pypi_namer     s$    $((a0066888r   )r   r	   r
   r   r   r   )r   r	   r   r.   )r?   r@   r   rA   )r^   r_   r`   r	   r   r   )rg   r	   r`   r	   r   r	   )r   r	   )r   r   )r^   r   r   r   )rM   r	   r   r_   r   r   )
rg   r	   r   r_   r   r	   r   r   r   r   )r   r	   r   r	   )-__doc__
__future__r   r   r   	functoolsrx   loggingrj   r   rert   rS   rz   typingr   r   r   flake8r   compileCOMMA_SEPARATED_LIST_RELOCAL_PLUGIN_LIST_REr   r   r!   r[   rZ   rY   rW   rX   r9   r3   r>   r]   curdirrf   rc   	lru_cacher   r   r   r   r   r   r   r   r   <module>r      s   ! ! " " " " " "         				  				  				 



                          $"*X.. !rz"233 &BJy11  (?/ / / / /(    Z   
 %K !uffcRZ)**E2RZe$RZ
V$RZ
V$RZ    "G G G GV )+		6 	6 	6 	6 	6 -/I 8 8 8 8 8* Q	+ 	+ 	+  	+0 0 0 0
   L L L L$   B
 
 
 
9 9 9 9 9 9r   