<s> from __future__ import division , print_function , unicode_literals <EOL> from brainstorm . utils import get_by_path <EOL> class BufferView ( list ) : <EOL> def __init__ ( self , buffer_names , buffers , full_buffer = None ) : <EOL> super ( BufferView , self ) . __init__ ( buffers ) <EOL> if not len ( buffers ) == len ( buffer_names ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( len ( buffers ) , len ( buffer_names ) ) ) <EOL> self . _full_buffer = full_buffer <EOL> self . _buffer_names = tuple ( buffer_names ) <EOL> self . _keys = set ( buffer_names ) <EOL> for i , n in enumerate ( buffer_names ) : <EOL> self . __dict__ [ n ] = self [ i ] <EOL> def adjust ( self , buffer_names , buffers , full_buffer = None ) : <EOL> assert self . _buffer_names == tuple ( buffer_names ) <EOL> self . _full_buffer = full_buffer <EOL> for i , ( n , b ) in enumerate ( zip ( buffer_names , buffers ) ) : <EOL> self [ i ] = b <EOL> self . __dict__ [ n ] = self [ i ] <EOL> return self <EOL> def _asdict ( self ) : <EOL> return dict ( zip ( self . _buffer_names , self ) ) <EOL> def items ( self ) : <EOL> return self . _asdict ( ) . items ( ) <EOL> def keys ( self ) : <EOL> return self . _asdict ( ) . keys ( ) <EOL> def values ( self ) : <EOL> return self . _asdict ( ) . values ( ) <EOL> def __getitem__ ( self , item ) : <EOL> if isinstance ( item , int ) : <EOL> return super ( BufferView , self ) . __getitem__ ( item ) <EOL> if item in self . _keys : <EOL> return self . __dict__ [ item ] <EOL> elif '<STR_LIT:.>' in item : <EOL> return get_by_path ( self , item ) <EOL> raise KeyError ( '<STR_LIT>' <EOL> . format ( item , "<STR_LIT:U+002CU+0020>" . join ( sorted ( self . _keys ) ) ) ) <EOL> def __contains__ ( self , item ) : <EOL> return item in self . _buffer_names </s>
