
    	h2                        d Z ddlZddlZddlZddlZddlmZmZmZ ddl	m
Z
mZmZmZmZ ddlmZ ddlmZ dZd	Z ej        d
          Z ej        d          Z G d dej                  Z G d deej                  ZdS )z?
An ``asyncio.Protocol`` subclass for lower level IO handling.
    N)DequeOptionalcast   )SMTPDataErrorSMTPReadTimeoutErrorSMTPResponseExceptionSMTPServerDisconnectedSMTPTimeoutError)SMTPResponse)
SMTPStatus)SMTPProtocoli    s   (?:\r\n|\n|\r(?!\n))s   (?m)^\.c                       e Zd ZdZddeej                 fdZddZddZ	dee
         ddfd	Zdd
Zdej        ddfdZdS )FlowControlMixina  
    Reusable flow control logic for StreamWriter.drain().
    This implements the protocol methods pause_writing(),
    resume_writing() and connection_lost().  If the subclass overrides
    these it must call the super methods.
    StreamWriter.drain() must wait for _drain_helper() coroutine.

    Copied from stdlib as per recommendation: https://bugs.python.org/msg343685.
    Logging and asserts removed, type annotations added.
    Nloopc                     |t          j                    | _        n|| _        d| _        t	          j                    | _        d| _        d S NF)asyncioget_event_loop_loop_pausedcollectionsdeque_drain_waiters_connection_lost)selfr   s     `/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/aiosmtplib/protocol.py__init__zFlowControlMixin.__init__)   sF    < /11DJJDJ;F;L;N;N %    returnc                     d| _         d S NT)r   r   s    r   pause_writingzFlowControlMixin.pause_writing3   s    r   c                 z    d| _         | j        D ]+}|                                s|                    d            ,d S r   )r   r   done
set_resultr   waiters     r   resume_writingzFlowControlMixin.resume_writing6   sJ    ) 	( 	(F;;== (!!$'''	( 	(r   excc                     d| _         | j        sd S | j        D ]C}|                                s-||                    d            .|                    |           Dd S r"   )r   r   r   r&   r'   set_exception)r   r+   r)   s      r   connection_lostz FlowControlMixin.connection_lost=   sv     $| 	F) 	. 	.F;;== .;%%d++++((---	. 	.r   c                 2  K   | j         rt          d          | j        sd S | j                                        }| j                            |           	 | d {V  | j                            |           d S # | j                            |           w xY wNConnection lost)r   ConnectionResetErrorr   r   create_futurer   appendremover(   s     r   _drain_helperzFlowControlMixin._drain_helperJ   s        	:&'8999| 	F))++""6***	/LLLLLLL&&v.....D&&v....s   A: :Bstreamasyncio.Future[None]c                     t           N)NotImplementedErrorr   r7   s     r   _get_close_waiterz"FlowControlMixin._get_close_waiterV   s    !!r   r:   r    N)__name__
__module____qualname____doc__r   r   AbstractEventLoopr   r$   r*   	Exceptionr.   r6   StreamWriterr=    r   r   r   r      s        	 	& &Xg&?@ & & & &   ( ( ( (.8I#6 .4 . . . .
/ 
/ 
/ 
/"(< "AW " " " " " "r   r   c            	           e Zd Z	 ddeej                 ddf fdZdej        ddfdZddZ	e
defd	            Zd
ej        ddfdZdee         ddf fdZdeddfdZdefdZdee         fdZdee         fdZddee         defdZdeddfdZdddedee         defdZ	 ddedee         defdZ	 	 d dej        dee         dee         defdZ  xZ!S )!r   Nr   r    c                     t                                          |           d| _        t                      | _        d | _        d | _        d | _        | j        	                                | _
        d| _        d S )N)r   F)superr   	_over_ssl	bytearray_buffer_response_waiter	transport_command_lockr   r3   _closed
_quit_sent)r   r   	__class__s     r   r   zSMTPProtocol.__init__[   si     	d### {{HL:>59/3z/G/G/I/Ir   r7   r8   c                     | j         S r:   )rP   r<   s     r   r=   zSMTPProtocol._get_close_waiteri   s
    |r   c                 .    |                                   d S r:   )_retrieve_response_exceptionr#   s    r   __del__zSMTPProtocol.__del__l   s     	))+++++r   c                 b    t          | j        duo| j                                                   S )z<
        Check if our transport is still connected.
        N)boolrN   
is_closingr#   s    r   is_connectedzSMTPProtocol.is_connectedq   s/    
 DN$.Rt~7P7P7R7R3RSSSr   rN   c                     t          t          j        |          | _        |                    d          d u| _        | j                                        | _        t          j	                    | _
        d| _        d S )N
sslcontextF)r   r   	TransportrN   get_extra_inforJ   r   r3   rM   LockrO   rQ   )r   rN   s     r   connection_madezSMTPProtocol.connection_madex   s_    g/;;"11,??tK $
 8 8 : :$\^^r   r+   c                    t                                          |           | j        sRt          d          }|r||_        | j        r3| j                                        s| j                            |           d | _        d | _	        d S r0   )
rI   r.   rQ   r
   	__cause__rM   r&   r-   rN   rO   )r   r+   smtp_excrR   s      r   r.   zSMTPProtocol.connection_lost   s    $$$ 	>-.?@@H )%("$ >T-B-G-G-I-I >%33H===!r   datac                    | j         t          d|          | j                                         rd S | j                            |           |                    d          }|dk    s||dz   |dz            dk    rd S 	 |                                 }|| j                             |           d S d S # t          $ r%}| j         	                    |           Y d }~d S d }~ww xY w)Nz4data_received called without a response waiter set:    
         -)
rM   RuntimeErrorr&   rL   extendrfind_read_response_from_bufferr'   rD   r-   )r   rd   last_linebreakresponser+   s        r   data_receivedzSMTPProtocol.data_received   s+    (OtOO   "'')) 	FD!!! E**b  NQ&!);;<DDF	;6688H #%00::::: $#  	5 	5 	5!//444444444	5s   B5 5
C$?CC$c                     t          d          }| j        r3| j                                        s| j                            |           dS )NzUnexpected EOF receivedF)r
   rM   r&   r-   )r   r+   s     r   eof_receivedzSMTPProtocol.eof_received   sO    $%>??  	5)>)C)C)E)E 	5!//444 ur   c                     | j         rK| j                                         r2| j                                         s| j                                         S dS )z
        Return any exception that has been set on the response waiter.

        Used to avoid 'Future exception was never retrieved' warnings
        N)rM   r&   	cancelled	exceptionr#   s    r   rU   z)SMTPProtocol._retrieve_response_exception   s[     !	5%**,,	5 )3355	5
 (22444tr   c                    d}t                      }d}d}	 | j                            d|          }|dk    rnt          | j        ||dz                      }t	          |          t
          k    rt          t          j        d          	 t          |dd	                   }n1# t          $ r$ t          t          j        j        d
|          dw xY w|t	          |          z  }t	          |          r|                    d           |                    |dd                             d                     |d	d         dk    rd}n7|r=t          |t          |                              dd                    }| j        d|= |S dS )z7Parse the actual response (if any) from the data bufferrg   r   FTrf   r   zResponse too longNrh   zMalformed SMTP response line: ri   s    	
rj   zutf-8surrogateescape)rK   rL   findbyteslenMAX_LINE_LENGTHr	   r   unrecognized_commandint
ValueErrorinvalid_responsevaluerl   stripr   decode)r   codemessageoffsetmessage_completeline_end_indexlinerp   s           r   rn   z'SMTPProtocol._read_response_from_buffer   s   ++ 	!\..uf==N##f~/A&ABCCD4yy?**+35H  48}}   +/5=T==   c$iiF7|| &u%%%NN48>>*55666AaCyD  #' 5	8  	#eGnn++G5FGG H WfW%O4s   B# #.Ctimeoutc                   K   | j         t          d          	 t          j        | j         |           d{V }n.# t          t          j        f$ r}t          d          |d}~ww xY w	 | j        d| _         nQ| j                                        | _         n2# | j        d| _         n| j                                        | _         w xY w|S )a  
        Get a status response from the server.

        This method must be awaited once per command sent; if multiple commands
        are written to the transport without awaiting, response data will be lost.

        Returns an :class:`.response.SMTPResponse` namedtuple consisting of:
          - server response code (e.g. 250, or such, if all goes well)
          - server response string (multiline responses are converted to a
            single, multiline string).
        Nr1   z%Timed out waiting for server response)	rM   r
   r   wait_forTimeoutErrorr   rN   r   r3   )r   r   resultr+   s       r   read_responsezSMTPProtocol.read_response   s        (():;;;		C"+D,A7KKKKKKKKFFg23 	Y 	Y 	Y&'NOOUXX	Y 
 ~%(,%%(,
(@(@(B(B%% ~%(,%%(,
(@(@(B(B%BBBBs&    ; B A&A!!A&&B /Cc                     | j         | j                                         rt          d          t          | j         d          st	          d| j         d          | j                             |           d S )Nr1   writez
Transport z does not support writing.)rN   rY   r
   hasattrrk   r   )r   rd   s     r   r   zSMTPProtocol.write  s    >!T^%>%>%@%@!():;;;t~w// 	IT^III   	T"""""r   r   argsc                D  K   | j         t          d          d                    |          dz   }| j         4 d{V  |                     |           |dk    rd| _        |                     |           d{V }ddd          d{V  n# 1 d{V swxY w Y   |S )zj
        Sends an SMTP command along with any args to the server, and returns
        a response.
        NServer not connected       
s   QUIT
Tr   )rO   r
   joinr   rQ   r   )r   r   r   commandrp   s        r   execute_commandzSMTPProtocol.execute_command  sb      %()?@@@))D//G+% 	A 	A 	A 	A 	A 	A 	A 	AJJw+%%"&!///@@@@@@@@H	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A s   ?B
BBr   c                   K   | j         t          d          t                              d|          }t                              d|          }|                    d          s|dz  }|dz  }| j         4 d{V  |                     d           |                     |           d{V }|j        t          j
        k    rt          |j        |j                  |                     |           |                     |           d{V }|j        t          j        k    rt          |j        |j                  	 ddd          d{V  n# 1 d{V swxY w Y   |S )z
        Sends an SMTP DATA command to the server, followed by encoded message content.

        Automatically quotes lines beginning with a period per RFC821.
        Lone \\r and \\n characters are converted to \\r\\n
        characters.
        Nr   r   s   ..s   .
s   DATA
r   )rO   r
   LINE_ENDINGS_REGEXsubPERIOD_REGEXendswithr   r   r   r   start_inputr   r   	completed)r   r   r   start_responserp   s        r   execute_data_commandz!SMTPProtocol.execute_data_command&  s      %()?@@@$(('::""5'22(( 	wG8% 		E 		E 		E 		E 		E 		E 		E 		EJJ{####'#5#5g#5#F#FFFFFFFN"j&<<<#N$79OPPPJJw!///@@@@@@@@H}
 444#HM83CDDDD		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E s   ;CE
EEtls_contextserver_hostnamec           	      ^  K   | j         rt          d          | j        t          d          | j        4 d{V  |                     d           |                     |           d{V }|j        t          j        k    rt          |j        |j
                  | j        | j                                        rt          d          	 | j                            | j        | |d||           d{V }n# t          t           j        f$ r}t#          d	          |d}~wt$          $ r }t#          |j        d
                   |d}~wt(          $ r,}|j        r|j        d
         }nd}t          |          |d}~ww xY w|| _        ddd          d{V  n# 1 d{V swxY w Y   |S )zG
        Puts the connection to the SMTP server into TLS mode.
        zAlready using TLS.Nr   s
   STARTTLS
r   r1   F)server_sider   ssl_handshake_timeoutz#Timed out while upgrading transportr   z.Connection was reset while upgrading transport)rJ   rk   rO   r
   r   r   r   r   readyr	   r   rN   rY   r   	start_tlsr   r   r   ConnectionAbortedErrorr   r2   )r   r   r   r   rp   tls_transportr+   r   s           r   r   zSMTPProtocol.start_tlsF  s      > 	53444%()?@@@% 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+JJ'''!///@@@@@@@@H}
 000+HM8;KLLL ~%)B)B)D)D%,->????&*j&:&:N %$3*1 '; ' ' ! ! ! ! ! ! !'"67 W W W&'LMMSVV) = = =&sx{33<' ? ? ?8 O!hqkGGNG,W553>? +DN?	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+B sN   BF+C98F9F DF ,EF 'E;;F  
F
F&)F&r:   r>   )NN)"r?   r@   rA   r   r   rC   r   rE   r=   rV   propertyrX   rZ   BaseTransportr`   rD   r.   rz   rq   rs   BaseExceptionrU   r   rn   floatr   r   r   r   ssl
SSLContextstrr   __classcell__)rR   s   @r   r   r   Z   s        59   w01  
           (< AW    , , , ,
 Td T T T XT )>  4        "8I#6 "4 " " " " " ";% ;D ; ; ; ;6d    h}.E    *H\,B * * * *X 8E? l    8#% #D # # # # 8<  %-e_	   , :> '/	   F *.#'	/ /^/ "#/ %	/
 
/ / / / / / / /r   r   )rB   r   r   rer   typingr   r   r   errorsr   r   r	   r
   r   rp   r   r   __all__r|   compiler   r   Protocolr   BaseProtocolr   rF   r   r   <module>r      sf         				 



 ( ( ( ( ( ( ( ( ( (              # " " " " "        RZ 899 rz+&&:" :" :" :" :"w' :" :" :"z[ [ [ [ [#W%9 [ [ [ [ [r   