
    g                       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	 	 	 	 	 d"d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 d#dZ!	 	 	 	 d$dZ"ejF                  f	 	 	 	 	 d%dZ$ejF                  fd&dZ% ejL                  d      d'd       Z'd(dZ(d)dZ)d*dZ	 	 	 	 	 	 	 	 	 	 d+dZ*d'd Z+d,d!Z,y)-zUtility methods for flake8.    )annotationsN)
NamedTuple)Pattern)Sequence)
exceptionsz[,\s]z[,\t\n\r\f\v]z[-_.]+c                    t        | t              sJ |        |j                  |       }d |D        }|D cg c]  }|s|	 c}S c c}w )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   | ]  }|j                           y wN)strip).0items     O/var/www/html/brdwt/brdwt/brdwtenv/lib/python3.12/site-packages/flake8/utils.py	<genexpr>z-parse_comma_separated_list.<locals>.<genexpr>)   s     3

3s   )
isinstancestrsplit)valueregexp	separateditem_genr   s        r   parse_comma_separated_listr      sG     eS!(5(!U#I33H%.TD...s
   AAc                  "    e Zd ZU ded<   ded<   y)_Tokenr   tpsrcN)__name__
__module____qualname____annotations__     r   r   r   -   s    G	Hr!   r   )codefilecoloncommawseofz[A-Z]+[0-9]*(?=$|\s|,)z[^\s:,]+z\s*:\s*z\s*,\s*z\s+c                v   g }d}|t        |       k  rt        D ]b  \  }}|j                  | |      }|s|j                  t	        ||j                         j                                      |j                         } n t        d| |      |t        |       k  r|j                  t	        t        d             |S )Nr   unreachable )
len_FILE_LIST_TOKEN_TYPESmatchappendr   groupr   endAssertionError_EOF)r   tokensitoken_re
token_namer-   s         r    _tokenize_files_to_codes_mappingr7   =   s    F	A
c%j.$: 	: HjNN5!,EfZ1D1D1FGHIIK	: !q99 c%j. MM&r"#Mr!   c                   t        | t              sdj                  |       n| g j                         sS  G d d      dfd}d	fd}t	              D ]e  }|j
                  t        t        hv rd_        $j                  su|j
                  t        k(  rd_	        d_        Rj                  r@|j
                  t        k(  r-j                  j                  |j                         d_         |       |j
                  t        k(  r |        j                  rA|j
                  t         k(  r.j"                  j                  |j                         d_        j                  rH|j
                  t        k(  r5 |        j                  j                  |j                         d_        a |        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                  2    e Zd ZU dZdZg Zded<   g Zded<   y)+parse_files_to_codes_mapping.<locals>.StateTF	list[str]	filenamescodesN)r   r   r   seen_sep
seen_colonr=   r   r>   r    r!   r   Stater;   b   s     
!	9!yr!   rA   c                     j                   r.j                  D ]  } j                  | j                   f       ! d_        d_        g _        g _         y )NTF)r>   r=   r.   r?   r@   )filenamerA   rets    r   _resetz,parse_files_to_codes_mapping.<locals>._reseth   sO    ;;!OO 4

Hekk234 r!   c                 x    t        j                  dt        j                   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   s9    ((9 u{{}f568
 	
r!   TF)returnNone)rK   zexceptions.ExecutionError)r   r   joinr   r7   r   _COMMA_WSr?   r@   _COLON_FILEr=   r.   r   r2   _CODEr>   )value_rE   rJ   tokenrA   rD   r   s       @@@r   parse_files_to_codes_mappingrU   N   sX    fc"		&!')C;;=
 
 2%8 *88}$!EN!!xx6!#' !%EHH$5&&uyy1!&')) xx4EHH$5""599-!&EHH$5&&uyy1!&'))5*8 Jr!   c                n    t        | t              sJ |        | D cg c]  }t        ||       c}S c c}w )zkNormalize a list of paths relative to a parent directory.

    :returns:
        The normalized paths.
    )r   listnormalize_path)pathsparentps      r   normalize_pathsr\      s4     eT")E)"/45!N1f%555s   2c                2   t         j                  j                  }t         j                  j                  xs d}| dk(  s
|| v s|rA|| v r=t         j                  j	                  t         j                  j                  ||             } | j                  ||z         S )zINormalize a single-path.

    :returns:
        The normalized path.
    r*   .)ospathsepaltsepabspathrM   rstrip)r`   rZ   	separatoralternate_separators       r   rX   rX      st     I''...B$74$?wwrww||FD9:;;y#6677r!      )maxsizec                    t         j                  j                  j                         } t	        j
                  |       }	 t        j                  |j                        \  }}|j                  d       t	        j                  ||      j                         S # t        t        t        f$ r | j                  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	

F+0022l3 +!!'**+s   AB %B>=B>c                 N    t        t        j                  t                           S )z8Return lines of stdin split according to file splitting.)rW   rn   StringIOr}   r    r!   r   stdin_get_linesr      s    O-.//r!   c                
    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    )rY   s    r   is_using_stdinr      s     %<r!   c                2     |sy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  J   K   | ]  }t        j                  |        y wr
   )_fnmatchfnmatch)r   patternrC   s     r   r   zfnmatch.<locals>.<genexpr>   s     Kwx'2Ks    #)any)rC   patternss   ` r   r   r      s     K(KKKr!   c                   |syt         j                  j                  |       }|dvr"t        ||      r|j	                  ||dd       yt         j                  j                  |       }t        ||      }|j	                  |||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>   ..r^   r*   )r`   whetherTznot )r_   r`   basenamer   debugrc   )r`   r   log_messageloggerr   absolute_pathr-   s          r   matches_filenamer      s    " ww%H{"wx'B[8"CDGGOOD)MM8,E
LL2FC Lr!   c                     dj                  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   	  s9     &&(! r!   c                J    t         j                  d|       j                         S )z3Normalize a distribution name according to PEP 503.r   )NORMALIZE_PACKAGE_NAME_REsublower)ss    r   normalize_pypi_namer     s    $((a06688r!   )r   r   r   zPattern[str]rK   r<   )r   r   rK   zlist[_Token])rS   zSequence[str] | strrK   zlist[tuple[str, list[str]]])rY   Sequence[str]rZ   r   rK   r<   )r`   r   rZ   r   rK   r   )rK   r   )rK   r<   )rY   r<   rK   bool)rC   r   r   r   rK   r   )
r`   r   r   r   r   r   r   zlogging.LoggerrK   r   )r   r   rK   r   )-__doc__
__future__r   r   r   	functoolsrn   loggingr_   r   rerj   rH   rp   typingr   r   r   flake8r   compileCOMMA_SEPARATED_LIST_RELOCAL_PLUGIN_LIST_REr   r   r   rR   rQ   rP   rN   rO   r2   r,   r7   rU   curdirr\   rX   	lru_cacher}   r   r   r   r   r   r    r!   r   <module>r      s   ! "   	  	  	 
      $"**X. !rzz"23 &BJJy1  (?//$//(Z 
 %K !uffcRZZ)*E2RZZe$RZZ
V$RZZ
V$RZZ "GG GV )+			6	6"%	6	6 -/II 8* Q	+  	+0
L$
  	
 
B
9r!   