<s> """<STR_LIT>""" <EOL> from . common import Remote <EOL> from . . compat import IS_PYTHON3 <EOL> __all__ = ( '<STR_LIT>' ) <EOL> if IS_PYTHON3 : <EOL> basestring = str <EOL> class Buffer ( Remote ) : <EOL> """<STR_LIT>""" <EOL> _api_prefix = "<STR_LIT>" <EOL> def __len__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( '<STR_LIT>' ) <EOL> def __getitem__ ( self , idx ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( idx , slice ) : <EOL> return self . _session . request ( '<STR_LIT>' , self , idx ) <EOL> include_end = False <EOL> start = idx . start <EOL> end = idx . stop <EOL> if start is None : <EOL> start = <NUM_LIT:0> <EOL> if end is None : <EOL> end = - <NUM_LIT:1> <EOL> include_end = True <EOL> return self . _session . request ( '<STR_LIT>' , self , start , end , <EOL> True , include_end ) <EOL> def __setitem__ ( self , idx , lines ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( idx , slice ) : <EOL> if lines is None : <EOL> return self . _session . request ( '<STR_LIT>' , self , idx ) <EOL> else : <EOL> return self . _session . request ( '<STR_LIT>' , self , idx , <EOL> lines ) <EOL> if lines is None : <EOL> lines = [ ] <EOL> include_end = False <EOL> start = idx . start <EOL> end = idx . stop <EOL> if start is None : <EOL> start = <NUM_LIT:0> <EOL> if end is None : <EOL> end = - <NUM_LIT:1> <EOL> include_end = True <EOL> return self . _session . request ( '<STR_LIT>' , self , start , end , <EOL> True , include_end , lines ) <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> lines = self [ : ] <EOL> for line in lines : <EOL> yield line <EOL> def __delitem__ ( self , idx ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( idx , slice ) : <EOL> self . __setitem__ ( idx , None ) <EOL> else : <EOL> self . __setitem__ ( idx , [ ] ) <EOL> def get_line_slice ( self , start , stop , start_incl , end_incl ) : <EOL> """<STR_LIT>""" <EOL> return self . _session . request ( '<STR_LIT>' , self , start , <EOL> stop , start_incl , end_incl ) <EOL> def set_line_slice ( self , start , stop , start_incl , end_incl , lines ) : <EOL> """<STR_LIT>""" <EOL> return self . _session . request ( '<STR_LIT>' , self , start , <EOL> stop , start_incl , end_incl , lines ) <EOL> def append ( self , lines , index = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( lines , basestring ) : <EOL> lines = [ lines ] <EOL> return self . _session . request ( '<STR_LIT>' , self , index , lines ) <EOL> def mark ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( '<STR_LIT>' , name ) <EOL> def range ( self , start , end ) : <EOL> """<STR_LIT>""" <EOL> return Range ( self , start , end ) <EOL> def add_highlight ( self , hl_group , line , col_start = <NUM_LIT:0> , <EOL> col_end = - <NUM_LIT:1> , src_id = - <NUM_LIT:1> , async = None ) : <EOL> """<STR_LIT>""" <EOL> if async is None : <EOL> async = ( src_id != <NUM_LIT:0> ) <EOL> return self . request ( '<STR_LIT>' , src_id , hl_group , <EOL> line , col_start , col_end , async = async ) <EOL> def clear_highlight ( self , src_id , line_start = <NUM_LIT:0> , line_end = - <NUM_LIT:1> , async = True ) : <EOL> """<STR_LIT>""" <EOL> self . request ( '<STR_LIT>' , src_id , <EOL> line_start , line_end , async = async ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( '<STR_LIT>' ) <EOL> @ name . setter <EOL> def name ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( '<STR_LIT>' , value ) <EOL> @ property <EOL> def valid ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( '<STR_LIT>' ) <EOL> @ property <EOL> def number ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( '<STR_LIT>' ) <EOL> class Range ( object ) : <EOL> def __init__ ( self , buffer , start , end ) : <EOL> self . _buffer = buffer <EOL> self . start = start - <NUM_LIT:1> <EOL> self . end = end - <NUM_LIT:1> <EOL> def __len__ ( self ) : <EOL> return self . end - self . start + <NUM_LIT:1> <EOL> def __getitem__ ( self , idx ) : <EOL> if not isinstance ( idx , slice ) : <EOL> return self . _buffer [ self . _normalize_index ( idx ) ] <EOL> start = self . _normalize_index ( idx . start ) <EOL> end = self . _normalize_index ( idx . stop ) <EOL> if start is None : <EOL> start = self . start <EOL> if end is None : <EOL> end = self . end + <NUM_LIT:1> <EOL> return self . _buffer [ start : end ] <EOL> def __setitem__ ( self , idx , lines ) : <EOL> if not isinstance ( idx , slice ) : <EOL> self . _buffer [ self . _normalize_index ( idx ) ] = lines <EOL> return <EOL> start = self . _normalize_index ( idx . start ) <EOL> end = self . _normalize_index ( idx . stop ) <EOL> if start is None : <EOL> start = self . start <EOL> if end is None : <EOL> end = self . end + <NUM_LIT:1> <EOL> self . _buffer [ start : end ] = lines <EOL> def __iter__ ( self ) : <EOL> for i in range ( self . start , self . end + <NUM_LIT:1> ) : <EOL> yield self . _buffer [ i ] <EOL> def append ( self , lines , i = None ) : <EOL> i = self . _normalize_index ( i ) <EOL> if i is None : <EOL> i = self . end + <NUM_LIT:1> <EOL> self . _buffer . append ( lines , i ) <EOL> def _normalize_index ( self , index ) : <EOL> if index is None : <EOL> return None <EOL> if index < <NUM_LIT:0> : <EOL> index = self . end <EOL> else : <EOL> index += self . start <EOL> if index > self . end : <EOL> index = self . end <EOL> return index </s>
