o
    ҷh-                     @  sD  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rBd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 dZd=ddZd=ddZd>ddZd?ddZd@d"d#Zd@d$d%ZdAd&d'Z dBd(d)Z!dCd-d.Z"dDd3d4Z#dEd5d6Z$d7Z%d8Z&d9Z'd:Z(d;Z)e*d<kre$  dS dS )FzG
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

import sys

from ._ki import enable_ki_protection
from ._run import GLOBAL_RUN_CONTEXT
ztry:
    return{}GLOBAL_RUN_CONTEXT.{}.{}
except AttributeError:
    raise RuntimeError("must be called from async context") from None
c                   @  sJ   e Zd ZU ded< ded< ejdddZded< ejdddZded	< d
S )Filer   pathstrmodname T)defaultkw_onlyplatformimportsN)__name__
__module____qualname____annotations__attrsfieldr   r    r   r   J/var/www/html/venv/lib/python3.10/site-packages/trio/_tools/gen_exports.pyr
   0   s
   
 r
   nodeast.ASTreturn1TypeGuard[ast.FunctionDef | ast.AsyncFunctionDef]c                 C  s   t | tjtjfS )zHCheck if the AST node is either a function
    or an async function
    )
isinstanceastFunctionDefAsyncFunctionDef)r   r   r   r   is_function8   s   r#   c                 C  s4   t | r| jD ]}t|tjr|jdkr dS qdS )z-Check if the AST node has a _public decorator_publicTF)r#   decorator_listr   r    Nameid)r   	decoratorr   r   r   	is_public?   s   
r)   tree0Iterator[ast.FunctionDef | ast.AsyncFunctionDef]c                 c  s$    t | D ]	}t|r|V  q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   r   r   r   get_public_methodsH   s   r-   funcdef&ast.FunctionDef | ast.AsyncFunctionDefr   c                 C  s~   dd | j j D }| j jr|d| j jj  | j jD ]}||jd |j  q| j jr7|d| j jj  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)"
    c                 S  s   g | ]}|j qS r   )arg).0r0   r   r   r   
<listcomp>]   s    z+create_passthrough_args.<locals>.<listcomp>*=z**z({})z, )argsvarargappendr0   
kwonlyargskwargformatjoin)r.   	call_argsr0   r   r   r   create_passthrough_argsU   s   r=   filesourcetuple[bool, str]c                 C  sN   ddl }tjtjddd| jdg|d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!
)	rB   
subprocessrunsys
executabler   
returncodestderrstdout)r>   r?   rB   resultr   r   r   	run_blackg   s   

rR   c              
   C  sT   ddl }tjtjdddddd| jd	g	|d
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   NrA   ruffcheckz--fixz--unsafe-fixesrC   rD   TrE   rF   FzFailed to run ruff!
)	rS   rJ   rK   rL   rM   r   rN   rO   rP   )r>   r?   rS   rQ   r   r   r   run_ruff   s&   

rU   c                 C  s6   t tfD ]}|| |\}}|st| td q|S )zFormat the specified file using black and ruff.

    Returns:
      Formatted source code.

    Raises:
      ImportError: If either is not installed.
      SystemExit: If either failed.
       )rR   rU   printrL   exit)r>   r?   fnsuccessr   r   r   run_linters   s   
r[   c                 C  s  t g}|| j | jr*d| jvr|d d| jvr |d |d| j d d|g}tj| j}g }t	|D ]|}|j
j
d jd	ksJJ |j
j
d= ||j |jD ]}t|tjri|jd
krid} nqXd}tdg|_t|}t|du r|jdd= n|jdd= tj|dd}	|r|	dd}	tt|tjrdnd| j|j| }
|	t|
d }|| q=|  |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contextmanagerTFenable_ki_protectionNrV   z    )indent_withz
->Iteratorz->AbstractContextManagerz await  z
__all__ = z

)HEADERr7   r   r   r;   astorcode_to_ast
parse_filer   r-   r5   r0   namer%   r   r    r&   r'   r=   get_docstringbody	to_sourcereplaceTEMPLATEr:   r"   r   r   sortinsert)r>   header	generatedr?   method_namesmethoddecis_cmnew_argsfunctemplatesnippetr   r   r   gen_public_wrappers_source   sR   






rw   	new_filesdict[str, str]boolc                 C  sF   |   D ]\}}tj|s dS t|jdd}||kr  dS qdS )NFutf-8)rI   T)itemsosr   existsr   	read_text)rx   new_path
new_source
old_sourcer   r   r   matches_disk_files	  s   r   filesIterable[File]do_testNonec          
   	   C  s   i }| D ]'}t d|j t|}t||}tj|j\}}tj|t| }|||< qt|}|rE|s?t d t	
d d S t d d S | D ]!\}}t|dddd}	|	| W d    n1 sew   Y  qIt d	 |sxt	
d d S d S )
Nz	Scanning:z2Generated sources are outdated. Please regenerate.rV   z!Generated sources are up to date.wr{   
)rI   newlinez!Regenerated sources successfully.)rW   r   rw   r[   r}   splitr;   PREFIXr   rL   rX   r|   openwrite)
r   r   rx   r>   r   dirnamebasenamer   matches_diskfpr   r   r   process  s.   

r   c               
   C  s   t jdd} | jddddd |  }t }|d  sJ |d	 }t|d
 dtdt|d dt	dt|d ddt
dt|d ddtdt|d ddtdg}t||jd 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_wrapr   r   r   main/  sN   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
a  from typing import TYPE_CHECKING

if TYPE_CHECKING:
    import select
    from collections.abc import Callable
    from contextlib import AbstractContextManager

    from .. import _core
    from .._file_io import _HasFileNo
    from ._traps import Abort, RaiseCancelT
a  from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from contextlib import AbstractContextManager

    from typing_extensions import Buffer

    from .._file_io import _HasFileNo
    from ._unbounded_queue import UnboundedQueue
    from ._windows_cffi import Handle, CData
__main__)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   )rx   ry   r   rz   )r   r   r   rz   r   r   )r   r   )+__doc__
__future__r   r   r    r}   rJ   rL   pathlibr   textwrapr   typingr   r   collections.abcr   r   typing_extensionsr   rb   r   ra   rj   definer
   r#   r)   r-   r=   rR   rU   r[   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sN   


	



&

I


.
