
    ie                    6   U 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mZmZmZmZmZ ddlmZ ddlmZmZmZmZmZ ded<   	 ddlZn# e$ r dZY nw xY w	 ddlZddlZd	Zn# e$ r d
ZY nw xY w ed          Z  e! ej"        d          dz            Z#ded<    ej$        d          Z%ded<   dZ&ded<   de&z  Z'ded<   dZ(ded<   dZ)ded<   dZ*ded<   dZ+ded<    e,d          Z-ded<   ddd%Z.dd&Z/dd)Z0dd.Z1dd0Z2dd3Z3dd7Z4dd9Z5 G d: d;e6          Z7dd=Z8ddBZ9ddHZ:ddJZ;dKZ<dedL<   dMZ=dedN<   dOZ>dedP<   dQZ?dedR<   dSZ@dedT<   dd\ZAdd^ZB G d_ d`          ZCddbZDddgZEi ZFdhedi<   ddmZG	 dddtZHddvZIe	jJ        dwk    se	jJ        dxk    rddyZKndd|ZKddd~ZLddZMddZNddZOddZPddZQddZRdddZSddZTddZUddZVddZW G d d          ZXddZYddZZddZ[ddZ\e
j]        Z^ddZ_ddZ`ddZadddZbddZcdS )z3Utility functions with no non-trivial dependencies.    )annotationsN)Callable	ContainerIterableSequenceSized)	resources)IOAnyFinalLiteralTypeVarr   orjsonTFTmypytypeshedr   TYPESHED_DIRs=   ([ \t\v]*#.*(\r\n?|\n))??[ \t\v]*#.*coding[:=][ \t]*([-\w.]+)ENCODING_RE   DEFAULT_SOURCE_OFFSET 
CODE_STARTP   DEFAULT_COLUMNS   MINIMUM_WIDTH
   MINIMUM_WINDOWS_MAJOR_VT100iZ)  MINIMUM_WINDOWS_BUILD_VT100)__init____new____call____init_subclass____class_getitem__SPECIAL_DUNDERSnamestrexclude_specialboolreturnc                p    |r| t           v rdS |                     d          o|                     d          S )zReturns whether name is a dunder name.

    Args:
        exclude_special: Whether to return False for a couple special dunder methods.

    F__)r%   
startswithendswith)r&   r(   s     H/root/projects/qq-shell/venv/lib64/python3.11/site-packages/mypy/util.py	is_dunderr0   9   s>      4?22u??4  8T]]4%8%88    c                    t          |            o/|                     d          o|                     d          o| dk    S N_)r0   r-   r.   r&   s    r/   	is_sunderr6   E   s?    ^4??3#7#7^DMM#<N<N^SW[^S^^r1   mod_name	list[str]c                ~    | g}d| v r5|                      dd          d         } |                    |            d| v 5|S )zReturn the module and all parent module names.

    So, if `mod_name` is 'a.b.c', this function will return
    ['a.b.c', 'a.b', and 'a'].
    .   r   )rsplitappend)r7   outs     r/   split_module_namesr?   I   sP     *C
//??3**1-

8 // Jr1   modulesIterable[str]target
str | Nonec                :    t          | |          }|d S |d         S Nr   )split_target)r@   rB   results      r/   module_prefixrH   V   s%    '6**F~t!9r1   tuple[str, str] | Nonec                    g }	 || v r|d                     |          fS |                    dd          }t          |          dk    rd S |d         }|                    d|d                    k)NTr:   r;   r   )joinr<   leninsert)r@   rB   	remaining
componentss       r/   rF   rF   ]   s    I+W388I....]]3**
z??a4AJqM***+r1   objobjectc                    | dS t          t          |                     }|                    d          d                             d          S )zReturn the last component of the type name of an object.

    If obj is None, return 'nil'. For example, if obj is 1, return 'int'.
    Nnilr:   z'>)r'   typesplitrstrip)rP   ts     r/   
short_typerY   i   sB    
 {uDIIA773<<""4(((r1   textbytestuple[str, int]c                
   t                               |           }|rb|                    d          rdnd}|                    d                              d          }|                    d          s|dk    rd}||fS d}|d	fS )
z*PEP-263 for detecting Python file encodingr;         ascii)ziso-latin-1-zlatin-1-ziso-latin-1zlatin-1utf8rT   )r   matchgroupdecoder-   )rZ   rG   lineencodingdefault_encodings        r/   find_python_encodingrh   t   s    t$$F 	$LLOO*qq<<??))'22;<< 	!M@Y@Y H~!##r1   bc                0    t          |           dd         S )a2  Converts bytes into some human-readable representation. Unprintable
    bytes such as the nul byte are escaped. For example:

        >>> b = bytes([102, 111, 111, 10, 0])
        >>> s = bytes_to_human_readable_repr(b)
        >>> print(s)
        foo
 
        >>> print(repr(s))
        'foo\n\x00'
    r^   rT   )repr)ri   s    r/   bytes_to_human_readable_reprrl      s     771R4=r1   c                      e Zd ZdZdS )DecodeErrorzException raised when a file cannot be decoded due to an unknown encoding type.

    Essentially a wrapper for the LookupError raised by `bytearray.decode`
    N)__name__
__module____qualname____doc__ r1   r/   rn   rn      s           r1   rn   sourcec                    |                      d          rd}| dd         } nt          |           \  }}	 |                     |          }n/# t          $ r"}t	          t          |                    |d}~ww xY w|S )zmRead the Python file with while obeying PEP-263 encoding detection.

    Returns the source as a string.
    s   ﻿ra   r_   N)r-   rh   rd   LookupErrorrn   r'   )rt   rf   r4   source_text	lookuperrs        r/   decode_python_encodingry      s     )) 3 +622!9mmH-- 9 9 9#i..))y89s   A 
A8A33A8pathreadCallable[[str], bytes]list[str] | Nonec                    	  ||           }	 t          |                                          }n# t          $ r Y dS w xY w|S # t          $ r Y dS w xY w)zaTry reading a Python file as list of source lines.

    Return None if something goes wrong.
    N)ry   
splitlinesrn   OSError)rz   r{   rt   source_liness       r/   read_py_filer      s    
	d	1&99DDFFLL 	 	 	44	    tts   A !0 
>>
AAre   max_lenintcol	min_widthc                L   |d|z  dz   k     rd|z  dz   }t          |           |k    r| dfS ||z   |k     r| d|         dz   dfS |t          |           |z
  dz
  k     r&||z
  |z   dz   }d| |||z   dz            z   dz   |dz
  fS d| | d         z   t          |           |z
  dz
  fS )a  Trim a line of source code to fit into max_len.

    Show 'min_width' characters on each side of 'col' (an error location). If either
    start or end is trimmed, this is indicated by adding '...' there.
    A typical result looks like this:
        ...some_variable = function_to_call(one_arg, other_arg) or...

    Return the trimmed string and the column offset to adjust error location.
    r^   r;   r   N...r_   rL   )re   r   r   r   offsets        r/   trim_source_liner      s     Y"""i-!# 4yyGQw Y  HWH~%q(( SYY"Q&&&w*Q.tFS9_q%8899EA6A:MM 4		?"CII$7!$;;;r1   list[tuple[int, str]]c                    d}|| vrg S |                      d          }g }t          |          D ]I\  }}|                    |          r/|                    |dz   |t	          |          d          f           J|S )Nz# mypy: 
r;   )rV   	enumerater-   r=   rL   )rt   PREFIXlinesresultsire   s         r/   get_mypy_commentsr      s    FV	LLEGU## 9 94??6"" 	9NNAE4F#67888Nr1   z<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="{errors}" failures="{failures}" name="mypy" skips="0" tests="{tests}" time="{time:.3f}">
JUNIT_HEADER_TEMPLATEz  <testcase classname="mypy" file="{filename}" line="1" name="{name}" time="{time:.3f}">
    <failure message="mypy produced messages">{text}</failure>
  </testcase>
JUNIT_TESTCASE_FAIL_TEMPLATEz  <testcase classname="mypy" file="mypy" line="1" name="mypy-py{ver}-{platform}" time="{time:.3f}">
    <error message="mypy produced errors">{text}</error>
  </testcase>
JUNIT_ERROR_TEMPLATEzr  <testcase classname="mypy" file="mypy" line="1" name="mypy-py{ver}-{platform}" time="{time:.3f}">
  </testcase>
JUNIT_TESTCASE_PASS_TEMPLATEz</testsuite>
JUNIT_FOOTERdtfloatseriousmessages_by_filedict[str | None, list[str]]versionplatformc                v   ddl m} |rd}t          |          }nt          |          }d}t                              ||| t          |          pd          }|s!|t
                              | ||          z  }n|                                D ]\  }	}
|	T|t                               |d                    |
                    |	| d                    |||	          	          z  }[|t                               |d                    |
                    d
| d| d| 	          z  }|t          z  }|S )Nr   )escaper;   )errorsfailurestimetests)r   verr   r   z"mypy-py{ver}-{platform} {filename})r   r   filename)rZ   r   r   r&   r   zmypy-py-)
xml.sax.saxutilsr   rL   r   formatr   itemsr   rK   r   )r   r   r   r   r   r   r   r   xmlr   messagess              r/   _generate_junit_contentsr     s    (''''' %&&'((

&
&"##(q '  C  +22RZ2[[["2"8"8":": 	 	Hh#3::		( 3 344%=DD#h E  	 ;    3::		( 3 344#7777X77	 ;    <CJr1   Nonec                r   t          | ||||          }t          j                            t          j                            |                    }t          j        |d           t          |d          5 }|                    |                    d                     d d d            d S # 1 swxY w Y   d S )NT)exist_okwbutf-8)	r   osrz   dirnameabspathmakedirsopenwriteencode)	r   r   r   rz   r   r   r   xml_dirsfs	            r/   write_junit_xmlr   3  s     #2w0@'8
T
TC wrwt4455HK4((((	dD		 %Q	

7##$$$% % % % % % % % % % % % % % % % % %s   6)B,,B03B0c                  "    e Zd ZdZd
dZddZd	S )IdMapperzGenerate integer ids for objects.

    Unlike id(), these start from 0 and increment by 1, and ids won't
    get reused across the life-time of IdMapper.

    Assume objects don't redefine __eq__ or __hash__.
    r*   r   c                "    i | _         d| _        d S rE   id_mapnext_idselfs    r/   r    zIdMapper.__init__N  s    )+r1   orQ   r   c                l    || j         vr| j        | j         |<   | xj        dz  c_        | j         |         S )Nr;   r   )r   r   s     r/   idzIdMapper.idR  s8    DK!\DKNLLALL{1~r1   N)r*   r   )r   rQ   r*   r   )ro   rp   rq   rr   r    r   rs   r1   r/   r   r   E  sF                 r1   r   fullnamec                :    |                      dd          d         S )zBDrop the final component of a qualified name (e.g. ('x.y' -> 'x').r:   r;   r   )r<   )r   s    r/   
get_prefixr   Y  s    ??3""1%%r1   
cur_mod_idrelativeis_cur_package_init_filetuple[str, bool]c                    |dk    r|dfS |                      d          }|}|r|dz  }t          |          |k    }|dk    rd                    |d |                    } | |rd|z   ndz   |fS )Nr   Tr:   r;    )rV   rL   rK   )r   r   rB   r   partsreloks          r/   correct_relative_importr   ^  s     1}}t|S!!E
C q	Us	B
axxXXeEcTEl++
69#,,r:B>>r1   z$Final[dict[type[object], list[str]]]fields_cacheclstype[object]Sequence[str]c                    dd l | t          vr-                    | fd          }d |D             t          | <   t          |          S )Nr   c                X                         |           p                    |           S N)isgetsetdescriptorismemberdescriptor)r   inspects    r/   <lambda>z'get_class_descriptors.<locals>.<lambda>w  s)    755a88YG<V<VWX<Y<Y r1   c                0    g | ]\  }}|d k    |dk    |S )__weakref____dict__rs   ).0xys      r/   
<listcomp>z)get_class_descriptors.<locals>.<listcomp>y  s,    ]]]41aa=6H6HQR\__Q___r1   )r   r   
getmembers)r   membersr   s     @r/   get_class_descriptorsr   p  sc    NNN ,$$YYYY
 
 ^]7]]]Sr1   rs   newold	copy_dict
skip_slotstuple[str, ...]c           	     p   t          |d          r(|rt          |j                  | _        n|j        | _        t          |j                  D ]h}||v r	 t          ||          r t          | |t          ||                     n t          | |          rt          | |           Y# t          $ r Y ew xY wdS )a   Copy state of old node to the new node.

    This handles cases where there is __dict__ and/or attribute descriptors
    (either from slots or because the type is defined in a C extension module).

    Assume that both objects have the same __class__.
    r   N)	hasattrdictr   r   	__class__setattrgetattrdelattrAttributeError)r   r   r   r   attrs        r/   replace_object_stater   }  s     sJ ( 	(--CLL<CL%cm44  :
	sD!! #T73#5#56666d## #T"""
  	 	 	D	 s   AB&&
B32B3dirc                    |                     t          j                  s|t          j        z  }|                     |          S )ay  Given two paths, return if path is a sub-path of dir.

    Moral equivalent of: Path(dir) in Path(path).parents

    Similar to the pathlib version:
    - Treats paths case-sensitively
    - Does not fully handle unnormalised paths (e.g. paths with "..")
    - Does not handle a mix of absolute and relative paths
    Unlike the pathlib version:
    - Fast
    - On Windows, assumes input has been slash normalised
    - Handles even fewer unnormalised paths (e.g. paths with "." and "//")

    As a result, callers should ensure that inputs have had os.path.abspath called on them
    (note that os.path.abspath will normalise)
    )r.   r   sepr-   )rz   r   s     r/   is_sub_path_normabsr     s7    " << rv??3r1   linuxdarwinc                x    |                     d          s| s|S |                     d          r| |z   S | dz   |z   S )N/)r-   r.   )rz   ri   s     r/   os_path_joinr    sM    << 	"D 	"H]]3 	"!8O#:>!r1   apc                B    t           j                            | |          S r   )r   rz   rK   )r  r  s     r/   r  r    s    w||Aq!!!r1   statusc                    t           j                                         t           j                                         t	          j        |            dS )zKill the current process without fully cleaning up.

    This can be quite a bit faster than a normal exit() since objects are not freed.
    N)sysstdoutflushstderrr   _exit)r  s    r/   	hard_exitr    sB    
 JJHVr1   c                ,    |                      d          S )z+Remove internal suffixes from a short name.')rW   r5   s    r/   unmangler    s    ;;sr1   existingContainer[str]c                    | dz   }||vr|S d}|t          |          z   |v r|dz  }|t          |          z   |v |t          |          z   S )zGet a simple redefinition name not present among existing.

    For example, for name 'foo' we try 'foo-redefinition', 'foo-redefinition2',
    'foo-redefinition3', etc. until we find one that is not in existing.
    z-redefinitionr^   r;   )r'   )r&   r  r_namer   s       r/   get_unique_redefinition_namer    sh     O#FX	A
3q66/X
%
%	Q 3q66/X
%
%CFF?r1   programc                    t           j        dd         dk     r*t          j        d                    |                      dS dS )zAReport issues with the Python used to run mypy, dmypy, or stubgenNr^   )r_   r   zYRunning {name} with Python 3.9 or lower is not supported; please upgrade to 3.10 or newerr5   )r	  version_infoexitr   )r  s    r/   check_python_versionr    sU     g%%..4f'f.B.B	
 	
 	
 	
 	
 &%r1   r   tuple[int, int, int]c                    d | D             }d |D             }d | D             }t          |          t          |          t          |          fS )zDCount total number of errors, notes and error_files in message list.c                    g | ]}d |v |	S ): error:rs   r   es     r/   r   zcount_stats.<locals>.<listcomp>  s    555AZ1__a___r1   c                D    h | ]}|                     d           d         S ):r   )rV   r   s     r/   	<setcomp>zcount_stats.<locals>.<setcomp>  s&    333q1773<<?333r1   c                    g | ]}d |v |	S ): note:rs   r   s     r/   r   zcount_stats.<locals>.<listcomp>  s    3331INNQNNNr1   r   )r   r   error_filesnotess       r/   count_statsr)    s\    55555F33F333K33333Ev;;E

C$4$444r1   msgc                    d}g }d}| D ]0}|dk    r|r|                     |           d}"|dk    r| }||z  }1|                     |           |S )z=Split line of text into words (but not within quoted groups).r   Tr   ")r=   )r*  	next_wordresallow_breakcs        r/   split_wordsr1    sy    ICK  888JJy!!!I88)/KQ		JJyJr1   c                     t          t          j        dd                    pt          j                    j        pt          S )zIGet current terminal width if possible, otherwise return the default one.MYPY_FORCE_TERMINAL_WIDTH0)r   r   getenvshutilget_terminal_sizecolumnsr   rs   r1   r/   get_terminal_widthr9    s=     	BI137788 	#%%-	r1   first_offset
num_indentc                   t          |           }|                    d          }g }|ri|                    d          }|r||z
  n||z
  }t          |          t          |          z   dz   |k    r	|d|z   z  }n|                    |           |}|i|                    |           dd|z  z   }	|	                    |          S )a  Wrap a long error message into few lines.

    Breaks will only happen between words, and never inside a quoted group
    (to avoid breaking types such as "Union[int, str]"). The 'first_offset' is
    the width before the start of first line.

    Pad every next line with 'num_indent' spaces. Every line will be at most 'max_len'
    characters, except if it is a single word or quoted group.

    For example:
               first_offset
        ------------------------
        path/to/file: error: 58: Some very long error message
            that needs to be split in separate lines.
            "Long[Type, Names]" are never split.
        ^^^^--------------------------------------------------
        num_indent           max_len
    r   r;   r   r   )r1  poprL   r=   rK   )
r*  r   r:  r;  words	next_liner   r-  max_line_lenpaddings
             r/   	soft_wraprB    s    & E		!IE
 "IIaLL	/4Pw++'L:Py>>C	NN*Q.,>>y(IILL###!I  " 
LLS:%%G<<r1   datac                N    t          j        |                                           S )zCompute a hash digest of some data.

    We use a cryptographic hash because we want a low probability of
    accidental collision, but we don't really care about any of the
    cryptographic properties.
    )hashlibsha1	hexdigestrC  s    r/   hash_digestrI  3  s      <'')))r1   c                N    t          j        |                                           S )zZCompute a hash digest of some data.

    Similar to above but returns a bytes object.
    )rE  rF  digestrH  s    r/   hash_digest_bytesrL  =  s     
 <$$&&&r1   cupc                   t           j        dk    s
J d            d                    | dd                                         dg          }t	          j        |                    d          dd	                                          }|S )
z.Reproduce a gray color in ANSI escape sequencewin32z"curses is not available on Windowsr   NrT   mr   r;   	   )r	  r   rK   rd   cursestparmr   )rM  	set_colorgrays      r/   parse_gray_colorrV  E  sx    <7"""$H"""SbS**C011I<	((111a88??AADKr1   c                     t          j        dt          j        dd                    } 	 t          t          |                     S # t          $ r t          |           cY S w xY w)NMYPY_FORCE_COLORFORCE_COLORr4  )r   r5  r)   r   
ValueError)env_vars    r/   should_force_colorr\  M  sf    i*BImS,I,IJJGCLL!!!   G}}s   A A"!A"c                      e Zd ZdZ	 d/d0dZd1dZd1dZd1dZ	 	 	 d2d3dZd4dZ		 d5d6dZ
d7d Zd8d"Zd9d$Zd:d;d)Zdd%d*d<d.ZdS )=FancyFormatterzcApply color and bold font to terminal output.

    This currently only works on Linux and Mac.
    Ff_outIO[str]f_errhide_error_codesr)   hide_successr*   r   c                   || _         || _        t          j        dvr	d| _        d S t                      s1|                                r|                                s	d| _        d S t          j        dk    r|                                  | _        nEt          j        dk    r|                                  | _        n| 	                                 | _        | j        s#| j
        | j        | j        | j        dd| _        d S d S )N)r   r   rO  
emscriptenTrO  re  r   )redgreenblueyellownone)rb  rc  r	  r   
dummy_termr\  isattyinitialize_win_colorsinitialize_vt100_colorsinitialize_unix_colorsREDGREENBLUEYELLOWcolors)r   r_  ra  rb  rc  s        r/   r    zFancyFormatter.__init__[  s    !1( <III"DOF!## 	U\\^^ 	5<<>> 	"DOF<7"""&"<"<">">>DOO\\))"&">">"@"@@DOO"&"="="?"??DO 	x	+ DKKK	 	r1   c                    t           j        dv sJ d| _        d| _        d| _        d| _        d| _        d| _        d| _        d	| _	        d
S )SReturn True if initialization was successful and we can use colors, False otherwise)rO  re  z[1mz[4mz[94mz[92mz[91mz[93mz[0mz[2mT)
r	  r   BOLDUNDERrr  rq  rp  rs  NORMALDIMr   s    r/   rn  z&FancyFormatter.initialize_vt100_colorsw  sU     |66666	
	
 tr1   c                Z   t           j        dk    rt          j                    }|j        t          k     s|j        t          k     rdS ddl}|j        j	        }d}d}d}d}|
                    |                    |          ||z  |z             |                                  d	S J d
            )rv  rO  Fr   Nr;   r^   r   iTzRunning not on Windows)r	  r   getwindowsversionmajorr   buildr   ctypeswindllkernel32SetConsoleModeGetStdHandlern  )r   winverr  r  ENABLE_PROCESSED_OUTPUTENABLE_WRAP_AT_EOL_OUTPUT"ENABLE_VIRTUAL_TERMINAL_PROCESSINGSTD_OUTPUT_HANDLEs           r/   rm  z$FancyFormatter.initialize_win_colors  s    
 <7""*,,F:::<"===uMMM}-H&)#(+%14. ###%%&788'+,45   ((***4.....r1   c                   t           j        dk    }|st          sdS 	 	 t           j                                        }t          j        |           nd# t          j        $ rR t          dd          5 }t          j        |                                           ddd           n# 1 swxY w Y   Y nw xY wn# t
          j
        $ r Y dS w xY wt          j        d          }t          j        d          }t          j        d	          }t          j        d
          }t          j        d          }|r|r|r|r|sdS |                                | _        |                                | _        |                                | _        t!          |          | _        t          j        |t
          j                                                  | _        t          j        |t
          j                                                  | _        t          j        |t
          j                                                  | _        t          j        |t
          j                                                  | _        dS )rv  rO  F)fdz	/dev/nullrbNboldsmulsetafrM  sgr0T)r	  r   CURSES_ENABLEDr
  filenorR  	setuptermioUnsupportedOperationr   errortigetstrrd   ry  rw  rx  rV  rz  rS  
COLOR_BLUErr  COLOR_GREENrq  	COLOR_REDrp  COLOR_YELLOWrs  )	r   is_winr  r   r  underrT  set_eseqnormals	            r/   ro  z%FancyFormatter.initialize_unix_colors  s^   ( 	 	5	(Z&&((
  B'''''	 * 4 4 4+t,, 4$

33334 4 4 4 4 4 4 4 4 4 4 4 4 4 44
 | 	 	 	55	 v&&''OG,,	?5))(( 	 	9 	 	f 	5mmooKKMM	\\^^
#H--LF,=>>EEGG	\)V-?@@GGII
<	6+;<<CCEEl9f.ABBIIKKtsR   A B7 B31(B%B3%B)	)B3,B)	-B30B7 2B33B7 7C
	C
rZ   r'   color1Literal['red', 'green', 'blue', 'yellow', 'none']r  	underlinedimc                    | j         r|S |r| j        }nd}|r
|| j        z  }|r
|| j        z  }|| j        |         z   |z   | j        z   S )z2Apply simple color and style (underlined or bold).r   )rk  rw  rx  rz  rt  ry  )r   rZ   r  r  r  r  starts          r/   stylezFancyFormatter.style  so     ? 	K 	IEEE 	 TZE 	TXEt{5))D04;>>r1   re   c                    |                                 }|                    t                    o8|                    d          o#t          |                              ddh          S )N^~)lstripr-   r   setissubset)r   re   s_lines      r/   is_marker_linezFancyFormatter.is_marker_line  sY    OOJ'' 1!!#&&1F$$c3Z00	
r1   Nr   r8   fixed_terminal_width
int | Nonec           	        |pt                      }|                                }t          |          D ]\  }}|                    t                    sYd|v rU|                    dd          \  }}t          ||t          |          t          d          z             }|dz   |z   ||<   y|                    t                    r$|                     |          s|t          d         }||dz            }	|	
                    d          }
|
t          z
  }d	|	vrd}n |	|
|	                    d	          dz            }|t          z
  d
z
  }t          |||t                    \  }}dt          z  |z   ||<   dt          |z   |z
  z  |z   }t          |          t          ||                   k    r6t          |          dk    r#|dt          ||                   dz
           dz   }|||dz   <   |S )zHImprove readability by wrapping error messages and trimming source code.r  error:r;   maxsplitzerror: )r:  Nr  r     r   r_   r   )r9  copyr   r-   r   rV   rB  rL   r  r   indexrindexr   r   )r   r   r  widthnew_messagesr   r  locr*  marker_linemarker_columncolumnmarkerr   source_liner   new_marker_lines                    r/   fit_in_terminalzFancyFormatter.fit_in_terminal  s    %<(:(<(<}}!(++ 	6 	6HAu##J// 6J%4G4G ;;x!;<<SUSC	NN9RSSS"%.3"6Q!!*-- 6d6I6I%6P6P 63445&q1uo + 1 1# 6 6&)>>k)) FF )9K9KC9P9PST9T)TUF  "77!;&6ugv}&]&]#V"%(="="KQ"%)>)G&)P"QTZ"Z''#l1o*>*>>>3v;;QR??&56PLO8L8Lq8P6P&QTY&YO&5QU#r1   r  c                $   |                     t                    rC|                     |          s|                     |dd          S |                     |d          S d|v r|                    dd          \  }}| j        r1||                     ddd	          z   |                     |          z   S |                    d
          }|dk    r||d         }|d|         }nd}||                     ddd	          z   |                     |          z   |                     |d          z   S d|v r^|                    dd          \  }}|                     |                     |                    }||                     dd          z   |z   S |S )zBColorize an output line by highlighting the status and error code.rj  T)r  rf  r  r  r;   r  r  [rT   Nr   ri  r&  znote:rh  )	r-   r   r  r  rV   rb  highlight_quote_groupsrfindunderline_link)r   r  r  r*  codeposcode	formatteds          r/   colorizezFancyFormatter.colorize
  s    J'' 	&&u-- ;zz%Tz:::::eU+++5  {{8a{88HC$ $**Xu4*@@@4C^C^_bCcCcc iinnG"}}788}(7(m**Xu4*889--c223 **T8,,- %{{7Q{77HC33D4G4G4L4LMMIGV444y@@Lr1   r*  c                   |                     d          dz  r|S |                    d          }d}t          |          D ]I\  }}|dz  dk    r||                     |d          z  }(||                     d|z   dz   dd          z  }J|S )zMake groups quoted with double quotes bold (including quotes).

        This is used to highlight types, attribute names etc.
        r,  r^   r   r   rj  Tr  )countrV   r   r  )r   r*  r   r>   r   parts         r/   r  z%FancyFormatter.highlight_quote_groups*  s    
 99S>>A 	J		# '' 	G 	GGAt1uzztzz$///tzz#*s"2FzFFF
r1   notec                    t          j        d|          }|s|S |                                }|                                }|d|         |                     |||         dd          z   ||d         z   S )zuUnderline a link in a note message (if any).

        This assumes there is at most one link in the message.
        zhttps?://\S*Nrj  T)r  )researchr  endr  )r   r  rb   r  r  s        r/   r  zFancyFormatter.underline_link;  s{    
 	/400 	KiikkFUF|djjeCi&DjQQQTXY\Y]Y]T^^^r1   T	n_sourcesr   	use_colorc                v    | j         rdS d| dt          |           }|s|S |                     |dd          S )zFormat short summary in case of success.

        n_sources is total number of files passed directly on command line,
        i.e. excluding stubs and followed imports.
        r   zSuccess: no issues found in  source filerg  Tr  )rc  plural_sr  )r   r  r  r*  s       r/   format_successzFancyFormatter.format_successG  sV      	2YYYYHYDWDWYY 	Jzz#wTz222r1   )blockersr  n_errorsn_filesr  c          
         d| dt          |           d| dt          |           }|r|dz  }n|d| dt          |           dz  }|s|S |                     |d	d
          S )z)Format a short summary in case of errors.zFound z errorz in z filez$ (errors prevented further checking)z
 (checked r  )rf  Tr  )r  r  )r   r  r  r  r  r  r*  s          r/   format_errorzFancyFormatter.format_errorU  s     ax``x'9'9``w``XV]M^M^`` 	N99CCM	MMx	7J7JMMMMC 	Jzz#u4z000r1   F)
r_  r`  ra  r`  rb  r)   rc  r)   r*   r   r*   r)   )FFF)rZ   r'   r  r  r  r)   r  r)   r  r)   r*   r'   )re   r'   r*   r)   r   )r   r8   r  r  r*   r8   )r  r'   r*   r'   )r*  r'   r*   r'   )r  r'   r*   r'   )T)r  r   r  r)   r*   r'   )r  r   r  r   r  r   r  r)   r  r)   r*   r'   )ro   rp   rq   rr   r    rn  rm  ro  r  r  r  r  r  r  r  r  rs   r1   r/   r^  r^  U  sT         \a    8   / / / /:$ $ $ $T ? ? ? ? ?*
 
 
 
 GK# # # # #J   @   "
_ 
_ 
_ 
_3 3 3 3 3( 1 1 1 1 1 1 1 1r1   r^  typeshed_dirfilec                    | | nt           } 	 t          j                            | t          j                            |          f          | k    S # t
          $ r Y dS w xY w)NF)r   r   rz   
commonpathr   rZ  )r  r  s     r/   is_typeshed_filer  i  se    #/#;<<Lw!!<1F1F"GHHLXX   uus   AA 
AAc                   d|vrdS | | nt           } t          j                            | d          }	 t          j                            |t          j                            |          f          |k    S # t          $ r Y dS w xY w)NstdlibF)r   r   rz   rK   r  r   rZ  )r  r  
stdlib_dirs      r/   is_stdlib_filer  q  s    tu#/#;<<LlH55Jw!!:rwt/D/D"EFF*TT   uus   AA5 5
BBc                    |                      d          sdS t          d t          j                            t          j                            |                     D                       S )Nz.pyiFc              3  @   K   | ]}|                     d           V  dS )z-stubsN)r.   )r   	components     r/   	<genexpr>z'is_stub_package_file.<locals>.<genexpr>  s0      bb	y!!(++bbbbbbr1   )r.   anyr   rz   rV   r   )r  s    r/   is_stub_package_filer  }  sU    ==   ubbRW]]27??[_K`K`=a=abbbbbbr1   c                    | d uo| dk    S r3   rs   r5   s    r/   unnamed_functionr    s    t++r1   t0c                N    t          t          j                    | z
  dz            S )Ni  )r   r   perf_counter_ns)r  s    r/   time_spent_usr    s#    $&&+t3444r1   sint | Sizedc                b    t          | t                    r| nt          |           }|dk    rdS dS )Nr;   r  r   )
isinstancer   rL   )r  r  s     r/   r  r    s3    As##/AAQEzzsrr1   docstrc                    d                     t          j        dt          |                               }|                    d          r,d|dd         vr|d         dk    rd|dd          dS d	| d	S d
| d
S )zKReturns docstring correctly encapsulated in a single or double quoted form.r   z(?<=[^\\])\\nr  r,  r;   rT   z"""z''z"")rK   r  rV   rk   r-   )r  docstr_reprs     r/   quote_docstringr    s     ))BH%5tF||DDEEKc"" $ k!B$'''KOs,B,B/QrT*////#K#####K####r1   debugc                   t           j|rt           j        t           j        z  }nt           j        }	 t          j        | |          S # t          $ r}t          |          dk    r Y d }~nd }~ww xY w|r*t          j        | dd                              d          S t          j        | dd                              d          S )	N)optionzInteger exceeds 64-bit ranger^   T)indent	sort_keysr   ),r#  )r  
separators)r   OPT_INDENT_2OPT_SORT_KEYSdumps	TypeErrorr'   jsonr   )rP   r   dumps_optionr!  s       r/   
json_dumpsr    s     	0!.1EELL "/L	<L9999 	 	 	1vv777 87777	  Vz#a4888??HHH z#*EEELLWUUUs   A 
A/A**A/c                `    t           t          j        |           S t          j        |           S r   )r   loadsr  rH  s    r/   
json_loadsr    s(    |D!!!:dr1   r  )r&   r'   r(   r)   r*   r)   )r&   r'   r*   r)   )r7   r'   r*   r8   )r@   rA   rB   r'   r*   rC   )r@   rA   rB   r'   r*   rI   )rP   rQ   r*   r'   )rZ   r[   r*   r\   )ri   r[   r*   r'   )rt   r[   r*   r'   )rz   r'   r{   r|   r*   r}   )
re   r'   r   r   r   r   r   r   r*   r\   )rt   r'   r*   r   )r   r   r   r)   r   r   r   r'   r   r'   r*   r'   )r   r   r   r)   r   r   rz   r'   r   r'   r   r'   r*   r   )r   r'   r*   r'   )
r   r'   r   r   rB   r'   r   r)   r*   r   )r   r   r*   r   )Frs   )
r   rQ   r   rQ   r   r)   r   r   r*   r   )rz   r'   r   r'   r*   r)   )rz   r'   ri   r'   r*   r'   )r  r'   r  r'   r*   r'   )r   )r  r   r*   r   )r&   r'   r*   r'   )r&   r'   r  r  r*   r'   )r  r'   r*   r   )r   r8   r*   r  )r*  r'   r*   r8   )r*   r   )
r*  r'   r   r   r:  r   r;  r   r*   r'   )rC  r[   r*   r'   )rC  r[   r*   r[   )rM  r[   r*   r'   r  )r  rC   r  r'   r*   r)   )r  r'   r*   r)   )r&   rC   r*   r)   )r  r   r*   r   )r  r  r*   r'   )r  r'   r*   r'   )rP   rQ   r   r)   r*   r[   )rC  r[   r*   r   )drr   
__future__r   rE  r  r  r   r  r6  r	  r   collections.abcr   r   r   r   r   	importlibr	   importlib_resourcestypingr
   r   r   r   r   __annotations__r   ImportError_cursesrR  r  r   r'   filesr   compiler   r   r   r   r   r   r   	frozensetr%   r0   r6   r?   rH   rF   rY   rh   rl   	Exceptionrn   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r)  r1  r9  rB  rI  rL  rV  r\  r^  r  r  r  r  r  time_refr  r  r  r  r  rs   r1   r/   <module>r     s   9 9 9 " " " " " "  				  				 				  



  J J J J J J J J J J J J J J 6 6 6 6 6 6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 MMMM   FFFNNNMMMNN   NNN GCLLc3-3F;;jHII I I I IRZ abb b b b b          //
 / / / /          &(  ' ' ' '%*  * * * *"Q     
	9 	9 	9 	9 	9_ _ _ _
 
 
 
   	+ 	+ 	+ 	+) ) ) )$ $ $ $       )      (   "< < < <@         '     
     
'         / / / /d% % % %$       (& & & &
? ? ? ? 68 7 7 7 7
 
 
 
 VX    @       , <7clh66" " " " "" " " "       
    
 
 
 
5 5 5 5   "   ! ! ! ! !H* * * *' ' ' '      Q1 Q1 Q1 Q1 Q1 Q1 Q1 Q1h   	 	 	 	c c c c, , , , 5 5 5 5   $ $ $ $"V V V V V,     s$   A A! A!%
A0 0A:9A: