<s> from base import Base <EOL> class Deque ( Base ) : <EOL> def front_pop ( self ) : <EOL> return self . _loads ( self . redis . rpop ( self . name ) ) <EOL> def back_pop ( self ) : <EOL> return self . _loads ( self . redis . lpop ( self . name ) ) <EOL> def back_push ( self , item ) : <EOL> try : <EOL> self . redis . lpush ( self . name , self . _dumps ( item ) ) <EOL> return True <EOL> except : <EOL> return False <EOL> def front_push ( self , item ) : <EOL> try : <EOL> self . redis . rpush ( self . name , self . _dumps ( item ) ) <EOL> return True <EOL> except : <EOL> return False <EOL> def addAll ( self , collection = [ ] , back = True ) : <EOL> assert type ( collection ) == list <EOL> with self . redis . pipeline ( ) as pipe : <EOL> for item in collection : <EOL> try : <EOL> if back : <EOL> pipe . lpush ( self . name , self . _dumps ( item ) ) <EOL> else : <EOL> pipe . rpush ( self . name , self . _dumps ( item ) ) <EOL> except : <EOL> continue <EOL> pipe . execute ( ) <EOL> def next ( self ) : <EOL> try : <EOL> got = self . front_pop ( ) <EOL> if got : <EOL> return got <EOL> raise StopIteration <EOL> except : <EOL> raise StopIteration </s>
