
    Yf                       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                    d  e	j        dd                              d          D                       Z ed          ZeeneZn# e$ r dZdZY nw xY wddlmZ ddlmZ ddlmZmZ esdZedu pedvZd e e           Z!esddlm"Z"  G d dee          Z#dS )z\
GObject Introspection reactor tests; i.e. `gireactor` module for gio/glib/gtk
integration.
    )annotations)skipIf)GioT)environ)get_required_versionrequire_version)	gireactorsomeVersionstrreturnc                t    	 t          d|            dS # t          $ r}t          |          cY d }~S d }~ww xY w)NGtk )r   
ValueErrorr   )r
   ves     V/var/www/html/env/lib/python3.11/site-packages/twisted/internet/test/test_gireactor.pyrequireEachr      sT    	E;/// 2  	 	 	r77NNNNNN	s    
7277z, c              #  4   K   | ]}t          |          V  d S )N)r   ).0versions     r   	<genexpr>r   "   s>         	G         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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                D   t          |d          st          d          g dfddfd}|                    d	|           |                                                     |           t          j        |            |                     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                 Z                         d                                             d S )Nstopped)appendstop)r#   results   r   r+   z6GApplicationRegistrationTests.runReactor.<locals>.stopR   s&    MM)$$$LLNNNNNr   widgetobjectc                ^                         d                               d           d S )N	activatedr   )r*   	callLater)r-   r#   r,   r+   s    r   activatez:GApplicationRegistrationTests.runReactor.<locals>.activateV   s1    MM+&&&a&&&&&r   r2   r0   r)   Nr   r%   )r-   r.   r   r%   )hasattrr   connectholdregisterGApplicationr   
runReactorassertEqual)selfr!   r#   r2   r,   r+   s     ` @@r   r8   z(GApplicationRegistrationTests.runReactorD   s     sF## 	?=>>>	 	 	 	 	 	 		' 	' 	' 	' 	' 	' 	' 	' 	J))) 	


$$S)))!$000+y!9:::::r   c                    d | _         |                                 }t          j        dt          j        j                  }|                     ||           dS )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&G&G&G r   !com.twistedmatrix.trial.gireactorapplication_idflagsN)reactorFactorybuildReactorr   ApplicationApplicationFlags
FLAGS_NONEr8   r:   r#   r!   s      r   test_gApplicationActivatez7GApplicationRegistrationTests.test_gApplicationActivatef   s_     HG##%%o>&1
 
 

 	W%%%%%r   c                   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.gtk3reactorrP   rQ   rR   assertIsr	   r@   PortableGIReactorflushWarningsr9   lenassertIn)r:   rP   rQ   rR   warningss        r   test_gtkAliasesz-GApplicationRegistrationTests.test_gtkAliasess   s    	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	k9#6777)9+FGGGgy0111%%''X***98A;y;Q	
 	
 	
 	
 	
r   c                    t           j        | _        |                                 }t	          j        dt          j        j                  }| 	                    ||           dS )zT
        L{Gtk.Application} instances can be registered with a gtk3reactor.
        z#com.twistedmatrix.trial.gtk3reactorrE   N)
r	   r@   rH   rI   r   rJ   r   rK   rL   r8   rM   s      r   test_gtkApplicationActivatez9GApplicationRegistrationTests.test_gtkApplicationActivate   s^    
 (1##%%o@&1
 
 
 	W%%%%%r   c                    t           j        | _        |                                 }t	          j        dt          j        j                  }|                     t          |j
        |           dS )zo
        L{gireactor.PortableGIReactor} doesn't support application
        registration at this time.
        rD   rE   N)r	   rW   rH   rI   r   rJ   rK   rL   assertRaisesNotImplementedErrorr7   rM   s      r   test_portablez+GApplicationRegistrationTests.test_portable   sf    
 (9##%%o>&1
 
 
 	-w/KSQQQQQr   c                   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                 ,    t          j        d          S r=   r?   rA   r   r   rB   z;GApplicationRegistrationTests.test_noQuit.<locals>.<lambda>   rC   r   r   zApplication registration is notN)	rH   rI   r.   r`   RuntimeErrorr7   
assertTrueargs
startswith)r:   r#   r!   excs       r   test_noQuitz)GApplicationRegistrationTests.test_noQuit   sq    
 HG##%%hhg.JCPP../PQQRRRRRr   c                     d  _                                          t          j        dt          j        j                  d	 fd}                    d|           t          j                    dS )
zp
        It is not possible to register a C{Application} after the reactor has
        already started.
        c                 ,    t          j        d          S r=   r?   rA   r   r   rB   zIGApplicationRegistrationTests.test_cantRegisterAfterRun.<locals>.<lambda>   rC   r   rD   rE   r   r%   c                                          t          j                  }                     | j        d         d                                            d S )Nr   z5Can't register application after reactor was started.)r`   r   r7   r9   rg   r+   )ri   r!   r#   r:   s    r   tryRegisterzLGApplicationRegistrationTests.test_cantRegisterAfterRun.<locals>.tryRegister   s[    ##%w'CS C T   LLNNNNNr   r   Nr3   )	rH   rI   r   rJ   rK   rL   r1   r   r8   )r:   rn   r!   r#   s   ` @@r   test_cantRegisterAfterRunz7GApplicationRegistrationTests.test_cantRegisterAfterRun   s    
 HG##%%o>&1
 
 

	 	 	 	 	 	 	 	 	![)))!$00000r   c                   d | _         |                                 }t          j        dt          j        j                  }|                    |           t          j        dt          j        j                  }|                     t          |j        |          }| 	                    |j
        d         d           dS )zN
        It is not possible to register more than one C{Application}.
        c                 ,    t          j        d          S r=   r?   rA   r   r   rB   zFGApplicationRegistrationTests.test_cantRegisterTwice.<locals>.<lambda>   rC   r   rD   rE   z"com.twistedmatrix.trial.gireactor2r   z2Can't register more than one application instance.N)rH   rI   r   rJ   rK   rL   r7   r`   re   r9   rg   )r:   r#   r!   app2ri   s        r   test_cantRegisterTwicez4GApplicationRegistrationTests.test_cantRegisterTwice   s     HG##%%o>&1
 
 
 	$$S)))?&1
 
 
 g.JDQQHQKM	
 	
 	
 	
 	
r   N)r!   r"   r#   r$   r   r%   r3   )__name__
__module____qualname____doc__r8   rN   r   	noGtkSkipnoGtkMessager\   r^   rb   rj   ro   rs   rA   r   r   r    r    :   s          ;  ;  ;  ;D& & & & VI|$$
 
 
 %$
( VI|$$
& 
& 
& %$
&R R R R
S 
S 
S 
S1 1 1 10
 
 
 
 
 
r   r    )r
   r   r   r   )$rw   
__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   skiprx   reprry   r   r    rA   r   r   <module>r      s    # " " " " "      N!!!!!!
 J88888888******    99  "w{#=yIIOOPSTT    L
 )(//M"/";JJ5    JJJJ: 9 8 8 8 8 8 > > > > > > 5 5 5 5 5 5 5 5  >=D4FZ~%E	9ttJ'7'799 "!!!!!!^
 ^
 ^
 ^
 ^
NH ^
 ^
 ^
 ^
 ^
s   B 	BB