<s> from __future__ import absolute_import <EOL> from io import BytesIO <EOL> from thriftpy . _compat import CYTHON <EOL> from . . import TTransportBase <EOL> class TBufferedTransport ( TTransportBase ) : <EOL> """<STR_LIT>""" <EOL> DEFAULT_BUFFER = <NUM_LIT> <EOL> def __init__ ( self , trans , buf_size = DEFAULT_BUFFER ) : <EOL> self . _trans = trans <EOL> self . _wbuf = BytesIO ( ) <EOL> self . _rbuf = BytesIO ( b"<STR_LIT>" ) <EOL> self . _buf_size = buf_size <EOL> def is_open ( self ) : <EOL> return self . _trans . is_open ( ) <EOL> def open ( self ) : <EOL> return self . _trans . open ( ) <EOL> def close ( self ) : <EOL> return self . _trans . close ( ) <EOL> def _read ( self , sz ) : <EOL> ret = self . _rbuf . read ( sz ) <EOL> if len ( ret ) != <NUM_LIT:0> : <EOL> return ret <EOL> self . _rbuf = BytesIO ( self . _trans . read ( max ( sz , self . _buf_size ) ) ) <EOL> return self . _rbuf . read ( sz ) <EOL> def write ( self , buf ) : <EOL> self . _wbuf . write ( buf ) <EOL> def flush ( self ) : <EOL> out = self . _wbuf . getvalue ( ) <EOL> self . _wbuf = BytesIO ( ) <EOL> self . _trans . write ( out ) <EOL> self . _trans . flush ( ) <EOL> def getvalue ( self ) : <EOL> return self . _trans . getvalue ( ) <EOL> class TBufferedTransportFactory ( object ) : <EOL> def get_transport ( self , trans ) : <EOL> return TBufferedTransport ( trans ) <EOL> if CYTHON : <EOL> from . cybuffered import TCyBufferedTransport , TCyBufferedTransportFactory </s>
