<s> __author__ = """<STR_LIT>""" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from os import getcwd <EOL> from os import sys <EOL> sys . path . append ( getcwd ( ) ) <EOL> from MOAL . helpers . display import Section <EOL> DEBUG = True if __name__ == '<STR_LIT:__main__>' else False <EOL> class InvalidBufferLength ( Exception ) : <EOL> pass <EOL> class CircularBuffer ( list ) : <EOL> def __init__ ( self , items , ** kwargs ) : <EOL> self . MAX_SIZE = <NUM_LIT:8> <EOL> self . pointer = <NUM_LIT:0> <EOL> if not isinstance ( items , list ) : <EOL> raise TypeError <EOL> if len ( items ) > self . MAX_SIZE : <EOL> raise InvalidBufferLength ( <EOL> '<STR_LIT>' . format ( self . MAX_SIZE ) ) <EOL> super ( CircularBuffer , self ) . __init__ ( items , ** kwargs ) <EOL> def __str__ ( self ) : <EOL> indices = map ( str , range ( len ( self ) ) ) <EOL> chars = map ( str , self ) <EOL> print ( '<STR_LIT>' . format ( <EOL> self . pointer , '<STR_LIT:U+0020>' + '<STR_LIT:U+0020>' . join ( indices ) ) ) <EOL> return '<STR_LIT>' . format ( '<STR_LIT>' . join ( chars ) ) <EOL> def __delitem__ ( self , key ) : <EOL> pass <EOL> def __getitem__ ( self , key ) : <EOL> return super ( CircularBuffer , self ) . __getitem__ ( key ) <EOL> def __setitem__ ( self , index , value ) : <EOL> old = self . pointer <EOL> if self . pointer >= self . MAX_SIZE : <EOL> self . pointer = <NUM_LIT:0> <EOL> super ( CircularBuffer , self ) . __setitem__ ( self . pointer , value ) <EOL> else : <EOL> super ( CircularBuffer , self ) . __setitem__ ( index , value ) <EOL> self . pointer += <NUM_LIT:1> <EOL> print ( '<STR_LIT>' . format ( old , self . pointer ) ) <EOL> def append ( self , value ) : <EOL> return self . __setitem__ ( self . pointer , value ) <EOL> if DEBUG : <EOL> with Section ( '<STR_LIT>' ) : <EOL> circbuff = CircularBuffer ( range ( <NUM_LIT:8> ) ) <EOL> print ( circbuff ) <EOL> circbuff . append ( '<STR_LIT:A>' ) <EOL> circbuff . append ( '<STR_LIT:B>' ) <EOL> circbuff . append ( '<STR_LIT:C>' ) <EOL> circbuff . append ( '<STR_LIT:D>' ) <EOL> circbuff . append ( '<STR_LIT:E>' ) <EOL> circbuff . append ( '<STR_LIT:0>' ) <EOL> circbuff . append ( '<STR_LIT>' ) <EOL> print ( circbuff ) <EOL> assert circbuff [ <NUM_LIT:0> ] == '<STR_LIT:A>' <EOL> assert circbuff [ <NUM_LIT:1> ] == '<STR_LIT:B>' <EOL> assert circbuff [ <NUM_LIT:2> ] == '<STR_LIT:C>' <EOL> assert circbuff [ <NUM_LIT:3> ] == '<STR_LIT:D>' <EOL> assert circbuff [ <NUM_LIT:4> ] == '<STR_LIT:E>' <EOL> circbuff . append ( '<STR_LIT>' ) <EOL> circbuff . append ( '<STR_LIT:X>' ) <EOL> circbuff . append ( '<STR_LIT:Y>' ) <EOL> assert circbuff [ <NUM_LIT:7> ] == '<STR_LIT>' <EOL> assert circbuff [ <NUM_LIT:0> ] == '<STR_LIT:X>' <EOL> assert circbuff [ <NUM_LIT:1> ] == '<STR_LIT:Y>' <EOL> print ( circbuff ) </s>
