o
    %h                      @   s   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m	Z	m
Z
mZmZmZmZmZmZmZ d dlZd dlmZ d dlmZmZ e ZedZedd	d
ZG dd dee ZG dd dee eZG dd deZG dd	 d	eZdS )    N)AbstractContextManager)TracebackType)
AnyCallable	Coroutine	GeneratorGenericOptionalTypeTypeVarUnioncast)Error)ImplToApiMappingImplWrapperTSelfSyncContextManager)boundc                   @   s@   e Zd ZdddZedefd	d
ZdddZdefddZ	dS )	EventInfo	sync_baseSyncBasefutureasyncio.Future[T]returnNc                    s,   || _ || _t  | j fdd d S )Nc                          S Nswitch_g_self O/var/www/html/myenv/lib/python3.10/site-packages/playwright/_impl/_sync_base.py<lambda>2       z$EventInfo.__init__.<locals>.<lambda>)
_sync_base_futuregreenlet
getcurrentadd_done_callbackselfr   r   r#   r!   r$   __init__.   s   zEventInfo.__init__c                 C   sV   | j  s| jj  | j  rt| jj | j  }|r |t	t
t| j  S r   )r(   doner'   _dispatcher_fiberr   asyncio_set_running_loop_loop	exceptionr   r   mappingfrom_maybe_implresult)r-   r4   r#   r#   r$   value4   s   


zEventInfo.valuec                 C   s   | j   d S r   )r(   cancelr-   r#   r#   r$   _cancel>   s   zEventInfo._cancelc                 C   
   | j  S r   )r(   r/   r:   r#   r#   r$   is_doneA      
zEventInfo.is_doner   r   r   r   r   Nr   N)
__name__
__module____qualname__r.   propertyr   r8   r;   boolr=   r#   r#   r#   r$   r   -   s    

	r   c                   @   sR   e Zd ZdddZdee fd	d
Zdeee	  dee	 dee
 ddfddZdS )EventContextManagerr   r   r   r   r   Nc                 C   s   t t ||| _d S r   )r   r   _eventr,   r#   r#   r$   r.   F   s   zEventContextManager.__init__c                 C   s   | j S r   )rG   r:   r#   r#   r$   	__enter__I   s   zEventContextManager.__enter__exc_typeexc_valexc_tbc                 C   s   |r	| j   d S | j j d S r   )rG   r;   r8   )r-   rI   rJ   rK   r#   r#   r$   __exit__L   s   zEventContextManager.__exit__r?   )rA   rB   rC   r.   r   r   rH   r	   r
   BaseExceptionr   rL   r#   r#   r#   r$   rF   E   s    

rF   c                       s   e Zd Zdeddf fddZdefddZdeeeeef e	eeef f defd	d
Z
deedef ef ded fddZdededdfddZdededdfddZdededdfddZ  ZS )r   impl_objr   Nc                    s    t  | |j| _|j| _d S r   )superr.   r3   r0   )r-   rN   	__class__r#   r$   r.   Y   s   zSyncBase.__init__c                 C   r<   r   )	_impl_obj__str__r:   r#   r#   r$   rS   ^   r>   zSyncBase.__str__coroc                    s   d}| j  r|  tdt  | j |}t|dt	d t|dt
jdd | fdd	 | sB| j  | r9t| j  | S )
NTz4Event loop is closed! Is Playwright already stopped?__pw_stack__r   __pw_stack_trace__
   )limitc                    r   r   r   r   r!   r#   r$   r%   o   r&   z SyncBase._sync.<locals>.<lambda>)r3   	is_closedcloser   r)   r*   create_tasksetattrinspectstack	tracebackextract_stackr+   r/   r0   r   r1   r2   r7   )r-   rT   __tracebackhide__taskr#   r!   r$   _synca   s   

zSyncBase._synchandler.).Nc                 C   s   t |r	t|S |S r   )callabler5   wrap_handler)r-   rd   r#   r#   r$   _wrap_handleru   s   
zSyncBase._wrap_handlereventfc                 C      | j || | dS )z9Registers the function ``f`` to the event name ``event``.N)rR   onrg   r-   rh   ri   r#   r#   r$   rk   |      zSyncBase.onc                 C   rj   )zoThe same as ``self.on``, except that the listener is automatically
        removed after being called.
        N)rR   oncerg   rl   r#   r#   r$   rn      s   zSyncBase.oncec                 C   rj   )z*Removes the function ``f`` from ``event``.N)rR   remove_listenerrg   rl   r#   r#   r$   ro      rm   zSyncBase.remove_listener)rA   rB   rC   r   r.   strrS   r   r   r   rc   r   rg   rk   rn   ro   __classcell__r#   r#   rP   r$   r   X   s     

r   c                   @   sR   e Zd ZdedefddZdeee  dee dee ddfd	d
Z	dddZ
dS )r   r-   r   c                 C   s   | S r   r#   r:   r#   r#   r$   rH      s   zSyncContextManager.__enter__rI   rJ   
_tracebackNc                 C   s   |    d S r   )rZ   )r-   rI   rJ   rr   r#   r#   r$   rL      s   zSyncContextManager.__exit__c                 C   s   d S r   r#   r:   r#   r#   r$   rZ      s    zSyncContextManager.closer@   )rA   rB   rC   r   rH   r	   r
   rM   r   rL   rZ   r#   r#   r#   r$   r      s    

)r1   r]   r_   
contextlibr   typesr   typingr   r   r   r   r   r	   r
   r   r   r   r)   playwright._impl._helperr   %playwright._impl._impl_to_api_mappingr   r   r5   r   r   r   rF   r   r   r#   r#   r#   r$   <module>   s    03