
    X-Ph                        U d Z ddlmZ ddlZddl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 dZd	ed
<   ddZddZ G d de          ZdS )zShared code between dmypy.py and dmypy_server.py.

This should be pretty lightweight and not depend on other mypy code (other than ipc).
    )annotationsN)IterableIterator)TracebackType)AnyFinalTextIO)IPCBasez.dmypy.jsonr   DEFAULT_STATUS_FILE
connectionr
   returnr   c                *   |                                  }|st          d          	 t          j        |          }n"# t          $ r}t          d          |d}~ww xY wt          |t                    s t          dt          |           d          |S )zReceive single JSON data frame from a connection.

    Raise OSError if the data received is not valid JSON or if it is
    not a dict.
    zNo data receivedzData received is not valid JSONNzData received is not a dict ())readOSErrorjsonloads	Exception
isinstancedicttype)r   bdatadataes       O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/dmypy_util.pyreceiver      s     OOE *()))@z%   @ @ @788a?@dD!! ECd4jjCCCDDDKs   < 
AAAr   Nonec                T    |                      t          j        |                     dS )zSend data to a connection encoded and framed.

    The data must be JSON-serializable. We assume that a single send call is a
    single frame to be sent on the connect.
    N)writer   dumps)r   r   s     r   sendr!   %   s(     TZ%%&&&&&    c                      e Zd ZdZd4d
Zd5dZd6dZd7dZd8dZd9dZ	d:dZ
d9dZd;dZd<d=dZd;dZd<d>d!Zd<d?d$Zd<d@d'Zd;d(Zd:d)Zd<dAd,ZdBd.Zd;d/ZdCd2Zd3S )DWriteToConnzAHelper class to write to a connection instead of standard output.serverr
   
output_keystrisattyboolr   r   c                0    || _         || _        || _        d S N)r%   r&   _isatty)selfr%   r&   r(   s       r   __init__zWriteToConn.__init__1   s    $r"   r	   c                    | S r+    r-   s    r   	__enter__zWriteToConn.__enter__6   s    r"   ttype[BaseException] | NonevalueBaseException | None	tracebackTracebackType | Nonec                    d S r+   r0   )r-   r3   r5   r7   s       r   __exit__zWriteToConn.__exit__9   s	     	r"   Iterator[str]c                    t           j        r+   ioUnsupportedOperationr1   s    r   __iter__zWriteToConn.__iter__A       %%r"   c                    t           j        r+   r=   r1   s    r   __next__zWriteToConn.__next__D   rA   r"   c                    d S r+   r0   r1   s    r   closezWriteToConn.closeG       r"   intc                    t           r+   )r   r1   s    r   filenozWriteToConn.filenoJ   s    r"   c                    d S r+   r0   r1   s    r   flushzWriteToConn.flushM   rF   r"   c                    | j         S r+   )r,   r1   s    r   r(   zWriteToConn.isattyP   s
    |r"   r   nc                    t           j        r+   r=   )r-   rM   s     r   r   zWriteToConn.readS   rA   r"   c                    dS NFr0   r1   s    r   readablezWriteToConn.readableV       ur"   limitc                    t           j        r+   r=   )r-   rS   s     r   readlinezWriteToConn.readlineY   rA   r"   hint	list[str]c                    t           j        r+   r=   )r-   rV   s     r   	readlineszWriteToConn.readlines\   rA   r"   offsetwhencec                    t           j        r+   r=   )r-   rZ   r[   s      r   seekzWriteToConn.seek_   rA   r"   c                    dS rP   r0   r1   s    r   seekablezWriteToConn.seekableb   rR   r"   c                    t           j        r+   r=   r1   s    r   tellzWriteToConn.telle   rA   r"   size
int | Nonec                    t           j        r+   r=   )r-   rb   s     r   truncatezWriteToConn.truncateh   rA   r"   outputc                \    | j         |i}t          | j        |           t          |          S r+   )r&   r!   r%   len)r-   rf   resps      r   r   zWriteToConn.writek   s,     $8T[$6{{r"   c                    dS )NTr0   r1   s    r   writablezWriteToConn.writablep   s    tr"   linesIterable[str]c                :    |D ]}|                      |           d S r+   )r   )r-   rl   ss      r   
writelineszWriteToConn.writeliness   s,     	 	AJJqMMMM	 	r"   N)r%   r
   r&   r'   r(   r)   r   r   )r   r	   )r3   r4   r5   r6   r7   r8   r   r   )r   r;   )r   r'   )r   r   )r   rG   )r   r)   )r   )rM   rG   r   r'   )rS   rG   r   r'   )rV   rG   r   rW   )rZ   rG   r[   rG   r   rG   )rb   rc   r   rG   )rf   r'   r   rG   )rl   rm   r   r   )__name__
__module____qualname____doc__r.   r2   r:   r@   rC   rE   rI   rK   r(   r   rQ   rU   rY   r]   r_   ra   re   r   rk   rp   r0   r"   r   r$   r$   .   s       KK   
      & & & && & & &            & & & & &   & & & & && & & & && & & & &   & & & && & & & &   
        r"   r$   )r   r
   r   r   )r   r
   r   r   r   r   )rt   
__future__r   r>   r   collections.abcr   r   typesr   typingr   r   r	   mypy.ipcr
   r   __annotations__r   r!   r$   r0   r"   r   <module>r{      s    
 # " " " " " 				  . . . . . . . .       % % % % % % % % % %      *  * * * *   $' ' ' 'G G G G G& G G G G Gr"   