Edit File: asynchat_25.cpython-36.pyc
3 �k�`L* � @ sj d Z ddlZddlmZ ddlmZ ddlmZ G dd� dej�Z G dd � d �Z G d d� d�Zdd � ZdS )a� A class supporting chat-style (command/response) protocols. This class adds support for 'chat' style protocols - where one side sends a 'command', and the other sends a response (examples would be the common internet protocols - smtp, nntp, ftp, etc..). The handle_read() method looks at the input stream for the current 'terminator' (usually '\r\n' for single-line responses, '\r\n.\r\n' for multi-line output), calling self.found_terminator() on its receipt. for example: Say you build an async nntp client using this class. At the start of the connection, you'll have self.terminator set to '\r\n', in order to process the single-line greeting. Just before issuing a 'LIST' command you'll set it to '\r\n.\r\n'. The output of the LIST command will be accumulated (using your own 'collect_incoming_data' method) up to the terminator, and then control will be returned to you - by calling your self.found_terminator() method. � N)�asyncore_25)�long)�as_bytesc @ s� e Zd ZdZdZdZd$dd�Zdd� Zdd � Zd d� Z dd � Z dd� Zdd� Zdd� Z dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zd d!� Zd"d#� ZdS )%� async_chatz�This is an abstract class. You must derive from this class, and add the two methods collect_incoming_data() and found_terminator()i Nc C s( d| _ d| _t� | _tjj| ||� d S )N� )�ac_in_buffer� ac_out_buffer�fifo� producer_fifo�asyncore� dispatcher�__init__)�selfZconn�map� r �!/usr/lib/python3.6/asynchat_25.pyr ? s zasync_chat.__init__c C s t d��d S )Nzmust be implemented in subclass)�NotImplementedError)r �datar r r �collect_incoming_dataE s z async_chat.collect_incoming_datac C s t d��d S )Nzmust be implemented in subclass)r )r r r r �found_terminatorH s zasync_chat.found_terminatorc C s || _ dS )zRSet the input delimiter. Can be a fixed string of any length, an integer, or NoneN)� terminator)r Ztermr r r �set_terminatorK s zasync_chat.set_terminatorc C s | j S )N)r )r r r r �get_terminatorO s zasync_chat.get_terminatorc C s� y| j | j�}W n tjk r. | j� d S X | j|7 _�x`| j�r�t| j�}| j� }|st| j| j� d| _qBt |t �s�t |t�r�|}||k r�| j| j� d| _| j|8 _n2| j| jd |� � | j|d � | _d| _| j � qBt|�}| jj|�}|dk�rD|dk�r&| j| jd |� � | j|| d � | _| j � qBt| j|�}|�r�||k�r�| j| jd | � � | j| d � | _P qB| j| j� d| _qBW d S )Nr r � ���)Zrecv�ac_in_buffer_size�socket�error�handle_errorr �lenr r � isinstance�intr r r �find�find_prefix_at_end)r r Zlbr �nZterminator_len�indexr r r �handle_readW sJ zasync_chat.handle_readc C s | j � d S )N)� initiate_send)r r r r �handle_write� s zasync_chat.handle_writec C s | j � d S )N)�close)r r r r �handle_close� s zasync_chat.handle_closec C s$ t |�}| jjt|�� | j� d S )N)r r �push�simple_producerr'