
    Vh                       d Z ddlmZ ddlmZ 	 ddlmZ dZddlm	Z	 ddl
mZmZ ddlmZ dd	Zd
j!                  d  e	j"                  dd      j%                  d      D              Z ed      ZeeneZddlmZ ddlmZ ddlmZmZ esdZedu xs edvZd e e       Z!esddlm"Z"  G d dee      Z#y# e$ r dZdZY Mw xY w)z\
GObject Introspection reactor tests; i.e. `gireactor` module for gio/glib/gtk
integration.
    )annotations)skipIf)GioT)environ)get_required_versionrequire_version)	gireactorc                `    	 t        d|        y# t        $ r}t        |      cY d }~S d }~ww xY w)NGtk )r   
ValueErrorstr)someVersionves     T/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/test/test_gireactor.pyrequireEachr      s1    	E;/   	r7N	s    	-
(--z, c              #  2   K   | ]  }t        |        y w)N)r   ).0versions     r   	<genexpr>r   "   s       	Gs   TWISTED_TEST_GTK_VERSIONz4.0,3.0,r   NF)ReactorAlreadyRunning)ReactorBuilder)SkipTestTestCasez0GObject Introspection `gi` module not importable)z3.0z4.0zUnknown GTK version: )r   c                      e Zd ZdZ	 	 	 	 	 	 ddZddZ eee      dd       Z	 eee      dd       Z
ddZddZddZdd	Zy
)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.
    c                   t        |d      st        d      g d	fdd
fd}|j                  d|       |j                          j	                  |       t        j                  |        | j                  ddg       y)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.c                 H    j                  d        j                          y )Nstopped)appendstop)reactorresults   r   r$   z6GApplicationRegistrationTests.runReactor.<locals>.stopR   s    MM)$LLN    c                L    j                  d       j                  d       y )N	activatedr   )r#   	callLater)widgetr%   r&   r$   s    r   activatez:GApplicationRegistrationTests.runReactor.<locals>.activateV   s    MM+&a&r'   r,   r)   r"   NreturnNone)r+   objectr.   r/   )hasattrr   connectholdregisterGApplicationr   
runReactorassertEqual)selfappr%   r,   r&   r$   s     ` @@r   r5   z(GApplicationRegistrationTests.runReactorD   sx     sF#=>>		' 	J) 	
$$S)!!$0+y!9:r'   c                    d | _         | j                         }t        j                  dt        j                  j
                        }| j                  ||       y)zR
        L{Gio.Application} instances can be registered with a gireactor.
        c                 .    t        j                  d      S NF)useGtkr	   	GIReactor r'   r   <lambda>zIGApplicationRegistrationTests.test_gApplicationActivate.<locals>.<lambda>j       i&9&9&G r'   !com.twistedmatrix.trial.gireactorapplication_idflagsN)reactorFactorybuildReactorr   ApplicationApplicationFlags
FLAGS_NONEr5   r7   r%   r8   s      r   test_gApplicationActivatez7GApplicationRegistrationTests.test_gApplicationActivatef   sK     H##%oo>&&11

 	W%r'   c                ^   ddl m}m}m} | j	                  |t
        j                         | j	                  |t
        j                         | j	                  |t
        j                         | j                         }| j                  t        |      d       | j                  d|d   d          y)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.gtk3reactorrN   rO   rP   assertIsr	   r>   PortableGIReactorflushWarningsr6   lenassertIn)r7   rN   rO   rP   warningss        r   test_gtkAliasesz-GApplicationRegistrationTests.test_gtkAliasess   s    	
 	
 	k9#6#67)9+F+FGgy001%%'X*98A;y;Q	
r'   c                    t         j                  | _        | j                         }t	        j
                  dt        j                  j                        }| j                  ||       y)zT
        L{Gtk.Application} instances can be registered with a gtk3reactor.
        z#com.twistedmatrix.trial.gtk3reactorrC   N)
r	   r>   rF   rG   r   rH   r   rI   rJ   r5   rK   s      r   test_gtkApplicationActivatez9GApplicationRegistrationTests.test_gtkApplicationActivate   sP    
 (11##%oo@&&11
 	W%r'   c                    t         j                  | _        | j                         }t	        j
                  dt        j                  j                        }| j                  t        |j                  |       y)zo
        L{gireactor.PortableGIReactor} doesn't support application
        registration at this time.
        rB   rC   N)r	   rU   rF   rG   r   rH   rI   rJ   assertRaisesNotImplementedErrorr4   rK   s      r   test_portablez+GApplicationRegistrationTests.test_portable   s[    
 (99##%oo>&&11
 	-w/K/KSQr'   c                    d | _         | j                         }t               }| j                  t        |j
                  |      }| j                  |j                  d   j                  d             y)zp
        Older versions of PyGObject lack C{Application.quit}, and so won't
        allow registration.
        c                 .    t        j                  d      S r;   r=   r?   r'   r   r@   z;GApplicationRegistrationTests.test_noQuit.<locals>.<lambda>   rA   r'   r   zApplication registration is notN)	rF   rG   r0   r^   RuntimeErrorr4   
assertTrueargs
startswith)r7   r%   r8   excs       r   test_noQuitz)GApplicationRegistrationTests.test_noQuit   s\    
 H##%hg.J.JCP../PQRr'   c                     d  _          j                         t        j                  dt        j                  j
                        d fd}j                  d|       t        j                          y)zp
        It is not possible to register a C{Application} after the reactor has
        already started.
        c                 .    t        j                  d      S r;   r=   r?   r'   r   r@   zIGApplicationRegistrationTests.test_cantRegisterAfterRun.<locals>.<lambda>   rA   r'   rB   rC   c                     j                  t        j                        } j                  | j                  d   d       j                          y )Nr   z5Can't register application after reactor was started.)r^   r   r4   r6   re   r$   )rg   r8   r%   r7   s    r   tryRegisterzLGApplicationRegistrationTests.test_cantRegisterAfterRun.<locals>.tryRegister   sI    ##%w'C'CSC T LLNr'   r   Nr-   )	rF   rG   r   rH   rI   rJ   r*   r   r5   )r7   rl   r8   r%   s   ` @@r   test_cantRegisterAfterRunz7GApplicationRegistrationTests.test_cantRegisterAfterRun   sc    
 H##%oo>&&11

	 	![)!!$0r'   c                   d | _         | j                         }t        j                  dt        j                  j
                        }|j                  |       t        j                  dt        j                  j
                        }| j                  t        |j                  |      }| j                  |j                  d   d       y)zN
        It is not possible to register more than one C{Application}.
        c                 .    t        j                  d      S r;   r=   r?   r'   r   r@   zFGApplicationRegistrationTests.test_cantRegisterTwice.<locals>.<lambda>   rA   r'   rB   rC   z"com.twistedmatrix.trial.gireactor2r   z2Can't register more than one application instance.N)rF   rG   r   rH   rI   rJ   r4   r^   rc   r6   re   )r7   r%   r8   app2rg   s        r   test_cantRegisterTwicez4GApplicationRegistrationTests.test_cantRegisterTwice   s     H##%oo>&&11
 	$$S)?&&11
 g.J.JDQHHQKM	
r'   N)r8   zGio.Applicationr%   zgireactor.GIReactorr.   r/   r-   )__name__
__module____qualname____doc__r5   rL   r   	noGtkSkipnoGtkMessagerZ   r\   r`   rh   rm   rq   r?   r'   r   r   r   :   sz     ; ; % ; 
	 ;D& I|$
 %
( I|$
& %
&R
S10
r'   r   )r   r   r.   r   )$ru   
__future__r   unittestr   gi.repositoryr   
giImportedosr   gir   r   twisted.internetr	   r   joingetspliterrorMessageactualVersion
gtkVersionImportErrortwisted.internet.errorr   #twisted.internet.test.reactormixinsr   twisted.trial.unittestr   r   skiprv   reprrw   r   r   r?   r'   r   <module>r      s    # N!
 J8* 99 "w{{#=yIOOPST L
 )/M"/";J 9 > 5 =D4FZ~%E	&tJ'7&89!^
NH ^
Y  JJs   B8 8	CC