Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/mail/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/twisted/mail/__pycache__/alias.cpython-310.pyc
o

�b�]�@sJdZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZddl
mZmZdd	�Zd d
d�ZGdd
�d
�Zee�Gdd�de��Zee
j�Gdd�d��Zee�Gdd�de��ZGdd�de�Zee
j�Gdd�d��ZGdd�dej�Zee�Gdd�de��Zee
j�Gdd�d��Zee�Gdd�de��ZdS)!zD
Support for aliases(5) configuration files.

@author: Jp Calderone
�N)�implementer)�defer�protocol�reactor)�smtp)�IAlias)�failure�logc	Cspdd�|�dd�D�}t|�dkr d}||f}t�||�dS|\}}|�|��g��ttj|�d���dS)	a�
    Parse a line from an aliases file.

    @type result: L{dict} mapping L{bytes} to L{list} of L{bytes}
    @param result: A dictionary mapping username to aliases to which
        the results of parsing the line are added.

    @type line: L{bytes}
    @param line: A line from an aliases file.

    @type filename: L{bytes}
    @param filename: The full or relative path to the aliases file.

    @type lineNo: L{int}
    @param lineNo: The position of the line within the aliases file.
    cS�g|]}|���qS���strip)�.0�prr�4/usr/lib/python3/dist-packages/twisted/mail/alias.py�
<listcomp>)�zhandle.<locals>.<listcomp>�:��z+Invalid format on line %d of alias file %s.�,N)	�split�lenr	�err�
setdefaultr
�extend�map�str)	�result�line�filename�lineNo�parts�fmt�arg�user�aliasrrr�handles(r'c
Cs�i}d}|durt|�}d}nt|dd�}d}d}z7|D],}|d7}|��}|���d	�r.q|�d
�s8|�d�r=||}q|rFt||||�|}qW|rP|��n|rX|��ww|rbt||||�|��D]\}}	t|	||�||<qf|S)a�
    Load a file containing email aliases.

    Lines in the file should be formatted like so::

         username: alias1, alias2, ..., aliasN

    Aliases beginning with a C{|} will be treated as programs, will be run, and
    the message will be written to their stdin.

    Aliases beginning with a C{:} will be treated as a file containing
    additional aliases for the username.

    Aliases beginning with a C{/} will be treated as the full pathname to a file
    to which the message will be appended.

    Aliases without a host part will be assumed to be addresses on localhost.

    If a username is specified multiple times, the aliases for each are joined
    together as if they had all been on one line.

    Lines beginning with a space or a tab are continuations of the previous
    line.

    Lines beginning with a C{#} are comments.

    @type domains: L{dict} mapping L{bytes} to L{IDomain} provider
    @param domains: A mapping of domain name to domain object.

    @type filename: L{bytes} or L{None}
    @param filename: The full or relative path to a file from which to load
        aliases. If omitted, the C{fp} parameter must be specified.

    @type fp: file-like object or L{None}
    @param fp: The file from which to load aliases. If specified,
        the C{filename} parameter is ignored.

    @rtype: L{dict} mapping L{bytes} to L{AliasGroup}
    @return: A mapping from username to group of aliases.
    FNT�namez	<unknown>r�r�#� �	)	�open�getattr�rstrip�lstrip�
startswithr'�close�items�
AliasGroup)
�domainsr �fprr2�i�prevr�u�arrr�
loadAliasFile3s>)
���
�r;c@s*eZdZdZdd�Zdd�Zd	dd�ZdS)
�	AliasBasez�
    The default base class for aliases.

    @ivar domains: See L{__init__}.

    @type original: L{Address}
    @ivar original: The original address being aliased.
    cCs||_t�|�|_dS)z�
        @type domains: L{dict} mapping L{bytes} to L{IDomain} provider
        @param domains: A mapping of domain name to domain object.

        @type original: L{bytes}
        @param original: The original address being aliased.
        N)r5r�Address�original)�selfr5r>rrr�__init__�szAliasBase.__init__cCs|j|jjS)z�
        Return the domain associated with original address.

        @rtype: L{IDomain} provider
        @return: The domain for the original address.
        )r5r>�domain�r?rrrrA��zAliasBase.domainNcCs0|duri}t|�|vrdSd|t|�<|��S�aY
        Map this alias to its ultimate destination.

        @type aliasmap: L{dict} mapping L{bytes} to L{AliasBase}
        @param aliasmap: A mapping of username to alias or group of aliases.

        @type memo: L{None} or L{dict} of L{AliasBase}
        @param memo: A record of the aliases already considered in the
            resolution process.  If provided, C{memo} is modified to include
            this alias.

        @rtype: L{IMessage <smtp.IMessage>} or L{None}
        @return: A message receiver for the ultimate destination or None for
            an invalid destination.
        N)r�createMessageReceiver�r?�aliasmap�memorrr�resolve�szAliasBase.resolve�N)�__name__�
__module__�__qualname__�__doc__r@rArIrrrrr<{s
		r<c@s8eZdZdZdd�Zdefdd�Zdd�Zdd
d�Zd	S)
�AddressAliasz�
    An alias which translates one email address into another.

    @type alias : L{Address}
    @ivar alias: The destination address.
    cGs"tj|g|�R�t�|�|_dS)aQ
        @type alias: L{Address}, L{User}, L{bytes} or object which can be
            converted into L{bytes}
        @param alias: The destination address.

        @type args: 2-L{tuple} of (0) L{dict} mapping L{bytes} to L{IDomain}
            provider, (1) L{bytes}
        @param args: Arguments for L{AliasBase.__init__}.
        N)r<r@rr=r&)r?r&�argsrrrr@�s
zAddressAlias.__init__�returncC�d|j�d�S)z�
        Build a string representation of this L{AddressAlias} instance.

        @rtype: L{bytes}
        @return: A string containing the destination address.
        z	<Address �>)r&rBrrr�__str__�rCzAddressAlias.__str__cCs|���t|j��S)z�
        Create a message receiver which delivers a message to
        the destination address.

        @rtype: L{IMessage <smtp.IMessage>} provider
        @return: A message receiver.
        )rA�existsrr&rBrrrrE�sz"AddressAlias.createMessageReceiverNcCs�|duri}t|�|vrdSd|t|�<z|���t�|jddd�|��WStjy/Ynw|jj|vr@||jj�||�SdSrD)	rrArUr�Userr&�SMTPBadRcpt�localrIrFrrrrI�s"�zAddressAlias.resolverJ)	rKrLrMrNr@rrTrErIrrrrrO�s
	
rOc@�>eZdZdZdd�Zdd�Zdd�Zdd	�Zd
efdd�Z	d
S)�FileWrappera
    A message receiver which delivers a message to a file.

    @type fp: file-like object
    @ivar fp: A file used for temporary storage of the message.

    @type finalname: L{bytes}
    @ivar finalname: The name of the file in which the message should be
        stored.
    cCst��|_||_dS)z�
        @type filename: L{bytes}
        @param filename: The name of the file in which the message should be
            stored.
        N)�tempfile�
TemporaryFiler6�	finalname)r?r rrrr@s

zFileWrapper.__init__cCs|j�|d�dS)z�
        Write a received line to the temporary file.

        @type line: L{bytes}
        @param line: A received line of the message.
        �
N)r6�write�r?rrrr�lineReceived�zFileWrapper.lineReceivedcCs�|j�dd�zt|jd�}Wntyt�t���YSw|�|�	|j�
��|j��Wd�n1s:wYt�|j�S)ac
        Handle end of message by writing the message to the file.

        @rtype: L{Deferred <defer.Deferred>} which successfully results in
            L{bytes}
        @return: A deferred which succeeds with the name of the file to which
            the message has been stored or fails if the message cannot be
            saved to the file.
        rr:N)
r6�seekr-r]�
BaseExceptionr�failr�Failurer_�readr2�succeed)r?�frrr�eomReceiveds
��zFileWrapper.eomReceivedcCs|j��d|_dS)zG
        Close the temporary file when the connection is lost.
        N)r6r2rBrrr�connectionLost-s

zFileWrapper.connectionLostrQcCrR)z�
        Build a string representation of this L{FileWrapper} instance.

        @rtype: L{bytes}
        @return: A string containing the file name of the message.
        z
<FileWrapper rS)r]rBrrrrT4rCzFileWrapper.__str__N�
rKrLrMrNr@rarjrkrrTrrrrrZ�s		rZc@s.eZdZdZdd�Zdefdd�Zdd�Zd	S)
�	FileAliasz_
    An alias which translates an address to a file.

    @ivar filename: See L{__init__}.
    cGstj|g|�R�||_dS)a"
        @type filename: L{bytes}
        @param filename: The name of the file in which to store the message.

        @type args: 2-L{tuple} of (0) L{dict} mapping L{bytes} to L{IDomain}
            provider, (1) L{bytes}
        @param args: Arguments for L{AliasBase.__init__}.
        N)r<r@r )r?r rPrrrr@Fs	
zFileAlias.__init__rQcCrR)z�
        Build a string representation of this L{FileAlias} instance.

        @rtype: L{bytes}
        @return: A string containing the name of the file.
        z<File rS)r rBrrrrTRrCzFileAlias.__str__cC�
t|j�S)z�
        Create a message receiver which delivers a message to the file.

        @rtype: L{FileWrapper}
        @return: A message receiver which writes a message to the file.
        )rZr rBrrrrE[�
zFileAlias.createMessageReceiverN)rKrLrMrNr@rrTrErrrrrm>s
	rmc@seZdZdZdS)�ProcessAliasTimeoutzb
    An error indicating that a timeout occurred while waiting for a process
    to complete.
    N)rKrLrMrNrrrrrpesrpc@s`eZdZdZdZdZdZeZddd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
defdd�ZdS)�MessageWrapperaF
    A message receiver which delivers a message to a child process.

    @type completionTimeout: L{int} or L{float}
    @ivar completionTimeout: The number of seconds to wait for the child
        process to exit before reporting the delivery as a failure.

    @type _timeoutCallID: L{None} or
        L{IDelayedCall <twisted.internet.interfaces.IDelayedCall>} provider
    @ivar _timeoutCallID: The call used to time out delivery, started when the
        connection to the child process is closed.

    @type done: L{bool}
    @ivar done: A flag indicating whether the child process has exited
        (C{True}) or not (C{False}).

    @type reactor: L{IReactorTime <twisted.internet.interfaces.IReactorTime>}
        provider
    @ivar reactor: A reactor which will be used to schedule timeouts.

    @ivar protocol: See L{__init__}.

    @type processName: L{bytes} or L{None}
    @ivar processName: The process name.

    @type completion: L{Deferred <defer.Deferred>}
    @ivar completion: The deferred which will be triggered by the protocol
        when the child process exits.
    F�<NcCsD||_||_t��|_|j|j_|j�|j�|dur ||_dSdS)a�
        @type protocol: L{ProcessAliasProtocol}
        @param protocol: The protocol associated with the child process.

        @type process: L{bytes} or L{None}
        @param process: The process name.

        @type reactor: L{None} or L{IReactorTime
            <twisted.internet.interfaces.IReactorTime>} provider
        @param reactor: A reactor which will be used to schedule timeouts.
        N)	�processNamerr�Deferred�
completion�onEnd�addBoth�
_processEndedr)r?r�processrrrrr@�s


�zMessageWrapper.__init__cCs(d|_|jdur|j��d|_dS|S)a�
        Record process termination and cancel the timeout call if it is active.

        @type result: L{Failure <failure.Failure>}
        @param result: The reason the child process terminated.

        @rtype: L{None} or L{Failure <failure.Failure>}
        @return: None, if the process end is expected, or the reason the child
            process terminated, if the process end is unexpected.
        TN)�done�_timeoutCallID�cancel)r?rrrrrx�s



zMessageWrapper._processEndedcCs |jrdS|jj�|d�dS)z�
        Write a received line to the child process.

        @type line: L{bytes}
        @param line: A received line of the message.
        Nr^)rzr�	transportr_r`rrrra�szMessageWrapper.lineReceivedcCs,|js|jj��|j�|j|j�|_|j	S)z�
        Disconnect from the child process and set up a timeout to wait for it
        to exit.

        @rtype: L{Deferred <defer.Deferred>}
        @return: A deferred which will be called back when the child process
            exits.
        )
rzrr}�loseConnectionr�	callLater�completionTimeout�_completionCancelr{rurBrrrrj�s	�zMessageWrapper.eomReceivedcCsDd|_|jj�d�td|j�d��}d|j_|j�t	�
|��dS)z�
        Handle the expiration of the timeout for the child process to exit by
        terminating the child process forcefully and issuing a failure to the
        L{completion} deferred.
        N�KILLzNo answer after z seconds)r{rr}�
signalProcessrpr�rvru�errbackrrf)r?�excrrrr��s
z MessageWrapper._completionCancelcCsdS)z9
        Ignore notification of lost connection.
        NrrBrrrrk�szMessageWrapper.connectionLostrQcCrR)z�
        Build a string representation of this L{MessageWrapper} instance.

        @rtype: L{bytes}
        @return: A string containing the name of the process.
        z<ProcessWrapper rS)rsrBrrrrT�rCzMessageWrapper.__str__�NN)rKrLrMrNrzr�r{rr@rxrarjr�rkrrTrrrrrqls
rqc@seZdZdZdZdd�ZdS)�ProcessAliasProtocolz�
    A process protocol which errbacks a deferred when the associated
    process ends.

    @type onEnd: L{None} or L{Deferred <defer.Deferred>}
    @ivar onEnd: If set, a deferred on which to errback when the process ends.
    NcCs|jdur
|j�|�dSdS)z�
        Call an errback.

        @type reason: L{Failure <failure.Failure>}
        @param reason: The reason the child process terminated.
        N)rvr�)r?�reasonrrr�processEnded�s
�z!ProcessAliasProtocol.processEnded)rKrLrMrNrvr�rrrrr��sr�c@s:eZdZdZeZdd�Zdefdd�Zdd�Zd	d
�Z	dS)�ProcessAliasa6
    An alias which is handled by the execution of a program.

    @type path: L{list} of L{bytes}
    @ivar path: The arguments to pass to the process. The first string is
        the executable's name.

    @type program: L{bytes}
    @ivar program: The path of the program to be executed.

    @type reactor: L{IReactorTime <twisted.internet.interfaces.IReactorTime>}
        and L{IReactorProcess <twisted.internet.interfaces.IReactorProcess>}
        provider
    @ivar reactor: A reactor which will be used to create and timeout the
        child process.
    cGs,tj|g|�R�|��|_|jd|_dS)aX
        @type path: L{bytes}
        @param path: The command to invoke the program consisting of the path
            to the executable followed by any arguments.

        @type args: 2-L{tuple} of (0) L{dict} mapping L{bytes} to L{IDomain}
            provider, (1) L{bytes}
        @param args: Arguments for L{AliasBase.__init__}.
        rN)r<r@r�path�program)r?r�rPrrrr@s
zProcessAlias.__init__rQcCrR)z�
        Build a string representation of this L{ProcessAlias} instance.

        @rtype: L{bytes}
        @return: A string containing the command used to invoke the process.
        z	<Process rS)r�rBrrrrT.rCzProcessAlias.__str__cCs|j�|||�S)aP
        Spawn a process.

        This wraps the L{spawnProcess
        <twisted.internet.interfaces.IReactorProcess.spawnProcess>} method on
        L{reactor} so that it can be customized for test purposes.

        @type proto: L{IProcessProtocol
            <twisted.internet.interfaces.IProcessProtocol>} provider
        @param proto: An object which will be notified of all events related to
            the created process.

        @type program: L{bytes}
        @param program: The full path name of the file to execute.

        @type path: L{list} of L{bytes}
        @param path: The arguments to pass to the process. The first string
            should be the executable's name.

        @rtype: L{IProcessTransport
            <twisted.internet.interfaces.IProcessTransport>} provider
        @return: A process transport.
        )r�spawnProcess)r?�protor�r�rrrr�7szProcessAlias.spawnProcesscCs,t�}t||j|j�}|�||j|j�|S)z�
        Launch a process and create a message receiver to pass a message
        to the process.

        @rtype: L{MessageWrapper}
        @return: A message receiver which delivers a message to the process.
        )r�rqr�rr�r�)r?r�mrrrrEQsz"ProcessAlias.createMessageReceiverN)
rKrLrMrNrr@rrTr�rErrrrr�
s	r�c@rY)�MultiWrapperz�
    A message receiver which delivers a single message to multiple other
    message receivers.

    @ivar objs: See L{__init__}.
    cCs
||_dS)z�
        @type objs: L{list} of L{IMessage <smtp.IMessage>} provider
        @param objs: Message receivers to which the incoming message should be
            directed.
        N)�objs)r?r�rrrr@hs
zMultiWrapper.__init__cCs|jD]}|�|�qdS)z�
        Pass a received line to the message receivers.

        @type line: L{bytes}
        @param line: A line of the message.
        N)r�ra)r?r�orrrraps
�zMultiWrapper.lineReceivedcCst�dd�|jD��S)aG
        Pass the end of message along to the message receivers.

        @rtype: L{DeferredList <defer.DeferredList>} whose successful results
            are L{bytes} or L{None}
        @return: A deferred list which triggers when all of the message
            receivers have finished handling their end of message.
        cSr
r)rj)rr�rrrr�rz,MultiWrapper.eomReceived.<locals>.<listcomp>)r�DeferredListr�rBrrrrjzs	zMultiWrapper.eomReceivedcCs|jD]}|��qdS)zQ
        Inform the message receivers that the connection has been lost.
        N)r�rk)r?r�rrrrk�s

�zMultiWrapper.connectionLostrQcCsdtt|j��d�S)z�
        Build a string representation of this L{MultiWrapper} instance.

        @rtype: L{bytes}
        @return: A string containing a list of the message receivers.
        z<GroupWrapper rS)rrr�rBrrrrT�rbzMultiWrapper.__str__Nrlrrrrr�_s
r�c@sDeZdZdZeZdd�Zdd�Zdefdd�Z	d	d
�Z
ddd
�ZdS)r4aL
    An alias which points to multiple destination aliases.

    @type processAliasFactory: no-argument callable which returns
        L{ProcessAlias}
    @ivar processAliasFactory: A factory for process aliases.

    @type aliases: L{list} of L{AliasBase} which implements L{IAlias}
    @ivar aliases: The destination aliases.
    c	GsJtj|g|�R�g|_|r�|����}|�d�r^z
t|dd��}Wnty8t�	d|dd����Yngw|�d�
dd�|D��}Wd�n1sPwY|�|�d��nA|�d	�ru|j�
|j|dd�g|�R��n*|�d
�r�tj�|�r�t�	d�n|j�
t|g|�R��n|j�
t|g|�R��|sdSdS)a�
        Create a group of aliases.

        Parse a list of alias strings and, for each, create an appropriate
        alias object.

        @type items: L{list} of L{bytes}
        @param items: Aliases.

        @type args: n-L{tuple} of (0) L{dict} mapping L{bytes} to L{IDomain}
            provider, (1) L{bytes}
        @param args: Arguments for L{AliasBase.__init__}.
        rrNzInvalid filename in alias file r+cSr
rr)r�lrrrr�rz'AliasGroup.__init__.<locals>.<listcomp>r�|�/z Directory delivery not supported)r<r@�aliases�popr
r1r-rdr	r�joinrr�append�processAliasFactory�osr��isdirrmrO)r?r3rP�addrrirrrr@�s,
��
$
�zAliasGroup.__init__cCrn)z�
        Return the number of aliases in the group.

        @rtype: L{int}
        @return: The number of aliases in the group.
        )rr�rBrrr�__len__�rozAliasGroup.__len__rQcCsdd�tt|j��S)z�
        Build a string representation of this L{AliasGroup} instance.

        @rtype: L{bytes}
        @return: A string containing the aliases in the group.
        z<AliasGroup [%s]>z, )r�rrr�rBrrrrT�szAliasGroup.__str__cCstdd�|jD��S)a,
        Create a message receiver for each alias and return a message receiver
        which will pass on a message to each of those.

        @rtype: L{MultiWrapper}
        @return: A message receiver which passes a message on to message
            receivers for each alias in the group.
        cSr
r)rE)rr:rrrr�rz4AliasGroup.createMessageReceiver.<locals>.<listcomp>)r�r�rBrrrrE�s	z AliasGroup.createMessageReceiverNcCs<|duri}g}|jD]}|�|�||��qttd|��S)a�
        Map each of the aliases in the group to its ultimate destination.

        @type aliasmap: L{dict} mapping L{bytes} to L{AliasBase}
        @param aliasmap: A mapping of username to alias or group of aliases.

        @type memo: L{None} or L{dict} of L{AliasBase}
        @param memo: A record of the aliases already considered in the
            resolution process.  If provided, C{memo} is modified to include
            this alias.

        @rtype: L{MultiWrapper}
        @return: A message receiver which passes the message on to message
            receivers for the ultimate destination of each alias in the group.
        N)r�r�rIr��filter)r?rGrH�rr:rrrrI�s
zAliasGroup.resolverJ)rKrLrMrNr�r�r@r�rrTrErIrrrrr4�s&		r4r�)rNr�r[�zope.interfacer�twisted.internetrrr�twisted.mailr�twisted.mail.interfacesr�twisted.pythonrr	r'r;r<rO�IMessagerZrm�	Exceptionrprq�ProcessProtocolr�r�r�r4rrrr�<module>s8
H6FE&T6

Spamworldpro Mini