o
    b
                     @   s   d Z ddlZddlZddlZdd Zeej ddlmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZ G d	d
 d
ZejfddZedkrJe  dS dS )zj
Implementation of C{AMP} worker commands, and main executable entry point for
the workers.

@since: 12.3
    Nc                 C   s*   d| v r| d  tjtjdd< dS dS )z
    Override C{sys.path} with what the parent passed in B{TRIAL_PYTHONPATH}.

    @see: twisted.trial._dist.disttrial.DistTrialRunner.launchWorkerProcesses
    TRIAL_PYTHONPATHN)splitospathsepsyspath)environ r	   A/usr/lib/python3/dist-packages/twisted/trial/_dist/workertrial.py
_setupPath   s   r   )FileWrapper)startLoggingWithObservertextFromEventDict)_WORKER_AMP_STDIN_WORKER_AMP_STDOUT)WorkerOptionsc                   @   s    e Zd ZdZdd Zdd ZdS )WorkerLogObserverzF
    A log observer that forward its output to a C{AMP} protocol.
    c                 C   s
   || _ dS )zg
        @param protocol: a connected C{AMP} protocol instance.
        @type protocol: C{AMP}
        N)protocol)selfr   r	   r	   r
   __init__*   s   
zWorkerLogObserver.__init__c                 C   s6   ddl m} t|}|du rdS | jj|j|d dS )z'
        Produce a log output.
        r   )managercommandsN)out)twisted.trial._distr   r   r   
callRemote	TestWrite)r   	eventDictr   textr	   r	   r
   emit1   s
   zWorkerLogObserver.emitN)__name__
__module____qualname____doc__r   r   r	   r	   r	   r
   r   %   s    r   c           
   
   C   s  t  }|  ddlm} ||d }| td}| td}|t| t|}t	|j
d 	 z|d}W n tyQ } z|jd tjkrLW Y d	}~q. d	}~ww |d
krWn|| |  tj  tj  q/|jrtd	 |j }	|	jdd| jd d	S d	S )z
    Main function to be run if __name__ == "__main__".

    @param _fdopen: If specified, the function to use in place of C{os.fdopen}.
    @type _fdopen: C{callable}
    r   )WorkerProtocolzforce-gcrbwbFT   N    )show_missingsummarycoverdir)r   parseOptionstwisted.trial._dist.workerr"   r   r   makeConnectionr   r   r   r   readOSErrorargserrnoEINTRdataReceivedflushr   stdoutstderrtracersettraceresultswrite_resultsr)   r   )
_fdopenconfigr"   workerProtocol
protocolInprotocolOutobserverrer8   r	   r	   r
   main=   s@   







rB   __main__)r!   r0   r   r   r   r   twisted.internet.protocolr   twisted.python.logr   r   r   r   r   twisted.trial._dist.optionsr   r   fdopenrB   r   r	   r	   r	   r
   <module>   s   

-
