
    Eg}-                    b   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m	Z	 ddl
mZ ddlmZ ddlZerddlmZmZ ddlmZ ddlZd	Zd
ZdZej         G d d                      Zd2dZd2dZd3dZd4dZd5dZd5dZd6d Z d7d!Z!d8d%Z"d9d*Z#d:d+Z$d,Z%d-Z&d.Z'd/Z(d0Z)e*d1k    r e$             dS dS );zG
Code generation script for class methods
to be exported as public API
    )annotationsN)Path)indent)TYPE_CHECKING)IterableIterator)	TypeGuard
_generateda9  # ***********************************************************
# ******* WARNING: AUTOGENERATED! ALL EDITS WILL BE LOST ******
# *************************************************************
from __future__ import annotations

from ._ki import LOCALS_KEY_KI_PROTECTION_ENABLED
from ._run import GLOBAL_RUN_CONTEXT
zlocals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
try:
    return{}GLOBAL_RUN_CONTEXT.{}.{}
except AttributeError:
    raise RuntimeError("must be called from async context") from None
c                      e Zd ZU ded<   ded<    ej        dd          Zded<    ej        dd          Zded	<   d
S )Filer   pathstrmodname T)defaultkw_onlyplatformimportsN)__name__
__module____qualname____annotations__attrfieldr   r        L/var/www/sysmax/venv/lib/python3.11/site-packages/trio/_tools/gen_exports.pyr   r   /   sh         JJJLLLDJr4888H88884:b$777G777777r   r   nodeast.ASTreturn1TypeGuard[ast.FunctionDef | ast.AsyncFunctionDef]c                V    t          | t          j        t          j        f          rdS dS )zHCheck if the AST node is either a function
    or an async function
    TF)
isinstanceastFunctionDefAsyncFunctionDef)r   s    r   is_functionr'   7   s*     $#*>?@@ t5r   c                    t          |           r2| j        D ]*}t          |t          j                  r|j        dk    r dS +dS )z-Check if the AST node has a _public decorator_publicTF)r'   decorator_listr#   r$   Nameid)r   	decorators     r   	is_publicr.   @   sQ    4 , 	 	I)SX.. 9<93L3Ltt5r   tree0Iterator[ast.FunctionDef | ast.AsyncFunctionDef]c              #  ^   K   t          j        |           D ]}t          |          r|V  dS )zReturn a list of methods marked as public.
    The function walks the given tree and extracts
    all objects that are functions which are marked
    public.
    N)r$   walkr.   )r/   r   s     r   get_public_methodsr3   I   sA         T?? 	JJJ r   funcdef&ast.FunctionDef | ast.AsyncFunctionDefr   c                   g }| j         j         D ]}|                    |j                   | j         j        r'|                    d| j         j        j        z              | j         j        D ]'}|                    |j        dz   |j        z              (| j         j        r'|                    d| j         j        j        z              d                    d                    |                    S )a  Given a function definition, create a string that represents taking all
    the arguments from the function, and passing them through to another
    invocation of the same function.

    Example input: ast.parse("def f(a, *, b): ...")
    Example output: "(a, b=b)"
    *=z**z({})z, )argsappendargvararg
kwonlyargskwargformatjoin)r4   	call_argsr;   s      r   create_passthrough_argsrB   V   s     I|  " "!!!!| 8w|266777|& 2 2301111| 8 2 66777==9--...r   filesourcetuple[bool, str]c                    ddl }t          j        t          j        ddd| j        dg|dd	          }|j        dk    rd
d|j         fS d|j        fS )a	  Run black on the specified file.

    Returns:
      Tuple of success and result string.
      ex.:
        (False, "Failed to run black!
error: cannot format ...")
        (True, "<formatted source>")

    Raises:
      ImportError: If black is not installed.
    r   N-mblack--stdin-filename-Tutf8inputcapture_outputencodingFzFailed to run black!
)	rH   
subprocessrunsys
executabler   
returncodestderrstdout)rC   rD   rH   results       r   	run_blackrX   j   sv     LLL
 ^	w(:DIsK  F A>v}>>>>r   c                    ddl }t          j        t          j        ddddddd	| j        d
g
|dd          }|j        dk    rdd|j         fS d|j        fS )a  Run ruff on the specified file.

    Returns:
      Tuple of success and result string.
      ex.:
        (False, "Failed to run ruff!
error: Failed to parse ...")
        (True, "<formatted source>")

    Raises:
      ImportError: If ruff is not installed.
    r   NrG   ruffcheckz--fixz--unsafe-fixesz--output-format=textrI   rJ   TrK   rL   FzFailed to run ruff!
)	rZ   rP   rQ   rR   rS   r   rT   rU   rV   )rC   rD   rZ   rW   s       r   run_ruffr\      s     KKK^ N"I	
 !  F& A=fm====r   c                    t          | |          \  }}|s#t          |           t          j        d           t	          | |          \  }}|s#t          |           t          j        d           |S )zFormat the specified file using black and ruff.

    Returns:
      Formatted source code.

    Raises:
      ImportError: If either is not installed.
      SystemExit: If either failed.
       )rX   printrR   exitr\   )rC   rD   successresponses       r   run_lintersrc      sq     "$//GX h x00GX hOr   c                   t           g}| j        r|                    | j                   | j        rZd| j        vr|                    d           d| j        vr|                    d           |                    d| j         d           d                    |          g}t
          j                            | j                  }g }t          |          D ]V}|j
        j
        d         j        d	k    sJ |j
        j
        d= |                    |j                   |j        D ]+}t          |t          j                  r|j        d
k    rd} n,d}g |_        t%          |          }t          j        |          |j        dd= n
|j        dd= t          j        |d          }	|r|	                    dd          }	t.                              t          |t          j                  rdnd| j        |j        |z             }
|	t7          |
d          z   }|                    |           X|                                 |                    dd|           d                    |          S )zZScan the given .py file for @_public decorators, and generate wrapper
    functions.

    r   z!from typing import TYPE_CHECKING
z
import syszimport sys
z,
assert not TYPE_CHECKING or sys.platform=="z"
r   r   selfcontextmanagerTFNr^   z    )indent_withz
->Iteratorz->ContextManagerz await  z
__all__ = z

)HEADERr   r:   r   r@   astorcode_to_ast
parse_filer   r3   r9   r;   namer*   r#   r$   r+   r,   rB   get_docstringbody	to_sourcereplaceTEMPLATEr?   r&   r   r   sortinsert)rC   header	generatedrD   method_namesmethoddecis_cmnew_argsfunctemplatesnippets               r   gen_public_wrappers_sourcer      s   
 XF| $dl###} 	
 $,..MM>???t|++MM.)))NDMNNN	
 	
 	
 !I))$)44FL$V,, +" +"{"&&0000KQFK(((( 	 	C#sx(( SV7G-G-GE !# +622 V$$,AAA ABB v7;;; 	B<<.@AAD ??#FC,@AAJIIsLK("
 
 '222 	!!!!Q5\55666;;y!!!r   	new_filesdict[str, str]boolc                
   |                                  D ]m\  }}t          j                            |          s dS t	          |d          5 }|                                }d d d            n# 1 swxY w Y   ||k    r dS ndS )NFutf-8rO   T)itemsosr   existsopenread)r   new_path
new_sourceold_file
old_sources        r   matches_disk_filesr     s     ) 1 1  *w~~h'' 	55(W--- 	)!J	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)##55 $4s   A..A2	5A2	filesIterable[File]do_testNonec                  i }| D ]}t          d|j                   t          |          }t          ||          }t          j                            |j                  \  }}t          j                            |t          |z             }|||<   |rEt          |          s%t          d           t          j
        d           d S t          d           d S |                                D ]D\  }}t          |dd          5 }|                    |           d d d            n# 1 swxY w Y   Et          d           d S )	Nz	Scanning:z2Generated sources are outdated. Please regenerate.r^   z!Generated sources are up to date.wr   r   z!Regenerated sources successfully.)r_   r   r   rc   r   splitr@   PREFIXr   rR   r`   r   r   write)	r   r   r   rC   r   dirnamebasenamer   fs	            r   processr     s   I ) )k49%%%/55
 z22
GMM$)447<<():;;(	( 
3!),, 	7FGGGHQKKKKK566666$-OO$5$5 	$ 	$ Hjhg666 $!
###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $122222s   D$$D(	+D(	c            
        t          j        d          } |                     dddd           |                                 }t	          j                    }|dz                                  sJ |d	z  }t          |d
z  dt                    t          |dz  dt                    t          |dz  ddt                    t          |dz  ddt                    t          |dz  ddt                    g}t          ||j                   d S )Nz,Generate python code for public api wrappers)descriptionz--testz-t
store_truez test if code is still up to date)actionhelpLICENSEzsrc/trio/_corez_run.pyrunner)r   z_instrumentation.pyzrunner.instrumentsz_io_windows.pyzrunner.io_managerwin32)r   r   z_io_epoll.pylinuxz_io_kqueue.pydarwin)r   )argparseArgumentParseradd_argument
parse_argsr   cwdr   r   IMPORTS_RUNIMPORTS_INSTRUMENTIMPORTS_WINDOWSIMPORTS_EPOLLIMPORTS_KQUEUEr   test)parserparsed_argssource_rootcoreto_wraps        r   mainr   6  sX   $B  F $|2T     ##%%K(**K)#++-----))DTIx===(( &	
 	
 	

 	###		
 	
 	
 	>!!		
 	
 	
 	?""		
 	
 	
'G6 G[-......r   aN  from collections.abc import Awaitable, Callable
from typing import Any, TYPE_CHECKING

from outcome import Outcome
import contextvars

from ._run import _NO_SEND, RunStatistics, Task
from ._entry_queue import TrioToken
from .._abc import Clock

if TYPE_CHECKING:
    from typing_extensions import Unpack
    from ._run import PosArgT
z)from ._instrumentation import Instrument
zZfrom typing import TYPE_CHECKING

if TYPE_CHECKING:
    from .._file_io import _HasFileNo
zfrom typing import Callable, ContextManager, TYPE_CHECKING

if TYPE_CHECKING:
    import select

    from .. import _core
    from ._traps import Abort, RaiseCancelT
    from .._file_io import _HasFileNo
zfrom typing import TYPE_CHECKING, ContextManager

if TYPE_CHECKING:
    from .._file_io import _HasFileNo
    from ._windows_cffi import Handle, CData
    from typing_extensions import Buffer

    from ._unbounded_queue import UnboundedQueue
__main__)r   r   r    r!   )r/   r   r    r0   )r4   r5   r    r   )rC   r   rD   r   r    rE   )rC   r   rD   r   r    r   )rC   r   r    r   )r   r   r    r   )r   r   r   r   r    r   )r    r   )+__doc__
__future__r   r   r$   r   rP   rR   pathlibr   textwrapr   typingr   r   collections.abcr   r   typing_extensionsr	   rj   r   ri   rr   definer   r'   r.   r3   rB   rX   r\   rc   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      sC    # " " " " "  



 				     



                          ,22222222++++++ 	
 8 8 8 8 8 8 8 8      
 
 
 
/ / / /(   >$ $ $ $N   0H" H" H" H"V   3 3 3 30(/ (/ (/ (/V 		 zDFFFFF r   