
    X-Phza                       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 ddlmZmZmZ ddlmZmZ ddlmZmZmZ ddlmZmZ dd	lmZ dd
lmZmZm Z  ddl!m"Z"  G d dej#                  Z$ ej%        ddd          Z&ej'        dk    rde&_(        e&)                    d           e&*                    ded           e&*                    dddde"z   d           e&+                                Z,e,-                    dd           xZ.Z/e/*                    d!d"e0d#$           e/*                    d%d&e1d'$           e/*                    d(d)d*e0d+,           e,-                    d-d.           xZ2Z/e/*                    d!d"e0d#$           e/*                    d%d&e1d'$           e/*                    d(d)d*e0d+,           e,-                    d/d0           xZ3Z/e/*                    d1d2d3d45           e/*                    d6d7            e,-                    d8d9           xZ4Z/e,-                    d:d;           xZ5Z/e,-                    d<e$d=>          xZ6Z/e/*                    d1d2d3d45           e/*                    d?d@d3ej7        5           e/*                    dAdB            e/*                    dCdD            e/*                    dEd"dFdGH           e/*                    dId3dJ5           e,-                    dKe$dL>          xZ8Z/e/*                    d1d2d3d45           e/*                    dAdB            e/*                    dCdD            e/*                    d%d&e1d'$           e/*                    d!d"e0d#$           e/*                    dId3dJ5           e/*                    d(dMd*e0dN,           e,-                    dOe$dP>          xZ9Z/e/*                    d1d2d3d45           e/*                    d?d@d3ej7        5           e/*                    dAdB            e/*                    dCdD            e/*                    dId3dJ5           e/*                    dQd"d*dRH           e/*                    dSd"d*dTH           e,-                    dUdV           xZ:Z/e/*                    dWdXe0dY$           e/*                    dZd3d[5           e/*                    d\d3d]5           e/*                    d^d3d_5           e/*                    d`e;dab           e/*                    dcd3dd5           e/*                    dedfe0dg$           e/*                    dhe1dib           e,-                    djdk           xZ<Z/e/*                    dldme0dn$           e/*                    dodpe0dqg drdst           e/*                    d2d1duddvw           e/*                    dxdye1ddz{           e/*                    d|d3d}5           e/*                    d~d3d5           e/*                    dd3d5           e/*                    dd3d5           e/*                    dd3d5           e,-                    dd           xZ=Z/e,-                    dd           xZ>Z/e/*                    d%d&e1d'$           e/*                    d!d"e0d#$           e/*                    d(d)d*e0d+,           e/*                    dej7                    e,-                    d          xZ?Z/[/ G d de@          ZAddZBddZCeejD        gdf         ZEddZF eFe.          dd            ZG eFe2          dd            ZHdddZIdddZJdddZK eFe8          dd            ZL eFe3          dd            ZM eFe4          dd            ZN eFe5          dd            ZO eFe6          dd            ZP eFe9          dd            ZQ eFe:          dd            ZR eFe<          dd            ZSddZTddZU eFe=          dd            ZV eFe>          dd            ZW eFe?          dd            ZXddddZYddĄZZddƄZ[ddȄZ\ddɄZ]ddʄZ^dS )zClient for mypy daemon mode.

This manages a daemon process which keeps useful state in memory
rather than having to read it back from disk on each run.
    )annotationsN)Mapping)AnyCallableNoReturn)alivekill)DEFAULT_STATUS_FILEreceivesend)	IPCClientIPCException)RECURSION_LIMIT)check_python_versionget_terminal_widthshould_force_color)__version__c                        e Zd Zd fdZ xZS )	AugmentedHelpFormatterprogstrkwargsr   returnNonec                @     t                      j        d|dd| d S )N   )r   max_help_position )super__init__)selfr   r   	__class__s      Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/dmypy/client.pyr    zAugmentedHelpFormatter.__init__    s-    CdbCCFCCCCC    )r   r   r   r   r   r   )__name__
__module____qualname__r    __classcell__)r"   s   @r#   r   r      sG        D D D D D D D D D Dr$   r   dmypyzClient for mypy daemon mode@)r   descriptionfromfile_prefix_chars)      Tactionz--status-filez&status file to retrieve daemon details)defaulthelpz-Vz	--versionversionz	%(prog)s z&Show program's version number and exit)r0   r3   r2   startzStart daemon)r2   z
--log-fileFILEz#Direct daemon stdout/stderr to FILE)metavartyper2   z	--timeoutTIMEOUTz$Server shutdown timeout (in seconds)flagsFLAG*z$Regular mypy flags (precede with --))r6   nargsr7   r2   restartz/Restart daemon (stop or kill followed by start)statuszShow daemon statusz-vz	--verbose
store_truezPrint detailed status)r0   r2   z--fswatcher-dump-filez0Collect information about the current file statestopz)Stop daemon (asks it politely to go away)r	   zKill daemon (kills the process)checkz"Check some files (requires daemon))formatter_classr2   z-qz--quietz--junit-xmlz!Write junit.xml to the given filez--perf-stats-filez/write performance information to the given filefiles+zFile (or directory) to check)r6   r<   r2   z--export-typeszLStore types of all expressions in a shared location (useful for inspections)runz2Check some files, [re]starting daemon if necessaryARGz.Regular mypy flags and files (precede with --)recheckzRRe-check the previous list of files, with optional modifications (requires daemon)z--updatezGFiles in the run to add or check again (default: all from previous run)z--removezFiles to remove from the runsuggestz>Suggest a signature or show call sites for a specific functionfunctionFUNCTIONz9Function specified as '[package.]module.[class.]function'z--jsonz:Produce json that pyannotate can use to apply a suggestionz--no-errorsz-Only produce suggestions that cause no errorsz--no-anyz/Only produce suggestions that don't contain Anyz
--flex-anyzJAllow anys in types if they go above a certain score (scores are from 0-1))r7   r2   z--callsitesz+Find callsites instead of suggesting a typez--use-fixmeNAMEzCA dummy name to use instead of Any for types that can't be inferredz--max-guesseszBSet the maximum number of types to try for a function (default 64)inspectz+Locate and statically inspect expression(s)locationLOCATIONzLocation specified as path/to/file.py:line:column[:end_line:end_column]. If position is given (i.e. only line and column), this will return all enclosing expressionsz--show
INSPECTIONr7   )r7   attrs
definitionzWhat kind of inspection to run)r6   r7   r1   choicesr2   countzFIncrease verbosity of the type string representation (can be repeated))r0   r1   r2   z--limitNUMzQReturn at most NUM innermost expressions (if position is given); 0 means no limit)r6   r7   r1   r2   z--include-spanz]Prepend each inspection result with the span of corresponding expression (e.g. 1:2:3:4:"int")z--include-kindz^Prepend each inspection result with the kind of corresponding expression (e.g. NameExpr:"int")z--include-object-attrsz4Include attributes of "object" in "attrs" inspectionz--union-attrszgInclude attributes valid for some of possible expression types (by default an intersection is returned)z--force-reloadz?Re-parse and re-type-check file before inspection (may be slow)hangzHang for 100 secondsdaemonzRun daemon in foregroundz--options-datar2   c                      e Zd ZdZdS )	BadStatuszException raised when there is something wrong with the status file.

    For example:
    - No status file found
    - Status file malformed
    - Process whose pid is in the status file does not exist
    N)r%   r&   r'   __doc__r   r$   r#   rX   rX     s           r$   rX   argv	list[str]r   r   c                   t          d           t          j        t                     t                              |           }|j        st                                           dS 	 |                    |           dS # t          $ r%}t          |j
        d                    Y d}~dS d}~wt          $ r+ t          j                     t          j        d           Y dS w xY w)zThe code is top-down.r)   r   N   )r   syssetrecursionlimitr   parser
parse_argsr0   print_usagerX   failargs	Exception	traceback	print_excexit)rZ   rd   errs      r#   mainrj     s    !!! /***T""D; 	KK 	 	 	! 	 	 	 !!!HQKKKKKK		s   &A= =
CB''4CCmsgr   r   c                d    t          | t          j                   t          j        d           d S )N)filer]   )printr^   stderrrh   )rk   s    r#   rc   rc   &  s(    	#CJHQKKKKKr$   	subparserargparse.ArgumentParser*Callable[[ActionFunction], ActionFunction]c                     d fd}|S )z3Decorator to tie an action function to a subparser.funcActionFunctionr   c                4                         |            | S )Nr/   )set_defaults)rt   rp   s    r#   registerzaction.<locals>.register1  s    d+++r$   )rt   ru   r   ru   r   )rp   rx   s   ` r#   r0   r0   .  s(          Or$   rd   argparse.Namespacec                    	 t          | j                   t          d           n# t          $ r Y nw xY wt	          |            dS )a  Start daemon (it must not already be running).

    This is where mypy flags are set from the command line.

    Setting flags is a bit awkward; you have to use e.g.:

      dmypy start -- --strict

    since we don't want to duplicate mypy's huge list of flags.
    zDaemon is still aliveN)
get_statusstatus_filerc   rX   start_serverrd   s    r#   do_startr   ;  sd    &4#$$$
 	$%%%%	    
 s   & 
33c                $    t          |            dS )zRestart daemon (it may or may not be running; but not hanging).

    We first try to stop it politely if it's running.  This also sets
    mypy flags from the command line (see do_start()).
    N)restart_serverr~   s    r#   
do_restartr   Q  s     4r$   Fallow_sourcesboolc                h    	 t          |            n# t          $ r Y nw xY wt          | |           dS )z?Restart daemon (it may or may not be running; but not hanging).N)do_stoprX   r}   )rd   r   s     r#   r   r   [  sL        }%%%%%s    
c                    ddl m}m}  || j        |          } ||| j        | j        | j                  rt          j        d           t          | j                   dS )z8Start the server from command arguments and wait for it.r   )	daemonizeprocess_start_options)timeoutlog_filer]   N)
mypy.dmypy_serverr   r   r9   r|   r   r   r^   rh   wait_for_server)rd   r   r   r   start_optionss        r#   r}   r}   e  sy     CBBBBBBB))$*mDDMy 0$,QUQ^___ D$%%%%%r$         @r|   r   floatc                (   t          j                     |z   }t          j                     |k     rU	 t          |           }n$# t          $ r t          j        d           Y Hw xY wt	          |           t          d           dS t          d           dS )zTWait until the server is up.

    Exit if it doesn't happen within the timeout.
    g?zDaemon startedNz%Timed out waiting for daemon to start)timeread_statusrX   sleepcheck_statusrn   rc   )r|   r   endtimedatas       r#   r   r   p  s    
 ikkG#G
)++

	{++DD 	 	 	JsOOOH	
 	T	011111s   ? A A c                   t          | j                  st          | d           t          j                    }t	          | j        dt
          | j        | j                  }d|v rQt          d|d                     t          | d           t	          | j        dt
          | j        | j                  }t          j                    }||z
  |d<   t          || j        | j        | j                   dS )	a  Do a check, starting (or restarting) the daemon as necessary

    Restarts the daemon if the running daemon reports that it is
    required (due to a configuration change, for example).

    Setting flags is a bit awkward; you have to use e.g.:

      dmypy run -- --strict a.py b.py ...

    since we don't want to duplicate mypy's huge list of flags.
    (The -- is only necessary if flags are specified.)
    Tr   rE   )r3   rd   export_typesr=   zRestarting: roundtrip_timeN)
is_runningr|   r}   r   requestr   r9   r   rn   r   check_outputverbose	junit_xmlperf_stats_filerd   t0responset1s       r#   do_runr     s    d&'' /T....	BZ&  H H2Xi022333t40000*
 
 
 
B!#bH4<9MNNNNNr$   c                R   t          | j                  }| j        rt          |           t	          |           t          | j        d| j        d          }| j        sd|v rt          |           d|v r#t          dt          j	        d          d           t          d           d	S )
zOPrint daemon status.

    This verifies that it is responsive to requests.
    r>      )fswatcher_dump_filer   error:Daemon may be busy processing; if this persists, consider r    killzDaemon is up and runningN)r   r|   r   
show_statsr   r   r   rc   r^   rZ   rn   )rd   r>   r   s      r#   	do_statusr     s     )**F| 6 (8PZ[  H | w(**8(\#(ST+\\\]]]	
$%%%%%r$   c                    t          | j        dd          }d|v r4t          |           t          dt          j        d          d           d	S t          d           d	S )
z!Stop daemon via a 'stop' request.r@   r   r   r   r   r   r   zDaemon stoppedN)r   r|   r   rc   r^   rZ   rn   rd   r   s     r#   r   r     sp     t';;;H(8\#(ST+\\\]]]]]r$   c                    t          | j                  \  }}	 t          |           t          d           dS # t          $ r'}t          t          |                     Y d}~dS d}~ww xY w)z!Kill daemon process with SIGKILL.zDaemon killedN)r{   r|   r	   rn   OSErrorrc   r   )rd   pid_ri   s       r#   do_killr     s|     ())FCS			 	o    SXXs   9 
A*A%%A*c                    t          j                     }t          | j        d| j        | j                  }t          j                     }||z
  |d<   t          || j        | j        | j                   dS )z(Ask the daemon to check a list of files.rA   )rC   r   r   N)	r   r   r|   rC   r   r   r   r   r   r   s       r#   do_checkr     si     
Bt'
QUQbcccH	B!#bH4<9MNNNNNr$   c                J   t          j                     }| j        | j        )t          | j        d| j        | j        | j                  }nt          | j        d| j                  }t          j                     }||z
  |d<   t          || j        | j        | j	                   dS )a  Ask the daemon to recheck the previous list of files, with optional modifications.

    If at least one of --remove or --update is given, the server will
    update the list of files to check accordingly and assume that any other files
    are unchanged.  If none of these flags are given, the server will call stat()
    on each file last checked to determine its status.

    Files given in --update ought to exist.  Files given in --remove need not exist;
    if they don't they will be ignored.
    The lists may be empty but oughtn't contain duplicates or overlap.

    NOTE: The list of files is lost when the daemon is restarted.
    NrG   )r   removeupdate)r   r   )
r   r   r   r   r|   r   r   r   r   r   r   s       r#   
do_recheckr     s     
B{$+"9*;;
 
 
 4+YTEVWWW	B!#bH4<9MNNNNNr$   c                    t          | j        d| j        | j        | j        | j        | j        | j        | j        | j	        
  
        }t          |ddd           dS )zAsk the daemon for a suggested signature.

    This just prints whatever the daemon reports as output.
    For now it may be closer to a list of call sites.
    rH   )rI   json	callsites	no_errorsno_anyflex_any	use_fixmemax_guessesFNr   r   r   )r   r|   rI   r   r   r   r   r   r   r   r   r   s     r#   
do_suggestr     si     Y..{.$  H 5D$OOOOOOr$   c                    t          | j        d| j        | j        | j        | j        | j        | j        | j        | j	        | j
                  }t          |ddd           dS )z.Ask daemon to print the type of an expression.rL   )	showrM   	verbositylimitinclude_spaninclude_kindinclude_object_attrsunion_attrsforce_reloadFNr   )r   r|   r   rM   r   r   r   r   r   r   r   r   r   s     r#   
do_inspectr     sr     Y,j&&!6$&  H 5D$OOOOOOr$   r   dict[str, Any]r   r   
str | Noner   c           	     b   d| v rt          | d                    	 | d         | d         | d         }}}n/# t          $ r" t          dt          |                       Y nw xY wt          j                            |           t          j                                         t          j                            |           t          j                                         |rt          |            |rRddl	m
} ||z                                   } || d         t          |          |rd	|ini || d
         | d                    |rS|                     di           }	t          |d          5 }
t          j        |	|
           d	d	d	           n# 1 swxY w Y   |rt          j        |           d	S d	S )zkPrint the output from a check or recheck command.

    Call sys.exit() unless the status code is zero.
    r   outri   r>   z
Response: r   )write_junit_xmlr   Npython_versionplatformstatsw)rc   KeyErrorr   r^   stdoutwriteflushro   r   	mypy.utilr   
splitlinesr   getopenr   dumprh   )r   r   r   r   r   ri   status_coder   messages	telemetryfs              r#   r   r   .  s!    (Xg+ (%(8BT+S + + +)#h--))*****+JSJJSJ 8 
------#I))++%&II (0T8b%&Z 	
 	
 	
  $LL"--	/3'' 	$1Ii###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$   s!   4 )A A *FFFMapping[str, object]c           	     |   t          |                                           D ]\  }}|dv r`t          |          dd         }t          |          dk    r |d d          dt          |          dz
   d}t	          |dd	|           it	          |dd	t          |t                    rd
|z  n|d           d S )N)r   ri   r   ro      2   (   z ... z more characters24z: z%.3fz>10)sorteditemsreprlenrn   
isinstancer   )r   keyvalues      r#   r   r   W  s    X^^--.. \ \
U444KK"%E5zzB ":KKCJJrMKKKee,---ssssj6N6N$YFUNNTY$YZ[[[[\ \r$   c                N    t          t          | j        dd                     dS )z&Hang for 100 seconds, as a debug hack.rU   r   r   N)rn   r   r|   r~   s    r#   do_hangr   c  s*     
'$"FA
6
6
677777r$   c                6   ddl m}m} | j        rut	          | j        dd          xt
          _        t
          _        t
          j                                        }t          j
        |d           t          j
        |d           | j        rQddlm} t          j        t!          j        | j                            } |            }|                    |          }n || j        d	          } ||| j        | j        
                                           dS )z!Serve requests in the foreground.r   )Serverr   ar   )	bufferingr]   )OptionsFr   r   N)r   r   r   r   r   r^   r   ro   filenoosdup2options_datamypy.optionsr   pickleloadsbase64	b64decodeapply_changesr9   r|   r   serve)rd   r   r   fdr   options_dictoptions_objoptionss           r#   	do_daemonr  i  s    @???????} "&t}cQ"G"G"GG
SZZ  
A
A I((((((|F$4T5F$G$GHHgii++L99''
%HHH
F7D$dl;;;AACCCCCr$   c                8    t                                            dS )z'Print full help (same as dmypy --help).N)r`   
print_helpr~   s    r#   do_helpr    s     r$   r   command
int | Nonekwdsobjectc                  i }t          |          }||d<   t          j                                        pt	                      |d<   t                      |d<   t          |           \  }}	 t          ||          5 }t          ||           d}	|	st          |          }t          |                    dd                    }	|                    dd          }
|
rt          j                            |
           |                    dd          }|rt          j                            |           |	ddd           n# 1 swxY w Y   n/# t          t          f$ r}d	t!          |          icY d}~S d}~ww xY w|S )
a  Send a request to the daemon.

    Return the JSON dict with the response.

    Raise BadStatus if there is something wrong with the status file
    or if the process whose pid is in the status file has died.

    Return {'error': <message>} if an IPC operation or receive()
    raised OSError.  This covers cases such as connection refused or
    closed prematurely as well as invalid JSON received.
    r  is_ttyterminal_widthFfinalr   Nro   r   )dictr^   r   isattyr   r   r{   r   r   r   r   popr   ro   r   r   r   )r|   r  r   r  r   rd   r   nameclientr  r   ro   ri   s                r#   r   r     s     "H::DDO Z&&((@,>,@,@DN/11D	%%GAt#tW%% 	-E -"6??X\\'599:: "h55 -J$$V,,,!h55 -J$$V,,,  -		- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-  \" # # #S"""""""# OsC   *E	 :B7D=1E	 =EE	 EE	 	E5E0*E50E5tuple[int, str]c                >    t          |           }t          |          S )zRead status file and check if the process is alive.

    Return (pid, connection_name) on success.

    Raise BadStatus if something's wrong.
    )r   r   )r|   r   s     r#   r{   r{     s     {##Dr$   r   c                B   d| vrt          d          | d         }t          |t                    st          d          t          |          st          d          d| vrt          d          | d         }t          |t                    st          d          ||fS )z}Check if the process is alive.

    Return (pid, connection_name) on success.

    Raise BadStatus if something's wrong.
    r   z"Invalid status file (no pid field)zpid field is not an intzDaemon has diedconnection_namez.Invalid status file (no connection_name field)z%connection_name field is not a string)rX   r   intr   r   )r   r   r  s      r#   r   r     s     D<===
u+Cc3 31222:: +)***$$HIII,-Oos++ A?@@@r$   dict[str, object]c                j   t           j                            |           st          d          t	          |           5 }	 t          j        |          }n"# t          $ r}t          d          |d}~ww xY w	 ddd           n# 1 swxY w Y   t          |t                    st          d          |S )zRead status file.

    Raise BadStatus if the status file doesn't exist or contains
    invalid JSON or the JSON is not a dict.
    zNo status file foundz Malformed status file (not JSON)Nz Invalid status file (not a dict))
r   pathisfilerX   r   r   loadre   r   r  )r|   r   r   es       r#   r   r     s    7>>+&& 0.///	k		 Ga	G9Q<<DD 	G 	G 	G>??QF	G G G G G G G G G G G G G G G G
 dD!! <:;;;Ks5   B AB
A4A//A44BBBc                J    	 t          |            n# t          $ r Y dS w xY wdS )z&Check if the server is running cleanlyFT)r{   rX   )r|   s    r#   r   r     s?    ;   uu4s    
  c                 H    t          t          j        dd                     d S )Nr   )rj   r^   rZ   r   r$   r#   console_entryr)    s     !""r$   )rZ   r[   r   r   )rk   r   r   r   )rp   rq   r   rr   )rd   ry   r   r   )F)rd   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   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   )_rY   
__future__r   argparser  r   r   r  r^   r   rf   collections.abcr   typingr   r   r   mypy.dmypy_osr   r	   mypy.dmypy_utilr
   r   r   mypy.ipcr   r   	mypy.mainr   r   r   r   r   mypy.versionr   RawDescriptionHelpFormatterr   ArgumentParserr`   version_infocolorrw   add_argumentadd_subparsers
subparsers
add_parserstart_parserpr   r   restart_parserstatus_parserstop_parserkill_parsercheck_parserSUPPRESS
run_parserrecheck_parsersuggest_parserr   inspect_parserhang_parserdaemon_parserhelp_parserre   rX   rj   rc   	Namespaceru   r0   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#   <module>rK     sR    # " " " " "    				  



      # # # # # # * * * * * * * * * * % % % % % % % % > > > > > > > > > > , , , , , , , , % % % % % % R R R R R R R R R R $ $ $ $ $ $D D D D DXA D D D
 
!	 	;SV
 
 
 wFL   4          07_       +%	1     ""$$
((~(FF Fq |V#<a b b b 3Y     V3S7]      **E +    |V#<a b b b 3Y     V3S7]     ))(9M)NN N t[<S T T T &-_ ` ` `''5`'aa aa''5V'WW Wa((3:^ )   q t[<S T T T tY|(:K L L L }#F G G G ")Z [ [ [ wc8V W W W 	W     &&	*	= '   
Q
 t[<S T T T }#F G G G ")Z [ [ [ 3Y     |V#<a b b b 	W    
 
		9      ***	] +   
 t[<S T T T tY|(:K L L L }#F G G G ")Z [ [ [ 	W    
 
	R	     z6;Y Z Z Z**T +    		D	     	E    
 ,-\     |*[     		U    
 ,-Z     		N	     		M      **A +    	
	     	+++	)     	Q     		\     
     
     	?    
 
0     	J     ''5K'LL La))(9S)TT T 3Y     |V#<a b b b V3S7]     h&7 8 8 8''// /a    	      ,   
 8-.45       *    & & & & && & & & &2 2 2 2 2( 
&O &O &O &OR & & & &*             O O O O O O O O< P P P P* P P P P$& & & &R	\ 	\ 	\ 	\ 8 8 8 8
 D D D D.     >B+ + + + + +\          ,   $        r$   