<s> class LineHistory ( object ) : <EOL> def __init__ ( self , numlines = <NUM_LIT:1000> ) : <EOL> super ( LineHistory , self ) . __init__ ( ) <EOL> self . history = [ ] <EOL> self . histidx = <NUM_LIT:0> <EOL> self . histlimit = numlines <EOL> def set_limit ( self , numlines ) : <EOL> self . histlimit = numlines <EOL> def get_history ( self ) : <EOL> return self . history <EOL> def set_history ( self , lines ) : <EOL> self . history = list ( lines ) <EOL> def append ( self , text ) : <EOL> self . history . append ( text ) <EOL> i = self . histlimit - len ( self . history ) <EOL> if i < <NUM_LIT:0> : <EOL> self . history = self . history [ abs ( i ) : ] <EOL> self . histidx = len ( self . history ) <EOL> def prev ( self ) : <EOL> i = self . histidx - <NUM_LIT:1> <EOL> if i >= <NUM_LIT:0> : <EOL> self . histidx = i <EOL> return self . history [ i ] <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def next ( self ) : <EOL> i = self . histidx + <NUM_LIT:1> <EOL> if i < len ( self . history ) : <EOL> self . histidx = i <EOL> return self . history [ i ] <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def save ( self , path ) : <EOL> with open ( path , '<STR_LIT:w>' ) as out_f : <EOL> out_f . write ( '<STR_LIT:\n>' . join ( self . history ) ) <EOL> def load ( self , path ) : <EOL> with open ( path , '<STR_LIT:r>' ) as in_f : <EOL> buf = in_f . read ( ) <EOL> self . history = buf . split ( '<STR_LIT:\n>' ) </s>
