B
    u9a                 @   s   d Z ddlZdadadd ZG dd dZG dd dZdd	d
ZejdfddZ	dd Z
dd Zdd Zdd Zdd Zdd ZejZejZejZejZejZdZdZdS )z8Mock socket module used by the smtpd and smtplib tests.
    Nc             C   s   | a d S )N)_reply_data)line r   !/usr/lib/python3.7/mock_socket.py
reply_with   s    r   c               @   s*   e Zd ZdZdd Zd
ddZdd Zd	S )MockFilez8Mock file object returned by MockSocket.makefile().
    c             C   s
   || _ d S )N)lines)selfr   r   r   r   __init__   s    zMockFile.__init__c             C   s>   | j dd }|dkr:| j d||d  |d | }|S )Nr   s   
)r   popinsert)r	   limitresultr   r   r   readline   s
    zMockFile.readlinec             C   s   d S )Nr   )r	   r   r   r   close   s    zMockFile.closeN)r   )__name__
__module____qualname____doc__r
   r   r   r   r   r   r   r      s   
r   c               @   s   e Zd ZdZd)ddZdd Zd*ddZd	d
 Zdd Zdd Z	dd Z
d+ddZdd Zdd Zdd Zdd Zdd Zd,dd Zd-d!d"Zd.d#d$Zd%d& Zd'd( ZdS )/
MockSocketz8Mock socket object used by smtpd and smtplib tests.
    Nc             C   s6   || _ g | _g | _tr&| jt d ad | _d | _d S )N)familyoutputr   r   appendconntimeout)r	   r   r   r   r   r
   &   s    zMockSocket.__init__c             C   s   | j | d S )N)r   r   )r	   r   r   r   r   
queue_recv1   s    zMockSocket.queue_recvc             C   s   | j dd }|S )Nr   s   
)r   r   )r	   bufsizeflagsdatar   r   r   recv4   s    zMockSocket.recvc             C   s   dS )Nr   r   )r	   r   r   r   fileno8   s    zMockSocket.filenoc             C   s   |d krt | _n|| _d S )N)_defaulttimeoutr   )r	   r   r   r   r   
settimeout;   s    zMockSocket.settimeoutc             C   s   | j S )N)r   )r	   r   r   r   
gettimeoutA   s    zMockSocket.gettimeoutc             C   s   d S )Nr   )r	   leveloptnamevaluer   r   r   
setsockoptD   s    zMockSocket.setsockoptc             C   s   dS )Nr   r   )r	   r&   r'   buflenr   r   r   
getsockoptG   s    zMockSocket.getsockoptc             C   s   d S )Nr   )r	   addressr   r   r   bindJ   s    zMockSocket.bindc             C   s   t  | _| jdfS )Nc)r   r   )r	   r   r   r   acceptM   s    zMockSocket.acceptc             C   s   dS )N)z0.0.0.0r   r   )r	   r   r   r   getsocknameQ   s    zMockSocket.getsocknamec             C   s   d S )Nr   )r	   flagr   r   r   setblockingT   s    zMockSocket.setblockingc             C   s   d S )Nr   )r	   Zbacklogr   r   r   listenW   s    zMockSocket.listenrr   c             C   s   t | j}|S )N)r   r   )r	   moder   Zhandler   r   r   makefileZ   s    
zMockSocket.makefilec             C   s   t | _| jt  tt S )N)r    lastr   r   len)r	   bufferr   r   r   r   sendall^   s    zMockSocket.sendallc             C   s   || _ | j| t|S )N)r7   r   r   r8   )r	   r    r   r   r   r   sendc   s    zMockSocket.sendc             C   s   dS )N)zpeer-addressz	peer-portr   )r	   r   r   r   getpeernameh   s    zMockSocket.getpeernamec             C   s   d S )Nr   )r	   r   r   r   r   k   s    zMockSocket.close)N)N)N)r4   r   )N)N)r   r   r   r   r
   r   r!   r"   r$   r%   r)   r+   r-   r/   r0   r2   r3   r6   r:   r;   r<   r   r   r   r   r   r   #   s&   





r   c             C   s   t | S )N)r   )r   typeprotor   r   r   socketo   s    r?   c             C   sN   yt | d }W n tk
r(   tY nX t }|tjkr@t }|| |S )N   )int
ValueErrorerrorr   socket_module_GLOBAL_DEFAULT_TIMEOUTgetdefaulttimeoutr$   )r,   r   Zsource_addressZint_portmsr   r   r   create_connectionr   s    


rH   c             C   s   | a d S )N)r#   )r   r   r   r   setdefaulttimeout   s    rI   c               C   s   t S )N)r#   r   r   r   r   rF      s    rF   c               C   s   dS )N r   r   r   r   r   getfqdn   s    rK   c               C   s   d S )Nr   r   r   r   r   gethostname   s    rL   c             C   s   dS )NrJ   r   )namer   r   r   gethostbyname   s    rN   c              O   s   t j| |S )N)rD   getaddrinfo)argskwr   r   r   rO      s    rO   )NNN)r   r?   rD   r#   r   r   r   r   rE   rH   rI   rF   rK   rL   rN   rO   ZgaierrorrC   ZAF_INETZAF_INET6ZSOCK_STREAMZ
SOL_SOCKETZSO_REUSEADDRr   r   r   r   <module>   s,   L
