
    zh                     *   d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	 ddl
mZ ddlmZmZ dZ G d	 d
e          Z G d de	j                  Z G d d          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )aK  
Copyright 2009-2010 Mozes, Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
    N)SSL)ClientFactory)deferreactorssl)Service)SMPPClientProtocolDataHandlerResponsezsmpp.twisted.clientc                   *    e Zd ZeZd Zd Zd Zd ZdS )SMPPClientFactoryc                     || _         t          j                    | _        t	          j        t                    | _        d S N)configr   DeferredbuildProtocolDeferredlogging	getLoggerLOG_CATEGORYlogselfr   s     c/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/smpp/twisted/client.py__init__zSMPPClientFactory.__init__   s/    %*^%5%5"$\22    c                     | j         S r   )r   r   s    r   	getConfigzSMPPClientFactory.getConfig"   s
    {r   c                 p    t          j        | |          }t          j        d| j        j        |           |S )Nr   )r   buildProtocolr   	callLaterr   callback)r   addrps      r   r   zSMPPClientFactory.buildProtocol%   s6    'd33 	!T7@!DDDr   c                     | j                             dt          |          z             | j                            |           dS )zConnection failed
        zConnection failed. Reason: %sN)r   errorstrr   errback)r   	connectorreasons      r   clientConnectionFailedz(SMPPClientFactory.clientConnectionFailed,   sA     	6VDEEE"**622222r   N)	__name__
__module____qualname__r	   protocolr   r   r   r*    r   r   r   r      sU        !H3 3 3
    3 3 3 3 3r   r   c                       e Zd Zd Zd ZdS )
CtxFactoryc                     || _         d S r   )
smppConfigr   s     r   r   zCtxFactory.__init__4   s     r   c                     t           j        | _        t          j                            |           }| j        j        r|                    | j        j                   |S r   )	r   SSLv23_METHODmethodr   ClientContextFactory
getContextr3   SSLCertificateFileuse_certificate_file)r   ctxs     r   r8   zCtxFactory.getContext7   sN    '&11$77?- 	I$$T_%GHHH
r   N)r+   r,   r-   r   r8   r/   r   r   r1   r1   2   s2        ! ! !    r   r1   c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 ZdS )
SMPPClientBaseNc                 l    || _         t          j        t                    | _        d | _        d | _        d S r   )r   r   r   r   r   smppbindDeferredr   s     r   r   zSMPPClientBase.__init__A   s0    $\22	 r   c                    t          | j                  }| j        j        rq| j                            d| j        j        | j        j        fz             t          j        | j        j        | j        j        |t          | j                             n]| j                            d| j        j        | j        j        fz             t          j
        | j        j        | j        j        |           |j                            | j                  S )Nz$Establishing SSL connection to %s:%dz$Establishing TCP connection to %s:%d)r   r   useSSLr   warninghostportr   
connectSSLr1   
connectTCPr   addCallback	onConnect)r   factorys     r   connectzSMPPClientBase.connectG   s    #DK00; 	LHCt{GWY]YdYiFjjkkkt{/1A7JW[WbLcLcddddHCt{GWY]YdYiFjjkkkt{/1A7KKK,88HHHr   c                 V    || _         | j        |                    | j                   |S r   )r?   
msgHandlersetDataRequestHandlerr   r?   s     r   rI   zSMPPClientBase.onConnectS   s,    	?&&&t777r   c                     t          j                    | _        |                                                     | j                                      | j        j                   | j        S r   )r   r   r@   rK   rH   doBind
addErrbackr'   r   s    r   connectAndBindzSMPPClientBase.connectAndBindY   sM    !N,,""4;//::4;L;TUUU  r   c                     |                      |                              | j                                      | j        |           |S r   )bindrH   boundrR   
bindFailedrO   s     r   rQ   zSMPPClientBase.doBind^   s9    		$##DJ//::4?DQQQr   c                     t                      r   )NotImplementedErrorrO   s     r   rU   zSMPPClientBase.bindb   s    !###r   c                 `     |                                                      fd           d S )Nc                 8    j                                       S r   )r@   r'   )resultr%   r   s    r   <lambda>z+SMPPClientBase.bindFailed.<locals>.<lambda>g   s    $BSB[B[\aBbBb r   )getDisconnectedDeferredrH   )r   r%   r?   s   `` r   rW   zSMPPClientBase.bindFailedf   s7    $$&&223b3b3b3b3bcccccr   c                 D    | j                             |j                   d S r   )r@   r!   r?   )r   r\   s     r   rV   zSMPPClientBase.boundi   s!    ""6;/////r   )r+   r,   r-   rM   r   rK   rI   rS   rQ   rU   rW   rV   r/   r   r   r=   r=   >   s        J! ! !
I 
I 
I  ! ! !
  $ $ $d d d0 0 0 0 0r   r=   c                       e Zd Zd ZdS )SMPPClientTransmitterc                 *    |                                 S r   )bindAsTransmitterrO   s     r   rU   zSMPPClientTransmitter.bindn   s    %%'''r   Nr+   r,   r-   rU   r/   r   r   ra   ra   l   s#        ( ( ( ( (r   ra   c                       e Zd Zd Zd ZdS )SMPPClientReceiverc                 J    t                               | |           || _        d S r   )r=   r   rM   )r   r   rM   s      r   r   zSMPPClientReceiver.__init__s   s#    f---$r   c                 6    |                     | j                  S r   )bindAsReceiverrM   rO   s     r   rU   zSMPPClientReceiver.bindw   s    ""4?333r   N)r+   r,   r-   r   rU   r/   r   r   rf   rf   q   s2        % % %4 4 4 4 4r   rf   c                       e Zd Zd ZdS )SMPPClientTransceiverc                 6    |                     | j                  S r   )bindAsTransceiverrM   rO   s     r   rU   zSMPPClientTransceiver.bind|   s    %%do666r   Nrd   r/   r   r   rk   rk   z   s#        7 7 7 7 7r   rk   c                   F    e Zd Zd Zd Zej        d             Zd Zd Z	dS )SMPPClientServicec                     || _         t          j                    | _        t	          j        t                    | _        d S r   )clientr   r   stopDeferredr   r   r   r   )r   
smppClients     r   r   zSMPPClientService.__init__   s/     !N,,$\22r   c                     | j         S r   )rr   r   s    r   getStopDeferredz!SMPPClientService.getStopDeferred   s      r   c              #      K   t          j        |            | j                                        }|                    | j                   |V }|                                                    | j                   t          j
        |           d S r   )r   startServicerq   rS   rR   handleStartErrorr^   chainDeferredrr   r   returnValue)r   r@   r?   s      r   rw   zSMPPClientService.startService   s      T"""{1133 5666!!!$$&&44T5FGGG$r   c                 :    | j                             |           |S r   )rr   r'   )r   r%   s     r   rx   z"SMPPClientService.handleStartError   s    !!%(((r   c                     t          j        |            | j        j        r8| j                            d           | j        j                                        S d S )NzStopping SMPP Client)r   stopServicerq   r?   r   infounbindAndDisconnectr   s    r   r}   zSMPPClientService.stopService   sV    D!!!; 	:HMM0111;#77999	: 	:r   N)
r+   r,   r-   r   ru   r   inlineCallbacksrw   rx   r}   r/   r   r   ro   ro      so        3 3 3
! ! !        : : : : :r   ro   )__doc__r   OpenSSLr   twisted.internet.protocolr   twisted.internetr   r   r   twisted.application.servicer   smpp.twisted.protocolr	   r
   r   r   r7   r1   r=   ra   rf   rk   ro   r/   r   r   <module>r      s           3 3 3 3 3 3 0 0 0 0 0 0 0 0 0 0 / / / / / / I I I I I I I I"3 3 3 3 3 3 3 32
 
 
 
 
) 
 
 
,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0\( ( ( ( (N ( ( (
4 4 4 4 4 4 4 47 7 7 7 7. 7 7 7: : : : : : : : : :r   