o
    >h                     @  s,  d Z ddlmZ ddlmZ zddlmZ W n ey#   dZdZ	Y n9w dZddl
mZ dd	lmZmZ dd
lmZ d ddZddd edddD ZedZedurZeneZ	ddlmZ ddlmZ ddlmZmZ estdZe	du p{e	dvZde e	 Z!esddlm"Z" G dd deeZ#dS )!z\
GObject Introspection reactor tests; i.e. `gireactor` module for gio/glib/gtk
integration.
    )annotations)skipIf)GioFNT)environ)get_required_versionrequire_version)	gireactorsomeVersionstrreturnc              
   C  s>   zt d|  W dS  ty } z
t|W  Y d }~S d }~ww )NGtk )r   
ValueErrorr
   )r	   ve r   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/internet/test/test_gireactor.pyrequireEach   s   r   z, c                 c  s    | ]}t |V  qd S )N)r   ).0versionr   r   r   	<genexpr>"   s
    
r   TWISTED_TEST_GTK_VERSIONz4.0,3.0,r   )ReactorAlreadyRunning)ReactorBuilder)SkipTestTestCasez0GObject Introspection `gi` module not importable)z3.0z4.0zUnknown GTK version: )r   c                   @  st   e Zd ZdZddd	Zdd
dZeeedddZ	eeedddZ
dddZdddZdddZdddZdS )GApplicationRegistrationTestsa  
    GtkApplication and GApplication are supported by
    L{twisted.internet.gtk3reactor} and L{twisted.internet.gireactor}.

    We inherit from L{ReactorBuilder} in order to use some of its
    reactor-running infrastructure, but don't need its test-creation
    functionality.
    appGio.Applicationreactorgireactor.GIReactorr   Nonec                   sv   t |ds	tdg d fddd fd	d
}|d| |   | t|   | ddg dS )z
        Register the app, run the reactor, make sure app was activated, and
        that reactor was running, and that reactor can be stopped.
        quitz Version of PyGObject is too old.r   r!   c                     s    d    d S )Nstopped)appendstopr   )r   resultr   r   r%   R   s   
z6GApplicationRegistrationTests.runReactor.<locals>.stopwidgetobjectc                   s    d  d d S )N	activatedr   )r$   	callLater)r'   r   r&   r%   r   r   activateV   s   
z:GApplicationRegistrationTests.runReactor.<locals>.activater,   r)   r#   Nr   r!   )r'   r(   r   r!   )hasattrr   connectholdregisterGApplicationr   
runReactorassertEqual)selfr   r   r,   r   r+   r   r2   D   s   
	
z(GApplicationRegistrationTests.runReactorc                 C  s4   dd | _ |  }tjdtjjd}| || dS )zR
        L{Gio.Application} instances can be registered with a gireactor.
        c                   S     t jddS NF)useGtkr   	GIReactorr   r   r   r   <lambda>j       zIGApplicationRegistrationTests.test_gApplicationActivate.<locals>.<lambda>!com.twistedmatrix.trial.gireactorapplication_idflagsN)reactorFactorybuildReactorr   ApplicationApplicationFlags
FLAGS_NONEr2   r4   r   r   r   r   r   test_gApplicationActivatef   s   
z7GApplicationRegistrationTests.test_gApplicationActivatec                 C  sn   ddl m}m}m} | |tj | |tj | |tj |  }| 	t
|d | d|d d  dS )z
        L{twisted.internet.gtk3reactor} is now just a set of compatibility
        aliases for L{twisted.internet.GIReactor}.
        r   )Gtk3ReactorPortableGtk3Reactorinstall   z+twisted.internet.gtk3reactor was deprecatedmessageN)twisted.internet.gtk3reactorrG   rH   rI   assertIsr   r9   PortableGIReactorflushWarningsr3   lenassertIn)r4   rG   rH   rI   warningsr   r   r   test_gtkAliasess   s   z-GApplicationRegistrationTests.test_gtkAliasesc                 C  s2   t j| _|  }tjdtjjd}| 	|| dS )zT
        L{Gtk.Application} instances can be registered with a gtk3reactor.
        z#com.twistedmatrix.trial.gtk3reactorr=   N)
r   r9   r@   rA   r   rB   r   rC   rD   r2   rE   r   r   r   test_gtkApplicationActivate   s   z9GApplicationRegistrationTests.test_gtkApplicationActivatec                 C  s6   t j| _|  }tjdtjjd}| t	|j
| dS )zo
        L{gireactor.PortableGIReactor} doesn't support application
        registration at this time.
        r<   r=   N)r   rN   r@   rA   r   rB   rC   rD   assertRaisesNotImplementedErrorr1   rE   r   r   r   test_portable   s   z+GApplicationRegistrationTests.test_portablec                 C  sB   dd | _ |  }t }| t|j|}| |jd d dS )zp
        Older versions of PyGObject lack C{Application.quit}, and so won't
        allow registration.
        c                   S  r5   r6   r8   r   r   r   r   r:      r;   z;GApplicationRegistrationTests.test_noQuit.<locals>.<lambda>r   zApplication registration is notN)	r@   rA   r(   rU   RuntimeErrorr1   
assertTrueargs
startswith)r4   r   r   excr   r   r   test_noQuit   s
   
z)GApplicationRegistrationTests.test_noQuitc                   sR   dd _  tjdtjjd d fdd}d	| t d
S )zp
        It is not possible to register a C{Application} after the reactor has
        already started.
        c                   S  r5   r6   r8   r   r   r   r   r:      r;   zIGApplicationRegistrationTests.test_cantRegisterAfterRun.<locals>.<lambda>r<   r=   r   r!   c                    s.    tj } | jd d   d S )Nr   z5Can't register application after reactor was started.)rU   r   r1   r3   rZ   r%   )r\   r   r   r4   r   r   tryRegister   s   
zLGApplicationRegistrationTests.test_cantRegisterAfterRun.<locals>.tryRegisterr   Nr-   )	r@   rA   r   rB   rC   rD   r*   r   r2   )r4   r_   r   r^   r   test_cantRegisterAfterRun   s   
	z7GApplicationRegistrationTests.test_cantRegisterAfterRunc                 C  sf   dd | _ |  }tjdtjjd}|| tjdtjjd}| t|j|}| 	|j
d d dS )	zN
        It is not possible to register more than one C{Application}.
        c                   S  r5   r6   r8   r   r   r   r   r:      r;   zFGApplicationRegistrationTests.test_cantRegisterTwice.<locals>.<lambda>r<   r=   z"com.twistedmatrix.trial.gireactor2r   z2Can't register more than one application instance.N)r@   rA   r   rB   rC   rD   r1   rU   rX   r3   rZ   )r4   r   r   app2r\   r   r   r   test_cantRegisterTwice   s   


z4GApplicationRegistrationTests.test_cantRegisterTwiceN)r   r   r   r    r   r!   r-   )__name__
__module____qualname____doc__r2   rF   r   	noGtkSkipnoGtkMessagerS   rT   rW   r]   r`   rb   r   r   r   r   r   :   s    
	
"


r   )r	   r
   r   r
   )$rf   
__future__r   unittestr   gi.repositoryr   ImportError
giImported
gtkVersionosr   gir   r   twisted.internetr   r   joingetspliterrorMessageactualVersiontwisted.internet.errorr   #twisted.internet.test.reactormixinsr   twisted.trial.unittestr   r   skiprg   reprrh   r   r   r   r   r   r   <module>   s:   

