HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_gireactor.cpython-38.pyc
U


W[R#�@sXdZddlmZmZmZddlZddlZzddlmZddl	m
Z
Wnek
r`dZdZYn8XzddlmZWnek
r�dZYnXddl	m
Z
ddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZmZddlmZddlmZddlm Z ddl!m"Z"edk�r"dZ#Gdd�dee�Z$Gdd�de�Z%Gdd�de�Z&dS)z
GI/GTK3 reactor tests.
�)�division�absolute_import�print_functionN)�	gireactor)�Gio)�gtk3reactor)�Gtk)�FilePath)�platform)�Deferred)�ReactorAlreadyRunning)�ProcessProtocol)�TestCase�SkipTest)�ReactorBuilder)�SetAsideModule)�IReactorProcess)�_PY3zgtk3/gi not importablec@sVeZdZdZdd�Zdd�Zdd�Zedkr2d	e_d
d�Z	dd
�Z
dd�Zdd�ZdS)�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.
    csrt|d�std��g���fdd�����fdd�}|�d|�|����|�t�|��|��dd	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.cs��d����dS)N�stopped)�append�stop�)�reactor�resultr�F/usr/lib/python3/dist-packages/twisted/internet/test/test_gireactor.pyr>s
z6GApplicationRegistrationTests.runReactor.<locals>.stopcs��d���d��dS)N�	activatedr)r�	callLater)Zwidget�rrrrr�activateAs
z:GApplicationRegistrationTests.runReactor.<locals>.activater rrN)�hasattrrZconnectZhold�registerGApplicationr�
runReactor�assertEqual)�self�apprr rrrr#5s

z(GApplicationRegistrationTests.runReactorcCs<tjdd�}|�|j|�tjdtjjd�}|�||�dS)zR
        L{Gio.Application} instances can be registered with a gireactor.
        F�ZuseGtk�!com.twistedmatrix.trial.gireactor�Zapplication_id�flagsN)	r�	GIReactor�
addCleanup�unbuildReactorr�Application�ApplicationFlags�
FLAGS_NONEr#�r%rr&rrr�test_gApplicationActivateQs�z7GApplicationRegistrationTests.test_gApplicationActivatecCs8t��}|�|j|�tjdtjjd�}|�	||�dS)zT
        L{Gtk.Application} instances can be registered with a gtk3reactor.
        z#com.twistedmatrix.trial.gtk3reactorr)N)
rZGtk3Reactorr,r-rr.rr/r0r#r1rrr�test_gtkApplicationActivate^s�z9GApplicationRegistrationTests.test_gtkApplicationActivateNz>Gtk unavailable (may require running with X11 DISPLAY env set)cCs<t��}|�|j|�tjdtjjd�}|�t	|j
|�dS)zo
        L{gireactor.PortableGIReactor} doesn't support application
        registration at this time.
        r(r)N)rZPortableGIReactorr,r-rr.r/r0�assertRaises�NotImplementedErrorr"r1rrr�
test_portableos��z+GApplicationRegistrationTests.test_portablecCsJtjdd�}|�|j|�t�}|�t|j|�}|�|j	d�
d��dS)zp
        Older versions of PyGObject lack C{Application.quit}, and so won't
        allow registration.
        Fr'rzApplication registration is notN)rr+r,r-�objectr4�RuntimeErrorr"�
assertTrue�args�
startswith)r%rr&�excrrr�test_noQuit}s�z)GApplicationRegistrationTests.test_noQuitcsXtjdd�����j��tjdtjjd�����fdd�}��d|�t	�
���dS)	zp
        It is not possible to register a C{Application} after the reactor has
        already started.
        Fr'r(r)cs.��t�j��}��|jdd����dS)Nrz5Can't register application after reactor was started.)r4rr"r$r:r)r<�r&rr%rr�tryRegister�s��zLGApplicationRegistrationTests.test_cantRegisterAfterRun.<locals>.tryRegisterrN)rr+r,r-rr.r/r0rrr#)r%r?rr>r�test_cantRegisterAfterRun�s�z7GApplicationRegistrationTests.test_cantRegisterAfterRuncCsntjdd�}|�|j|�tjdtjjd�}|�|�tjdtjjd�}|�	t
|j|�}|�|jdd�dS)	zN
        It is not possible to register more than one C{Application}.
        Fr'r(r)z"com.twistedmatrix.trial.gireactor2rz2Can't register more than one application instance.N)
rr+r,r-rr.r/r0r"r4r8r$r:)r%rr&Zapp2r<rrr�test_cantRegisterTwice�s$�
���z4GApplicationRegistrationTests.test_cantRegisterTwice)
�__name__�
__module__�__qualname__�__doc__r#r2r3r�skipr6r=r@rArrrrr,s
�rc@s eZdZdZdd�Zdd�ZdS)�PygtkCompatibilityTestsz_
    pygtk imports are either prevented, or a compatibility layer is used if
    possible.
    cs�trtd��ddlm}t�|�s*td��t��G�fdd�dt�}tt	��
d�j}ttj
���}|j|�|||gdd	�tj�id
���|jd��S)z�
        If no compatibility layer is present, imports of gobject and friends
        are disallowed.

        We do this by running a process where we make sure gi.pygtkcompat
        isn't present.
        z+Python3 always has the compatibility layer.r)rz-No process support available in this reactor.cs,eZdZdZdd�Zdd�Z�fdd�ZdS)	zAPygtkCompatibilityTests.test_noCompatibilityLayer.<locals>.Stdout�cSst|�dS�N)�print)r%�errrrr�errReceived�szMPygtkCompatibilityTests.test_noCompatibilityLayer.<locals>.Stdout.errReceivedcSs|j|7_dSrI)�data)r%rMrrr�outReceived�szMPygtkCompatibilityTests.test_noCompatibilityLayer.<locals>.Stdout.outReceivedcs��|j�dSrI)�callbackrM)r%�reason�rrr�
processExited�szOPygtkCompatibilityTests.test_noCompatibilityLayer.<locals>.Stdout.processExitedN)rBrCrDrMrLrNrRrrQrr�Stdout�srSsprocess_gireactornocompat.py�
PYTHONPATH�:)�envssuccess)rr�twisted.internetrrZ
providedByrr
r	�__file__Zsibling�path�sys�
executableZ_asBytesPathZspawnProcess�joinZaddCallbackr$)r%rrSrYZpyExerrQr�test_noCompatibilityLayer�s
�z1PygtkCompatibilityTests.test_noCompatibilityLayercCs0dtjkrtd��ddl}|�|j�d��dS)zo
        If compatibility layer is present, importing gobject uses the gi
        compatibility layer.
        zgi.pygtkcompatz/This version of gi doesn't include pygtkcompat.rNzgi.)rZ�modulesr�gobjectr9rBr;)r%r_rrr�test_compatibilityLayer�s
z/PygtkCompatibilityTests.test_compatibilityLayerN)rBrCrDrEr]r`rrrrrG�s&rGc@s2eZdZdZdd�Ze��dks(e��r.de_dS)�Gtk3ReactorTestsz#
    Tests for L{gtk3reactor}.
    c	Cshtj�dd�}|dk	r0|�tjjd|�tjd=td��&|�ttd�}|�	|j
dd�W5QRXdS)zs
        On X11, L{gtk3reactor} is unimportable if the C{DISPLAY} environment
        variable is not set.
        ZDISPLAYNztwisted.internet.gtk3reactorrz=Gtk3 requires X11, and no DISPLAY environment variable is set)�os�environ�getr,�__setitem__rr4�ImportError�
__import__r$r:)r%Zdisplayr<rrr�test_requiresDISPLAY�s
��z%Gtk3ReactorTests.test_requiresDISPLAY�posixz)This test is only relevant when using X11N)	rBrCrDrErhr
ZgetTypeZisMacOSXrFrrrrra�sra)'rEZ
__future__rrrrZrbrWrZ
gi.repositoryrrfrrZtwisted.python.filepathr	Ztwisted.python.runtimer
Ztwisted.internet.deferrZtwisted.internet.errorrZtwisted.internet.protocolr
Ztwisted.trial.unittestrrZ#twisted.internet.test.reactormixinsrZtwisted.test.test_twistedrZtwisted.internet.interfacesrZtwisted.python.compatrrFrrGrarrrr�<module>s:


	7