U
    dR…f
  ã                   @   sH   d dl mZ ddlmZmZ dd„ ZG dd„ deƒZG dd	„ d	eƒZd
S )é    )Úabsolute_importé   )ÚTTypeÚ
TExceptionc                 C   sN   d}d}||k rJ| || ƒ}|t |ƒ7 }||7 }t |ƒdkrttjdƒ‚q|S )Nó    r   z"End of file reading from transport)ÚlenÚTTransportExceptionÚEND_OF_FILE)Zread_fnÚszZbuffZhaveÚchunk© r   ú</tmp/pip-unpacked-wheel-jqs7l_7o/thriftpy2/transport/base.pyÚreadall   s    ÿr   c                   @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )ÚTTransportBasez&Base class for Thrift transport layer.c                 C   s   t ‚dS )z Check if this transport is open.N©ÚNotImplementedError©Úselfr   r   r   Úis_open   s    zTTransportBase.is_openc                 C   s   t ‚dS )zy
        Prepare this transport for usage and allocate any necessary resources
        like sockets or sessions.
        Nr   r   r   r   r   Úopen   s    zTTransportBase.openc                 C   s   t ‚dS )z:Clean up and deallocate any resources allocated in open().Nr   r   r   r   r   Úclose%   s    zTTransportBase.closec                 C   s   t ‚dS )zs
        Internal read method which can read up to `sz` bytes but doesn't
        need to return them all.
        Nr   ©r   r
   r   r   r   Ú_read)   s    zTTransportBase._readc                 C   s   t | j|ƒS )aN  
        Get exactly `sz` bytes from the underlying connection.

        When implementing a custom transport, this method must return exactly
        `sz` bytes if it is expected to be called from the protocol layer. If
        it intends to wrapped by another transport, like TBufferedTransport,
        it should return whatever the underlying connection/transport can get.
        The wrapping transport will take care of ensuring `sz` bytes are
        returned. For a more in depth discussion, see:
        https://github.com/Thriftpy/thriftpy2/pull/108#discussion_r355131677
        )r   r   r   r   r   r   Úread0   s    zTTransportBase.readc                 C   s   t ‚dS )zr
        Submit some data to be written to the connection. May be
        buffered until flush is called.
        Nr   )r   Úbufr   r   r   Úwrite>   s    zTTransportBase.writec                 C   s   t ‚dS )zAEnsure that all internal buffers are emptied into the connection.Nr   r   r   r   r   ÚflushE   s    zTTransportBase.flushN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r   r      s   r   c                       sP   e Zd ZdZejdfejdfdœZdZdZ	dZ
dZd	Zed
f‡ fdd„	Z‡  ZS )r   z Custom Transport Exception classÚmessageÚtype)é   r   r   r#   r   é   é   Nc                    s   t t| ƒ ¡  || _|| _d S )N)Úsuperr   Ú__init__r"   r!   )r   r"   r!   ©Ú	__class__r   r   r'   X   s    zTTransportException.__init__)r   r   r   r    r   ÚSTRINGZI32Zthrift_specÚUNKNOWNZNOT_OPENZALREADY_OPENZ	TIMED_OUTr	   r'   Ú__classcell__r   r   r(   r   r   J   s   þr   N)	Ú
__future__r   Zthriftr   r   r   Úobjectr   r   r   r   r   r   Ú<module>   s   3